Make it possible to use sub-strategies to get offline unexpired access tokens #185
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Do people use
omniauth-oauth2
sub-strategies to instantiate, and possibly refresh, access tokens from tokens saved from the authorization flow (offline access), or do they directly instantiateoauth2
Client
andAccessToken
classes? If the latter, it seems to me that much of the work done by, and settings in, the strategies must be duplicated, especially the various options.This PR adds a
refresh_access_token
method that encapsulates the sametoken_params
andoptions.auth_token_params
settings as used in getting the access token during the authorization flow. This is now also called when the token is already expired when obtained. Does this happen?A
set_access_token_from_hash
utility method is also added so that the common requirement of setting the access token from a saved hash needs less code.Example code to generate an unexpired access token from saved access and refresh tokens becomes:
An alternative is a
strategy.get_unexpired_access_token_from_hash
method that incorporates the code above, with a good way to detect a refreshed token so it can be saved.