lepture / authlib

The ultimate Python library in building OAuth, OpenID Connect clients and servers. JWS,JWE,JWK,JWA,JWT included.
https://authlib.org/
BSD 3-Clause "New" or "Revised" License
4.49k stars 448 forks source link

Support Retries for fetching and refreshing tokens if the token endpoint gives 500 server errors #520

Closed pghole closed 1 year ago

pghole commented 1 year ago

Is your feature request related to a problem? Please describe.

If the token url gives say 503, then the fetch token doesn't perform the retry (number of retries should be configurable). The sessions adapter method does support retries but if we are using the "get" on the oauth2client as follows, how to send the configure the session adapter/retry settings

oauth_client = OAuth2Session(client_id=client_id,
                             client_secret=client_secret,
                             token_endpoint=token_url,
                             grant_type='client_credentials',
                             verify=ssl)
oauth_client.fetch_token(token_url)  # Can we retry if this fails in 1st attempt.
oauth.get(url)  # can we retry here if the existing token fails and the authlib attempts to fetch new token and there it meets 503 for token_url

Describe the solution you'd like

Need help on how we can enable and pass custom retries to the final request made by the authlib to fetch tokens.

Describe alternatives you've considered

To do this manually using while loop and retry the request.

Additional context

Add any other context or screenshots about the feature request here.

lepture commented 1 year ago

You can try to call . fetch_token several times yourself. Authlib will not add this logic.