Skip to content

Commit 632b5dd

Browse files
committed
fix: openid and cookies
1 parent 91926ae commit 632b5dd

File tree

6 files changed

+130
-20
lines changed

6 files changed

+130
-20
lines changed

supertokens_python/recipe/oauth2provider/api/auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
from __future__ import annotations
1616

17-
from datetime import datetime
1817
from http.cookies import SimpleCookie
1918
from typing import TYPE_CHECKING, Any, Dict
2019
from urllib.parse import parse_qsl
20+
from dateutil import parser
2121

2222
from supertokens_python.recipe.session.asyncio import get_session
2323
from supertokens_python.recipe.session.exceptions import TryRefreshTokenError
@@ -85,7 +85,7 @@ async def auth_get(
8585
domain=morsel.get("domain"),
8686
secure=morsel.get("secure", True),
8787
httponly=morsel.get("httponly", True),
88-
expires=datetime.strptime(morsel.get("expires", ""), "%a, %d %b %Y %H:%M:%S %Z").timestamp() * 1000, # type: ignore
88+
expires=parser.parse(morsel.get("expires", "")).timestamp() * 1000, # type: ignore
8989
path=morsel.get("path", "/"),
9090
samesite=morsel.get("samesite", "lax"),
9191
)

supertokens_python/recipe/oauth2provider/api/login.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from typing import TYPE_CHECKING, Any, Dict, Optional
1818

19-
from datetime import datetime
19+
from dateutil import parser
2020

2121
from supertokens_python.exceptions import raise_bad_input_exception
2222
from supertokens_python.framework import BaseResponse
@@ -87,7 +87,7 @@ async def login(
8787
domain=morsel.get("domain"),
8888
secure=morsel.get("secure", True),
8989
httponly=morsel.get("httponly", True),
90-
expires=datetime.strptime(morsel.get("expires", ""), "%a, %d %b %Y %H:%M:%S %Z").timestamp() * 1000, # type: ignore
90+
expires=parser.parse(morsel.get("expires", "")).timestamp() * 1000, # type: ignore
9191
path=morsel.get("path", "/"),
9292
samesite=morsel.get("samesite", "lax").lower(),
9393
)

