Skip to content

Commit 91926ae

Browse files
committed
fix: tests
1 parent 92a7a0b commit 91926ae

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

supertokens_python/recipe/oauth2provider/interfaces.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,13 @@ def from_json(json: Dict[str, Any]):
259259
)
260260

261261
def to_json(self) -> Dict[str, Any]:
262-
return {
262+
result = {
263263
"status": "OK",
264264
"clients": [client.to_json() for client in self.clients],
265-
"nextPaginationToken": self.next_pagination_token,
266265
}
266+
if self.next_pagination_token is not None:
267+
result["nextPaginationToken"] = self.next_pagination_token
268+
return result
267269

268270

269271
class GetOAuth2ClientOkResult:
@@ -920,7 +922,7 @@ def to_json(self) -> Dict[str, Any]:
920922
result["audience"] = self.audience
921923
if not isinstance(self.grant_types, NotSet):
922924
result["grantTypes"] = self.grant_types
923-
if self.response_types is not None:
925+
if not isinstance(self.response_types, NotSet):
924926
result["responseTypes"] = self.response_types
925927
if not isinstance(self.client_uri, NotSet):
926928
result["clientUri"] = self.client_uri

supertokens_python/recipe/oauth2provider/recipe_implementation.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
from supertokens_python.recipe.openid.recipe import OpenIdRecipe
2626
from supertokens_python.recipe.session.interfaces import SessionContainer
2727
from supertokens_python.recipe.session.jwks import get_latest_keys
28+
from supertokens_python.recipe.session.jwt import (
29+
parse_jwt_without_signature_verification,
30+
)
2831
from supertokens_python.recipe.session.recipe import SessionRecipe
2932
from supertokens_python.types import RecipeUserId, User
3033

@@ -543,7 +546,7 @@ async def get_oauth2_clients(
543546
clients=[
544547
OAuth2Client.from_json(client) for client in response["clients"]
545548
],
546-
next_pagination_token=response["nextPaginationToken"],
549+
next_pagination_token=response.get("nextPaginationToken"),
547550
)
548551

549552
return ErrorOAuth2Response(
@@ -632,9 +635,11 @@ async def validate_oauth2_access_token(
632635
check_database: Optional[bool],
633636
user_context: Dict[str, Any],
634637
) -> Dict[str, Any]:
638+
access_token_obj = parse_jwt_without_signature_verification(token)
639+
635640
# Verify token signature using session recipe's JWKS
636641
session_recipe = SessionRecipe.get_instance()
637-
matching_keys = get_latest_keys(session_recipe.config)
642+
matching_keys = get_latest_keys(session_recipe.config, access_token_obj.kid)
638643
err: Optional[Exception] = None
639644

640645
payload: Dict[str, Any] = {}

tests/test-server/oauth2provider.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def get_oauth2_clients_api(): # type: ignore
1313
assert request.json is not None
1414
print("OAuth2Provider:getOAuth2Clients", request.json)
1515

16-
data = request.json
16+
data = request.json.get("input", {})
1717
if data is None:
1818
return jsonify({"status": "MISSING_DATA_ERROR"})
1919

@@ -52,9 +52,11 @@ def delete_oauth2_client_api(): # type: ignore
5252
assert request.json is not None
5353
print("OAuth2Provider:deleteOAuth2Client", request.json)
5454

55+
data = request.json.get("input", {})
56+
5557
response = OAuth2Provider.delete_oauth2_client(
56-
client_id=request.json["input"],
57-
user_context=request.json.get("userContext"),
58+
client_id=data.get("clientId"),
59+
user_context=data.get("userContext"),
5860
)
5961
return jsonify(response.to_json())
6062

@@ -75,7 +77,7 @@ def validate_oauth2_access_token_api(): # type: ignore
7577
check_database=request.json.get("checkDatabase"),
7678
user_context=request.json.get("userContext"),
7779
)
78-
return jsonify({**response, "status": "OK"})
80+
return jsonify({"payload": response, "status": "OK"})
7981

8082
@app.route("/test/oauth2provider/validateoauth2refreshtoken", methods=["POST"]) # type: ignore
8183
def validate_oauth2_refresh_token_api(): # type: ignore

tests/test-server/session.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,31 @@ def merge_into_access_token_payload_on_session_object(): # type: ignore
195195
}
196196
)
197197

198+
@app.route("/test/session/sessionobject/revokesession", methods=["POST"]) # type: ignore
199+
def revoke_session(): # type: ignore
200+
data = request.json
201+
if data is None:
202+
return jsonify({"status": "MISSING_DATA_ERROR"})
203+
204+
log_override_event("sessionobject.revokesession", "CALL", data)
205+
206+
try:
207+
session = convert_session_to_container(data)
208+
if not session:
209+
raise Exception(
210+
"This should never happen: failed to deserialize session"
211+
)
212+
ret_val = session.sync_revoke_session(data.get("userContext", {}))
213+
response = {
214+
"retVal": ret_val,
215+
"updatedSession": convert_session_to_json(session),
216+
}
217+
log_override_event("sessionobject.revokesession", "RES", ret_val)
218+
return jsonify(response)
219+
except Exception as e:
220+
log_override_event("sessionobject.revokesession", "REJ", e)
221+
return jsonify({"status": "ERROR", "message": str(e)}), 500
222+
198223
@app.route("/test/session/mergeintoaccesspayload", methods=["POST"]) # type: ignore
199224
def merge_into_access_payload(): # type: ignore
200225
data = request.json

0 commit comments

Comments
 (0)