Skip to content

Commit

Permalink
Consider auto_refresh_kwargs for token refresh authentication.\nThis …
Browse files Browse the repository at this point in the history
…is a follow-up on requests#340.
  • Loading branch information
fodinabor committed Apr 21, 2020
1 parent d75279c commit acf81b3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions requests_oauthlib/oauth2_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,15 @@ def refresh_token(
"Adding auto refresh key word arguments %s.", self.auto_refresh_kwargs
)
kwargs.update(self.auto_refresh_kwargs)

auth = auth or kwargs.pop('auth', None)
client_id = kwargs.get('client_id')
client_secret = kwargs.get('client_secret', '')

if client_id and (auth is None):
log.debug('Encoding client_id "%s" with client_secret as Basic auth credentials.', client_id)
auth = requests.auth.HTTPBasicAuth(client_id, client_secret)

body = self._client.prepare_refresh_body(
body=body, refresh_token=refresh_token, scope=self.scope, **kwargs
)
Expand Down Expand Up @@ -491,16 +500,9 @@ def request(
self.auto_refresh_url,
)

# We mustn't pass auth twice.
auth = kwargs.pop("auth", None)
if client_id and client_secret and (auth is None):
log.debug(
'Encoding client_id "%s" with client_secret as Basic auth credentials.',
client_id,
)
auth = requests.auth.HTTPBasicAuth(client_id, client_secret)
token = self.refresh_token(
self.auto_refresh_url, auth=auth, **kwargs
self.auto_refresh_url, client_id=client_id,
client_secret=client_secret, **kwargs
)
if self.token_updater:
log.debug(
Expand Down

0 comments on commit acf81b3

Please sign in to comment.