Skip to content

Commit 502bcb0

Browse files
authored
feat: [AUTH-5729] Scaffold idp for codegen (#284)
1 parent 7fc7f0f commit 502bcb0

File tree

3 files changed

+85
-37
lines changed

3 files changed

+85
-37
lines changed

stytch/b2b/api/idp.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# !!!
2+
# WARNING: This file is autogenerated
3+
# Only modify code within MANUAL() sections
4+
# or your changes may be overwritten later!
5+
# !!!
6+
17
from __future__ import annotations
28

39
from typing import Any, Dict, Optional
@@ -25,26 +31,14 @@ def __init__(
2531
self.api_base = api_base
2632
self.sync_client = sync_client
2733
self.async_client = async_client
34+
self.policy_cache = policy_cache
2835
self.jwks_client = jwks_client
2936
self.project_id = project_id
30-
self.non_custom_claim_keys = [
31-
"aud",
32-
"exp",
33-
"iat",
34-
"iss",
35-
"jti",
36-
"nbf",
37-
"sub",
38-
"active",
39-
"client_id",
40-
"request_id",
41-
"scope",
42-
"status_code",
43-
"token_type",
44-
"https://stytch.com/organization",
45-
]
46-
self.policy_cache = policy_cache
4737

38+
# MANUAL(IDP)(SERVICE_METHOD)
39+
# ADDIMPORT: from stytch.b2b.models.sessions import AuthorizationCheck
40+
# ADDIMPORT: from stytch.shared import jwt_helpers, rbac_local
41+
# ADDIMPORT: from stytch.consumer.models.idp import IDPTokenClaims, IDPTokenResponse
4842
def introspect_token_network(
4943
self,
5044
token: str,
@@ -80,7 +74,7 @@ def introspect_token_network(
8074
if not jwtResponse.active:
8175
return None
8276
custom_claims = {
83-
k: v for k, v in res.json.items() if k not in self.non_custom_claim_keys
77+
k: v for k, v in res.json.items() if k not in self._non_custom_claim_keys()
8478
}
8579
organization_claim = res.json["https://stytch.com/organization"]
8680
organization_id = organization_claim["organization_id"]
@@ -142,7 +136,7 @@ async def introspect_token_network_async(
142136
if not jwtResponse.active:
143137
return None
144138
custom_claims = {
145-
k: v for k, v in res.json.items() if k not in self.non_custom_claim_keys
139+
k: v for k, v in res.json.items() if k not in self._non_custom_claim_keys()
146140
}
147141
organization_claim = res.json["https://stytch.com/organization"]
148142
organization_id = organization_claim["organization_id"]
@@ -222,3 +216,22 @@ def introspect_access_token_local(
222216
token_type="access_token",
223217
organization_claim=org_claim,
224218
)
219+
220+
def _non_custom_claim_keys(self):
221+
return [
222+
"aud",
223+
"exp",
224+
"iat",
225+
"iss",
226+
"jti",
227+
"nbf",
228+
"sub",
229+
"active",
230+
"client_id",
231+
"request_id",
232+
"scope",
233+
"status_code",
234+
"token_type",
235+
]
236+
237+
# ENDMANUAL(IDP)

stytch/consumer/api/idp.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# !!!
2+
# WARNING: This file is autogenerated
3+
# Only modify code within MANUAL() sections
4+
# or your changes may be overwritten later!
5+
# !!!
6+
17
from __future__ import annotations
28

39
from typing import Any, Dict, Optional
@@ -25,25 +31,14 @@ def __init__(
2531
self.api_base = api_base
2632
self.sync_client = sync_client
2733
self.async_client = async_client
34+
self.policy_cache = policy_cache
2835
self.jwks_client = jwks_client
2936
self.project_id = project_id
30-
self.non_custom_claim_keys = [
31-
"aud",
32-
"exp",
33-
"iat",
34-
"iss",
35-
"jti",
36-
"nbf",
37-
"sub",
38-
"active",
39-
"client_id",
40-
"request_id",
41-
"scope",
42-
"status_code",
43-
"token_type",
44-
]
45-
self.policy_cache = policy_cache
4637

38+
# MANUAL(IDP)(SERVICE_METHOD)
39+
# ADDIMPORT: from stytch.shared import jwt_helpers, rbac_local
40+
# ADDIMPORT: from stytch.consumer.models.idp import IDPTokenClaims, IDPTokenResponse
41+
# ADDIMPORT: from stytch.consumer.models.sessions import AuthorizationCheck
4742
def introspect_token_network(
4843
self,
4944
token: str,
@@ -78,7 +73,7 @@ def introspect_token_network(
7873
res = self.sync_client.post_form(url, data, headers)
7974
jwtResponse = IDPTokenResponse.from_json(res.response.status_code, res.json)
8075
custom_claims = {
81-
k: v for k, v in res.json.items() if k not in self.non_custom_claim_keys
76+
k: v for k, v in res.json.items() if k not in self._non_custom_claim_keys()
8277
}
8378
if not jwtResponse.active:
8479
return None
@@ -135,7 +130,7 @@ async def introspect_token_network_async(
135130
res = await self.async_client.post_form(url, data, headers)
136131
jwtResponse = IDPTokenResponse.from_json(res.response.status, res.json)
137132
custom_claims = {
138-
k: v for k, v in res.json.items() if k not in self.non_custom_claim_keys
133+
k: v for k, v in res.json.items() if k not in self._non_custom_claim_keys()
139134
}
140135
if not jwtResponse.active:
141136
return None
@@ -207,3 +202,22 @@ def introspect_access_token_local(
207202
not_before=generic_claims.reserved_claims["nbf"],
208203
token_type="access_token",
209204
)
205+
206+
def _non_custom_claim_keys(self):
207+
return [
208+
"aud",
209+
"exp",
210+
"iat",
211+
"iss",
212+
"jti",
213+
"nbf",
214+
"sub",
215+
"active",
216+
"client_id",
217+
"request_id",
218+
"scope",
219+
"status_code",
220+
"token_type",
221+
]
222+
223+
# ENDMANUAL(IDP)

stytch/consumer/models/idp.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1+
# !!!
2+
# WARNING: This file is autogenerated
3+
# Only modify code within MANUAL() sections
4+
# or your changes may be overwritten later!
5+
# !!!
6+
7+
from __future__ import annotations
8+
19
from typing import Any, Dict, List, Optional
210

311
import pydantic
412

513
from stytch.core.response_base import ResponseBase
614

715

16+
class ScopeResult(pydantic.BaseModel):
17+
scope: str
18+
description: str
19+
is_grantable: bool
20+
21+
22+
# MANUAL(IDP)(TYPES)
23+
# ADDIMPORT: from stytch.core.response_base import ResponseBase
24+
25+
826
class IDPTokenResponse(ResponseBase):
927
"""Response type for `IDP.introspect_token_network`.
1028
Fields:
@@ -54,3 +72,6 @@ class IDPTokenClaims(pydantic.BaseModel):
5472
not_before: Optional[int]
5573
token_type: Optional[str]
5674
organization_claim: Optional[Dict[str, Any]] = None
75+
76+
77+
# ENDMANUAL(IDP)

0 commit comments

Comments
 (0)