supertokens_python/recipe/oauth2provider/recipe.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,8 @@ async def get_default_access_token_payload(
346346
payload["emails"] = user.emails
347347

348348
if "phoneNumber" in scopes:
349-
payload["phoneNumber"] = (
350-
user.phone_numbers[0] if user.phone_numbers else None
351-
)
349+
if user.phone_numbers:
350+
payload["phoneNumber"] = user.phone_numbers[0]
352351
payload["phoneNumber_verified"] = (
353352
any(
354353
lm.has_same_phone_number_as(user.phone_numbers[0]) and lm.verified
@@ -387,9 +386,8 @@ async def get_default_id_token_payload(
387386
payload["emails"] = user.emails
388387

389388
if "phoneNumber" in scopes:
390-
payload["phoneNumber"] = (
391-
user.phone_numbers[0] if user.phone_numbers else None
392-
)
389+
if user.phone_numbers:
390+
payload["phoneNumber"] = user.phone_numbers[0]
393391
payload["phoneNumber_verified"] = (
394392
any(
395393
lm.has_same_phone_number_as(user.phone_numbers[0]) and lm.verified

supertokens_python/recipe/openid/api/implementation.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,15 @@ async def open_id_discovery_configuration_get(
3030
)
3131
)
3232
return OpenIdDiscoveryConfigurationGetResponse(
33-
response.issuer, response.jwks_uri
33+
issuer=response.issuer,
34+
jwks_uri=response.jwks_uri,
35+
authorization_endpoint=response.authorization_endpoint,
36+
token_endpoint=response.token_endpoint,
37+
userinfo_endpoint=response.userinfo_endpoint,
38+
revocation_endpoint=response.revocation_endpoint,
39+
token_introspection_endpoint=response.token_introspection_endpoint,
40+
end_session_endpoint=response.end_session_endpoint,
41+
subject_types_supported=response.subject_types_supported,
42+
id_token_signing_alg_values_supported=response.id_token_signing_alg_values_supported,
43+
response_types_supported=response.response_types_supported,
3444
)

supertokens_python/recipe/openid/interfaces.py

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414
from abc import ABC, abstractmethod
15-
from typing import Any, Dict, Union, Optional
15+
from typing import Any, Dict, List, Union, Optional
1616

1717
from supertokens_python.framework import BaseRequest, BaseResponse
1818
from supertokens_python.recipe.jwt.interfaces import (
@@ -26,9 +26,48 @@
2626

2727

2828
class GetOpenIdDiscoveryConfigurationResult:
29-
def __init__(self, issuer: str, jwks_uri: str):
29+
def __init__(
30+
self,
31+
issuer: str,
32+
jwks_uri: str,
33+
authorization_endpoint: str,
34+
token_endpoint: str,
35+
userinfo_endpoint: str,
36+
revocation_endpoint: str,
37+
token_introspection_endpoint: str,
38+
end_session_endpoint: str,
39+
subject_types_supported: List[str],
40+
id_token_signing_alg_values_supported: List[str],
41+
response_types_supported: List[str],
42+
):
3043
self.issuer = issuer
3144
self.jwks_uri = jwks_uri
45+
self.authorization_endpoint = authorization_endpoint
46+
self.token_endpoint = token_endpoint
47+
self.userinfo_endpoint = userinfo_endpoint
48+
self.revocation_endpoint = revocation_endpoint
49+
self.token_introspection_endpoint = token_introspection_endpoint
50+
self.end_session_endpoint = end_session_endpoint
51+
self.subject_types_supported = subject_types_supported
52+
self.id_token_signing_alg_values_supported = (
53+
id_token_signing_alg_values_supported
54+
)
55+
self.response_types_supported = response_types_supported
56+
57+
def to_json(self) -> Dict[str, Any]:
58+
return {
59+
"issuer": self.issuer,
60+
"jwks_uri": self.jwks_uri,
61+
"authorization_endpoint": self.authorization_endpoint,
62+
"token_endpoint": self.token_endpoint,
63+
"userinfo_endpoint": self.userinfo_endpoint,
64+
"revocation_endpoint": self.revocation_endpoint,
65+
"token_introspection_endpoint": self.token_introspection_endpoint,
66+
"end_session_endpoint": self.end_session_endpoint,
67+
"subject_types_supported": self.subject_types_supported,
68+
"id_token_signing_alg_values_supported": self.id_token_signing_alg_values_supported,
69+
"response_types_supported": self.response_types_supported,
70+
}
3271

3372

3473
class RecipeInterface(ABC):
@@ -75,12 +114,49 @@ def __init__(
75114
class OpenIdDiscoveryConfigurationGetResponse(APIResponse):
76115
status: str = "OK"
77116

78-
def __init__(self, issuer: str, jwks_uri: str):
117+
def __init__(
118+
self,
119+
issuer: str,
120+
jwks_uri: str,
121+
authorization_endpoint: str,
122+
token_endpoint: str,
123+
userinfo_endpoint: str,
124+
revocation_endpoint: str,
125+
token_introspection_endpoint: str,
126+
end_session_endpoint: str,
127+
subject_types_supported: List[str],
128+
id_token_signing_alg_values_supported: List[str],
129+
response_types_supported: List[str],
130+
):
79131
self.issuer = issuer
80132
self.jwks_uri = jwks_uri
133+
self.authorization_endpoint = authorization_endpoint
134+
self.token_endpoint = token_endpoint
135+
self.userinfo_endpoint = userinfo_endpoint
136+
self.revocation_endpoint = revocation_endpoint
137+
self.token_introspection_endpoint = token_introspection_endpoint
138+
self.end_session_endpoint = end_session_endpoint
139+
self.subject_types_supported = subject_types_supported
140+
self.id_token_signing_alg_values_supported = (
141+
id_token_signing_alg_values_supported
142+
)
143+
self.response_types_supported = response_types_supported
81144

82145
def to_json(self):
83-
return {"status": self.status, "issuer": self.issuer, "jwks_uri": self.jwks_uri}
146+
return {
147+
"status": self.status,
148+
"issuer": self.issuer,
149+
"jwks_uri": self.jwks_uri,
150+
"authorization_endpoint": self.authorization_endpoint,
151+
"token_endpoint": self.token_endpoint,
152+
"userinfo_endpoint": self.userinfo_endpoint,
153+
"revocation_endpoint": self.revocation_endpoint,
154+
"token_introspection_endpoint": self.token_introspection_endpoint,
155+
"end_session_endpoint": self.end_session_endpoint,
156+
"subject_types_supported": self.subject_types_supported,
157+
"id_token_signing_alg_values_supported": self.id_token_signing_alg_values_supported,
158+
"response_types_supported": self.response_types_supported,
159+
}
84160

85161

86162
class APIInterface:

supertokens_python/recipe/openid/recipe_implementation.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,45 @@ class RecipeImplementation(RecipeInterface):
3939
async def get_open_id_discovery_configuration(
4040
self, user_context: Dict[str, Any]
4141
) -> GetOpenIdDiscoveryConfigurationResult:
42+
from ..oauth2provider.constants import (
43+
AUTH_PATH,
44+
TOKEN_PATH,
45+
USER_INFO_PATH,
46+
REVOKE_TOKEN_PATH,
47+
INTROSPECT_TOKEN_PATH,
48+
END_SESSION_PATH,
49+
)
50+
4251
issuer = (
43-
self.config.issuer_domain.get_as_string_dangerous()
44-
+ self.config.issuer_path.get_as_string_dangerous()
52+
self.app_info.api_domain.get_as_string_dangerous()
53+
+ self.app_info.api_base_path.get_as_string_dangerous()
4554
)
4655

4756
jwks_uri = (
48-
self.config.issuer_domain.get_as_string_dangerous()
49-
+ self.config.issuer_path.append(
57+
self.app_info.api_domain.get_as_string_dangerous()
58+
+ self.app_info.api_base_path.append(
5059
NormalisedURLPath(GET_JWKS_API)
5160
).get_as_string_dangerous()
5261
)
5362

54-
return GetOpenIdDiscoveryConfigurationResult(issuer, jwks_uri)
63+
api_base_path: str = (
64+
self.app_info.api_domain.get_as_string_dangerous()
65+
+ self.app_info.api_base_path.get_as_string_dangerous()
66+
)
67+
68+
return GetOpenIdDiscoveryConfigurationResult(
69+
issuer=issuer,
70+
jwks_uri=jwks_uri,
71+
authorization_endpoint=api_base_path + AUTH_PATH,
72+
token_endpoint=api_base_path + TOKEN_PATH,
73+
userinfo_endpoint=api_base_path + USER_INFO_PATH,
74+
revocation_endpoint=api_base_path + REVOKE_TOKEN_PATH,
75+
token_introspection_endpoint=api_base_path + INTROSPECT_TOKEN_PATH,
76+
end_session_endpoint=api_base_path + END_SESSION_PATH,
77+
subject_types_supported=["public"],
78+
id_token_signing_alg_values_supported=["RS256"],
79+
response_types_supported=["code", "id_token", "id_token token"],
80+
)
5581

5682
def __init__(
5783
self,

0 commit comments

Comments
 (0)