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

Integrate authlib instead of doing oauth manually. #42

Merged
merged 6 commits into from
Jan 20, 2024
Merged

Integrate authlib instead of doing oauth manually. #42

merged 6 commits into from
Jan 20, 2024

Conversation

caarmen
Copy link
Owner

@caarmen caarmen commented Jan 13, 2024

Configure authlib.

Add compliance hooks for withings behavior which deviates from default behavior expected by authlib.

For the token update hook: we don't have access to the dependency injection in FastAPI, which provides a db session: yet we need to write the new token to the database. Save the db session in a ContextVar to make it accessible from the update token hook.

Regarding refreshing the token:

  • Remove our custom decorator which was refreshing the token upon a 401 error to a resource request.
  • Adapt test_retry_authentication to be test_refresh_token
  • When we get/refresh our access token, save it in the db with an expiration date which is a few minutes sooner than the real one. This will help ensure that we'll fetch a new token when we want to do a resource request and our token is about to expire.

@caarmen caarmen force-pushed the authlib branch 4 times, most recently from 9bb6b89 to 50e78b6 Compare January 14, 2024 19:56
@caarmen caarmen force-pushed the authlib branch 2 times, most recently from c5f09b4 to f0c0de8 Compare January 19, 2024 23:15
@caarmen caarmen changed the title [WIP] Integrate authlib instead of doing oauth manually. Withings: Integrate authlib instead of doing oauth manually. Jan 19, 2024
Configure authlib.

Add compliance hooks for withings behavior which deviates from default behavior expected by authlib.

For the token update hook: we don't have access to the dependency injection in FastAPI, which provides a db session: yet we need to write the new token to the database. Save the db session in a `ContextVar` to make it accessible from the update token hook.

Regarding refreshing the token:
* Remove our custom decorator which was refreshing the token upon a 401 error to a resource request.
* Adapt `test_retry_authentication` to be `test_refresh_token`
* When we get/refresh our access token, save it in the db with an expiration date which is a few minutes sooner than the real one. This will help ensure that we'll fetch a new token when we want to do a resource request and our token is about to expire.
This works for the initial token request, but not for automatic token refresh.
Send the client secret in requests.
Add compliance hooks for fitbit behavior which deviates from default behavior expected by authlib.

Regarding refreshing the token:
* Remove our custom decorator which was refreshing the token upon a 401 error to a resource request.
* When we get/refresh our access token, save it in the db with an expiration date which is a few minutes sooner than the real one. This will help ensure that we'll fetch a new token when we want to do a resource request and our token is about to expire.
* Adapt `test_retry_authentication` to be `test_refresh_token`
@caarmen caarmen marked this pull request as ready for review January 20, 2024 15:19
Fitbit: Integrate authlib instead of doing oauth manually
@caarmen caarmen changed the title Withings: Integrate authlib instead of doing oauth manually. Integrate authlib instead of doing oauth manually. Jan 20, 2024
@caarmen caarmen merged commit a80a04b into main Jan 20, 2024
@caarmen caarmen deleted the authlib branch January 20, 2024 15:21
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