MCPcopy
hub / github.com/tornadoweb/tornado / get_authenticated_user

Method get_authenticated_user

tornado/auth.py:354–398  ·  view source on GitHub ↗

Gets the OAuth authorized user and access token. This method should be called from the handler for your OAuth callback URL to complete the registration process. We run the callback with the authenticated user dictionary. This dictionary will contain an ``access_key`

(
        self, http_client: Optional[httpclient.AsyncHTTPClient] = None
    )

Source from the content-addressed store, hash-verified

352 self._on_request_token(url, callback_uri, response)
353
354 async def get_authenticated_user(
355 self, http_client: Optional[httpclient.AsyncHTTPClient] = None
356 ) -> Dict[str, Any]:
357 """Gets the OAuth authorized user and access token.
358
359 This method should be called from the handler for your
360 OAuth callback URL to complete the registration process. We run the
361 callback with the authenticated user dictionary. This dictionary
362 will contain an ``access_key`` which can be used to make authorized
363 requests to this service on behalf of the user. The dictionary will
364 also contain other fields such as ``name``, depending on the service
365 used.
366
367 .. versionchanged:: 6.0
368
369 The ``callback`` argument was removed. Use the returned
370 awaitable object instead.
371 """
372 handler = cast(RequestHandler, self)
373 request_key = escape.utf8(handler.get_argument("oauth_token"))
374 oauth_verifier = handler.get_argument("oauth_verifier", None)
375 request_cookie = handler.get_cookie("_oauth_request_token")
376 if not request_cookie:
377 raise AuthError("Missing OAuth request token cookie")
378 handler.clear_cookie("_oauth_request_token")
379 cookie_key, cookie_secret = (
380 base64.b64decode(escape.utf8(i)) for i in request_cookie.split("|")
381 )
382 if cookie_key != request_key:
383 raise AuthError("Request token does not match cookie")
384 token = dict(
385 key=cookie_key, secret=cookie_secret
386 ) # type: Dict[str, Union[str, bytes]]
387 if oauth_verifier:
388 token["verifier"] = oauth_verifier
389 if http_client is None:
390 http_client = self.get_auth_http_client()
391 assert http_client is not None
392 response = await http_client.fetch(self._oauth_access_token_url(token))
393 access_token = _oauth_parse_response(response.body)
394 user = await self._oauth_get_user_future(access_token)
395 if not user:
396 raise AuthError("Error getting user")
397 user["access_token"] = access_token
398 return user
399
400 def _oauth_request_token_url(
401 self,

Callers 10

getMethod · 0.45
getMethod · 0.45
getMethod · 0.45
getMethod · 0.45
getMethod · 0.45
getMethod · 0.45
getMethod · 0.45
getMethod · 0.45
getMethod · 0.45
getMethod · 0.45

Calls 10

get_auth_http_clientMethod · 0.95
AuthErrorClass · 0.85
_oauth_parse_responseFunction · 0.85
get_argumentMethod · 0.80
clear_cookieMethod · 0.80
splitMethod · 0.80
get_cookieMethod · 0.45
fetchMethod · 0.45

Tested by 8

getMethod · 0.36
getMethod · 0.36
getMethod · 0.36
getMethod · 0.36
getMethod · 0.36
getMethod · 0.36
getMethod · 0.36
getMethod · 0.36