-
Notifications
You must be signed in to change notification settings - Fork 4
oauth token caching #110
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
oauth token caching #110
Conversation
geokollias
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Helmi! Have added some (mostly minor) comments/questions.
railib/rest.py
Outdated
| except Exception: | ||
| return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see we swallow these exceptions in these cache functions (the go sdk does sth similar as well). Is that on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I do understand, if the cache is not accessible for some reason we should not block the user and instead we request a new token
| else: | ||
| cache = {creds.client_id: creds.access_token} | ||
| with open(_cache_file(), 'w') as f: | ||
| f.write(json.dumps(cache, default=vars)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's default=vars needed for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is one way to make python class json serializable
railib/rest.py
Outdated
| if cache: | ||
| cache[creds.client_id] = creds.access_token | ||
| else: | ||
| cache = {creds.client_id: creds.access_token} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we could avoid this branch by returning {} from _read_cache's exception path
| def _read_token_cache(creds: ClientCredentials) -> AccessToken: | ||
| try: | ||
| cache = _read_cache() | ||
| return AccessToken(**cache[creds.client_id]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume if the cache doesn't contain that client id an exception is thrown?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep that's true and we just by-pass it, if _read_token_cache function return None we will request a new token anyway
This PR adds support to oauth token caching