1
-
2
1
from __future__ import annotations
3
2
4
- from typing import Any , Dict , Optional , Union
3
+ from typing import Any , Dict , Optional
5
4
6
5
import jwt
7
6
7
+ from stytch .b2b .models .idp import AccessTokenJWTClaims , AccessTokenJWTResponse
8
8
from stytch .core .api_base import ApiBase
9
9
from stytch .core .http .client import AsyncClient , SyncClient
10
- from stytch .shared import jwt_helpers , rbac_local
10
+ from stytch .shared import jwt_helpers
11
11
from stytch .shared .policy_cache import PolicyCache
12
- from stytch . b2b . models . idp import AccessTokenJWTClaims , AccessTokenJWTResponse
12
+
13
13
14
14
class IDP :
15
15
def __init__ (
@@ -27,7 +27,6 @@ def __init__(
27
27
self .policy_cache = policy_cache
28
28
self .jwks_client = jwks_client
29
29
self .project_id = project_id
30
-
31
30
32
31
# MANUAL(introspect_idp_access_token)(SERVICE_METHOD)
33
32
# ADDIMPORT: from typing import Optional
@@ -37,10 +36,15 @@ def introspect_idp_access_token(
37
36
access_token : str ,
38
37
client_id : str ,
39
38
client_secret : Optional [str ] = None ,
40
- grant_type : str = ' authorization_code' ,
41
- token_type_hint : str = ' access_token'
39
+ grant_type : str = " authorization_code" ,
40
+ token_type_hint : str = " access_token" ,
42
41
) -> Optional [AccessTokenJWTClaims ]:
43
- return self .introspect_idp_access_token_local (access_token , client_id ) or self .introspect_idp_access_token_network (access_token , client_id , client_secret , grant_type , token_type_hint )
42
+ return self .introspect_idp_access_token_local (
43
+ access_token , client_id
44
+ ) or self .introspect_idp_access_token_network (
45
+ access_token , client_id , client_secret , grant_type , token_type_hint
46
+ )
47
+
44
48
# ENDMANUAL(introspect_idp_access_token)
45
49
46
50
# MANUAL(introspect_idp_access_token_network)(SERVICE_METHOD)
@@ -53,30 +57,30 @@ def introspect_idp_access_token_network(
53
57
access_token : str ,
54
58
client_id : str ,
55
59
client_secret : Optional [str ] = None ,
56
- grant_type : str = ' authorization_code' ,
57
- token_type_hint : str = ' access_token'
60
+ grant_type : str = " authorization_code" ,
61
+ token_type_hint : str = " access_token" ,
58
62
) -> Optional [AccessTokenJWTClaims ]:
59
- headers : Dict [str , str ] = {
60
- "Content-Type" : "application/x-www-form-urlencoded"
61
- }
63
+ headers : Dict [str , str ] = {"Content-Type" : "application/x-www-form-urlencoded" }
62
64
data : Dict [str , Any ] = {
63
65
"token" : access_token ,
64
66
"client_id" : client_id ,
65
67
"grant_type" : grant_type ,
66
- "token_type_hint" : token_type_hint
68
+ "token_type_hint" : token_type_hint ,
67
69
}
68
70
if client_secret is not None :
69
71
data ["client_secret" ] = client_secret
70
72
71
- url = self .api_base .url_for (f"/v1/public/{ self .project_id } /oauth2/introspect" , data )
73
+ url = self .api_base .url_for (
74
+ f"/v1/public/{ self .project_id } /oauth2/introspect" , data
75
+ )
72
76
res = self .sync_client .postForm (url , data , headers )
73
- jwtResponse = AccessTokenJWTResponse .from_json (res .response .status_code , res .json )
77
+ jwtResponse = AccessTokenJWTResponse .from_json (
78
+ res .response .status_code , res .json
79
+ )
74
80
if not jwtResponse .active :
75
81
return None
76
82
return AccessTokenJWTClaims (
77
- subject = jwtResponse .sub ,
78
- scopes = jwtResponse .scope ,
79
- custom_claims = None
83
+ subject = jwtResponse .sub , scopes = jwtResponse .scope , custom_claims = None
80
84
)
81
85
82
86
# ENDMANUAL(introspect_idp_access_token_network)
@@ -96,7 +100,7 @@ def introspect_idp_access_token_local(
96
100
jwks_client = self .jwks_client ,
97
101
jwt = access_token ,
98
102
custom_audience = client_id ,
99
- custom_issuer = f"https://stytch.com/{ self .project_id } "
103
+ custom_issuer = f"https://stytch.com/{ self .project_id } " ,
100
104
)
101
105
if generic_claims is None :
102
106
return None
@@ -108,7 +112,7 @@ def introspect_idp_access_token_local(
108
112
return AccessTokenJWTClaims (
109
113
subject = generic_claims .reserved_claims ["sub" ],
110
114
scopes = generic_claims .untyped_claims [_scope_claim ],
111
- custom_claims = custom_claims
115
+ custom_claims = custom_claims ,
112
116
)
113
117
114
- # ENDMANUAL(introspect_idp_access_token_local)
118
+ # ENDMANUAL(introspect_idp_access_token_local)
0 commit comments