Skip to content

Commit

Permalink
Make token refresh more user friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
nosnilmot committed Feb 3, 2024
1 parent 85f9ff9 commit 16fa567
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions authlib/oauth2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def token_from_fragment(self, authorization_response, state=None):
self.token = token
return token

def refresh_token(self, url, refresh_token=None, body='',
def refresh_token(self, url=None, refresh_token=None, body='',
auth=None, headers=None, **kwargs):
"""Fetch a new access token using a refresh token.
Expand All @@ -247,6 +247,9 @@ def refresh_token(self, url, refresh_token=None, body='',
if headers is None:
headers = DEFAULT_HEADERS.copy()

if url is None:
url = self.metadata.get('token_endpoint')

for hook in self.compliance_hook['refresh_token_request']:
url, headers, body = hook(url, headers, body)

Expand All @@ -257,7 +260,9 @@ def refresh_token(self, url, refresh_token=None, body='',
url, refresh_token=refresh_token, body=body, headers=headers,
auth=auth, **session_kwargs)

def ensure_active_token(self, token):
def ensure_active_token(self, token=None):
if token is None:
token = self.token
if not token.is_expired():
return True
refresh_token = token.get('refresh_token')
Expand Down

0 comments on commit 16fa567

Please sign in to comment.