Skip to content

Commit

Permalink
Merge pull request #625 from nosnilmot/token-refresh
Browse files Browse the repository at this point in the history
Make token refresh more user friendly
  • Loading branch information
lepture authored Feb 28, 2024
2 parents 23b8b43 + 16fa567 commit 5ac4680
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 5ac4680

Please sign in to comment.