Repository navigation
Expand file tree
/
Copy pathtypes.py
More file actions
53 lines (42 loc) · 1.75 KB
/
Copy pathtypes.py
File metadata and controls
53 lines (42 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Type definitions for auth0-api-python SDK
"""
from collections.abc import Awaitable, Callable
from typing import Optional, TypedDict, Union
class DomainsResolverContext(TypedDict, total=False):
"""
Context passed to domains resolver functions.
Attributes:
request_url: The URL the API request was made to (optional)
request_headers: Request headers dict (e.g., Host, X-Forwarded-Host) (optional)
unverified_iss: The issuer claim from the unverified token
"""
request_url: Optional[str]
request_headers: Optional[dict]
unverified_iss: str
DomainsResolver = Callable[
[DomainsResolverContext], Union[list[str], Awaitable[list[str]]]
]
"""
Type alias for domains resolver function.
A DomainsResolver is a sync or async function that receives a DomainsResolverContext
and returns a list of allowed domain strings.
Args:
context (DomainsResolverContext): Dictionary containing:
- 'request_url' (str | None): The URL the API request was made to
- 'request_headers' (dict | None): Request headers (e.g., Host, X-Forwarded-Host)
- 'unverified_iss' (str): The issuer claim from the unverified token
Returns:
list[str]: List of allowed domain strings (e.g., ['tenant.auth0.com'])
Example (sync):
from auth0_api_python import DomainsResolverContext
def my_resolver(context: DomainsResolverContext) -> list[str]:
host = (context.get('request_headers') or {}).get('host')
if host == 'api.brand.com':
return ['brand.custom-domain.com']
return ['tenant.auth0.com']
Example (async):
async def my_async_resolver(context: DomainsResolverContext) -> list[str]:
domains = await db.lookup_domains(context['unverified_iss'])
return domains
"""