Debian Codegraph @

src/auth0/authentication/users.py

raw symbols SCIP
1 from __future__ import annotations
2
3 from typing import Any
4
5 from .rest import RestClient, RestClientOptions
6 from .types import TimeoutType
7
8
9 class Users:
10 """Users client.
11
12 Args:
13 domain (str): The domain of your Auth0 tenant
14 telemetry (bool, optional): Enable or disable telemetry (defaults to True)
15 timeout (float or tuple, optional): Change the requests connect and read timeout. Pass a tuple to specify both values separately or a float to set both to it. (defaults to 5.0 for both)
16 protocol (str, optional): Useful for testing. (defaults to 'https')
17 """
18
19 def __init__(
20 self,
21 domain: str,
22 telemetry: bool = True,
23 timeout: TimeoutType = 5.0,
24 protocol: str = "https",
25 ) -> None:
26 self.domain = domain
27 self.protocol = protocol
28 self.client = RestClient(
29 None,
30 options=RestClientOptions(telemetry=telemetry, timeout=timeout, retries=0),
31 )
32
33 """Userinfo related endpoints.
34
35 Args:
36 domain (str): Your auth0 domain (e.g: username.auth0.com)
37 """
38
39 def userinfo(self, access_token: str) -> dict[str, Any]:
40 """Returns the user information based on the Auth0 access token.
41 This endpoint will work only if openid was granted as a scope for the access_token.
42
43 Args:
44 access_token (str): Auth0 access token (obtained during login).
45
46 Returns:
47 The user profile.
48 """
49 data: dict[str, Any] = self.client.get(
50 url=f"{self.protocol}://{self.domain}/userinfo",
51 headers={"Authorization": f"Bearer {access_token}"},
52 )
53 return data