-
Notifications
You must be signed in to change notification settings - Fork 215
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
Improve Oauth2 API for handling tokens persistence with SQL #207
Comments
I think you can accomplish this with the current API, by creating a custom lock-like object that calls your
|
Yes that's right. I'm merely suggesting what I think is an improvement that looks like the right abstraction to me and can avoid a hidden state solution. |
I'm trying to accommodate storing my tokens in an SQL database, and trying to extend the
OAuth2
class to enable storing and retrieving the tokens from the database. The_refresh_lock
is something that is naturally also managed by the same database. (You have a conceptually similar implementation for redis withRedisManagedOAuth2
)What you would typically do with SQL in order to lock a specific row to update it (exactly what we want to do here) is use the
SELECT ... FOR UPDATE
command, which locks and retrieves the data at the same timeThe existing code where the lock is used (
box-python-sdk/boxsdk/auth/oauth2.py
Lines 201 to 202 in 6597e93
box-python-sdk/boxsdk/auth/oauth2.py
Lines 305 to 306 in 6597e93
What I'm looking for is this
Well, I can't really extend the class to achieve that unless I rewrite the whole methods
refresh
andrevoke
. I think a better API to express the need to "lock tokens and retrieve them" is with its own context manager function, that can have a default implementation that can be overridden. This contextmanager can be trivially rewritten to use select for updateThe text was updated successfully, but these errors were encountered: