Best way to refresh the auth token for a fully programatic authentication #61
Replies: 5 comments 2 replies
-
Hi. Sorry for my silly comments or questions, my python knowledge is still quite basic. So, obviously, there is the auth file already used in this very repo: main/monzo/authentication.py :) I did a little step forward, I added a detailed error print on the transactions example and I now get "Could not refresh the access token", which at least is more descriptive than 'Failed to retrieve transactions'.
Now we only need to find out why that happens and how to make it work... :) |
Beta Was this translation helpful? Give feedback.
-
Hi @SomeDevWeb If authentication was successful but you get that error it would usually be one of the following:
To combat the first issue you should only fetch transactions older than 90 days when you first create the token. To combat the 2nd, tokens only last for so long, this is of course not convenient when you use an automated process to fetch transactions. Tokens are accompanied by a refresh token. The code will refresh the token when required and can provide the new token details when a new token is created from that refresh token. The following explains how this works: https://monzo-api.readthedocs.io/en/latest/refreshing_tokens.html The error you are receiving is potentially that the code automatically refreshed the token and you tried to use the original token details again, the above would get around this. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot, @petermcd, that shed a bit more light on this issue! Firstly, as a thought, I see Echo is imported from So this is some sample code I tried to use - store info in a local file and used it from there, but it still says "Could not refresh the access token". It doesn't seem to refresh anything, but probably some of the code is not doing the right thing...
|
Beta Was this translation helpful? Give feedback.
-
Hi @petermcd and thanks for the reply. No, I'm afraid I abandoned it again, as I didn't find any solution and it was getting so agravating that it wasn't worth it anymore. So, I think we should re-clarify a few aspects:
Actually, if it helps, I also tried doin the whole procedure from scratch, which gave me new access_token and refresh_token and with those ones I could indeed retrieve the accounts for example, but this time when I tried to get the refresh token, I got some other error "URL could not be accessed"... |
Beta Was this translation helpful? Give feedback.
-
Wow, I think I got it. So a few thoughts in conclusion:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys.
I thought I would start a discussion topic rather than an issue, as this is not one as such.
So, ever since I started working with this Monzo API, I had trouble understanding and applying the truly automated authentication.
Now, even in this lovely repo, the auth in the examples files is done in two steps and part of that procedure involves clicking links in the browser and waiting for a confirmation link in the email and moreover, you also need to click the "accept" button in the app in order to get the final auth tokens. The problem is actually that the returned tokens expire in about 1 day, so you need to do the procedure again, which completely defies the purpose of any API automation script... :(
I understand there is a way to truly check and refresh the auth token automatically, but I can't put my finger on it in order to implement it in a working/production script.
As a thought, @petermcd, would this file work from the project you gracefully shared previously:
https://github.com/petermcd/monzo-api/blob/v0.1.6/monzo/authentication.py
Maybe a little code example of how that can be implemented in a real script would be great.
Thanks a lot for any support or ideas!
Best regards,
Andy
Beta Was this translation helpful? Give feedback.
All reactions