Skip to content

Commit acf81b3

Browse files
committed
Consider auto_refresh_kwargs for token refresh authentication.\nThis is a follow-up on requests#340.
1 parent d75279c commit acf81b3

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

requests_oauthlib/oauth2_session.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,15 @@ def refresh_token(
418418
"Adding auto refresh key word arguments %s.", self.auto_refresh_kwargs
419419
)
420420
kwargs.update(self.auto_refresh_kwargs)
421+
422+
auth = auth or kwargs.pop('auth', None)
423+
client_id = kwargs.get('client_id')
424+
client_secret = kwargs.get('client_secret', '')
425+
426+
if client_id and (auth is None):
427+
log.debug('Encoding client_id "%s" with client_secret as Basic auth credentials.', client_id)
428+
auth = requests.auth.HTTPBasicAuth(client_id, client_secret)
429+
421430
body = self._client.prepare_refresh_body(
422431
body=body, refresh_token=refresh_token, scope=self.scope, **kwargs
423432
)
@@ -491,16 +500,9 @@ def request(
491500
self.auto_refresh_url,
492501
)
493502

494-
# We mustn't pass auth twice.
495-
auth = kwargs.pop("auth", None)
496-
if client_id and client_secret and (auth is None):
497-
log.debug(
498-
'Encoding client_id "%s" with client_secret as Basic auth credentials.',
499-
client_id,
500-
)
501-
auth = requests.auth.HTTPBasicAuth(client_id, client_secret)
502503
token = self.refresh_token(
503-
self.auto_refresh_url, auth=auth, **kwargs
504+
self.auto_refresh_url, client_id=client_id,
505+
client_secret=client_secret, **kwargs
504506
)
505507
if self.token_updater:
506508
log.debug(

0 commit comments

Comments
 (0)