Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic token refreshment #24

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Add automatic token refreshment #24

wants to merge 9 commits into from

Conversation

jackleland
Copy link
Collaborator

Adds functionality for automatically refreshing tokens when the one used is returned via a 401. Stops the workflow and asks for a username and password, which will kill automatic workflows but going to a access+refresh token situation didn't seem like a better option – I have added a flag for turning off auto-refresh onto the client constructor so this can be deactivated if necessary! The refreshment automatically updates the config file with the new token, I'm not 100% how this would work with mulitple clients open at teh same time though - we might want the auto-refresh to first check the config file to see if the token has been updated and then do a refreshment call? Will have a think abou this...

I've also added a method on the client (update_token()) so that users can manually refresh their token without intervention.

These changes necessitated a bit of a refactor, so 'authentication.py' and 'config.py' now handle the token and the config file respectively. Have a look and let me know if you think it all makes sense, very happy to go through it in person of course!

@jackleland
Copy link
Collaborator Author

Just pushed a small change and a bug-fix: the bug-fix was missing kwargs on the client child classes, the change was refactoring of the update_token method, making instead a distinction between 'refreshing' the token (i.e. sending a request to the auth-token endpoint with a username and password) and 'rereading' the token which involves literally rereading the config file and remaking the Token within the client. The re-reading only happens a single time upon an 'invalid token' response from the API, so we can now have multiple clients on the go at once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant