Debian Codegraph @

src/auth0/authentication/delegated.py

raw symbols SCIP
1 from __future__ import annotations
2
3 from typing import Any
4
5 from .base import AuthenticationBase
6
7
8 class Delegated(AuthenticationBase):
9 """Delegated authentication endpoints.
10
11 Args:
12 domain (str): Your auth0 domain (e.g: username.auth0.com)
13 """
14
15 def get_token(
16 self,
17 target: str,
18 api_type: str,
19 grant_type: str,
20 id_token: str | None = None,
21 refresh_token: str | None = None,
22 scope: str = "openid",
23 ) -> Any:
24 """Obtain a delegation token."""
25
26 if id_token and refresh_token:
27 raise ValueError("Only one of id_token or refresh_token can be None")
28
29 data = {
30 "client_id": self.client_id,
31 "grant_type": grant_type,
32 "target": target,
33 "scope": scope,
34 "api_type": api_type,
35 }
36
37 if id_token:
38 data.update({"id_token": id_token})
39 elif refresh_token:
40 data.update({"refresh_token": refresh_token})
41 else:
42 raise ValueError("Either id_token or refresh_token must have a value")
43
44 return self.post(f"{self.protocol}://{self.domain}/delegation", data=data)