MCPcopy Create free account
hub / github.com/authlib/authlib / refresh_token

Method refresh_token

authlib/oauth2/client.py:281–321  ·  view source on GitHub ↗

Fetch a new access token using a refresh token. :param url: Refresh Token endpoint, must be HTTPS. :param refresh_token: The refresh_token to use. :param body: Optional application/x-www-form-urlencoded body to add the include in the token request. Prefe

(
        self, url=None, refresh_token=None, body="", auth=None, headers=None, **kwargs
    )

Source from the content-addressed store, hash-verified

279 return token
280
281 def refresh_token(
282 self, url=None, refresh_token=None, body="", auth=None, headers=None, **kwargs
283 ):
284 """Fetch a new access token using a refresh token.
285
286 :param url: Refresh Token endpoint, must be HTTPS.
287 :param refresh_token: The refresh_token to use.
288 :param body: Optional application/x-www-form-urlencoded body to add the
289 include in the token request. Prefer kwargs over body.
290 :param auth: An auth tuple or method as accepted by requests.
291 :param headers: Dict to default request headers with.
292 :return: A :class:`OAuth2Token` object (a dict too).
293 """
294 session_kwargs = self._extract_session_request_params(kwargs)
295 refresh_token = refresh_token or self.token.get("refresh_token")
296 if "scope" not in kwargs and self.scope:
297 kwargs["scope"] = self.scope
298 body = prepare_token_request(
299 "refresh_token", body, refresh_token=refresh_token, **kwargs
300 )
301
302 if headers is None:
303 headers = DEFAULT_HEADERS.copy()
304
305 if url is None:
306 url = self.metadata.get("token_endpoint")
307
308 for hook in self.compliance_hook["refresh_token_request"]:
309 url, headers, body = hook(url, headers, body)
310
311 if auth is None:
312 auth = self.client_auth(self.token_endpoint_auth_method)
313
314 return self._refresh_token(
315 url,
316 refresh_token=refresh_token,
317 body=body,
318 headers=headers,
319 auth=auth,
320 **session_kwargs,
321 )
322
323 def ensure_active_token(self, token=None):
324 if token is None:

Calls 5

client_authMethod · 0.95
_refresh_tokenMethod · 0.95
prepare_token_requestFunction · 0.85
getMethod · 0.45