Skip to content

Commit 219c767

Browse files
committed
Fixed bug in server where multiple space-separated scopes were not split into separate scopes rendering the validation process impossible
1 parent ee74bca commit 219c767

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

server/security/jwt_utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,20 @@ async def verify_token_signature(token: str = Depends(oauth2_scheme)) -> Decoded
5454

5555
logger.info(f"Token signature successfully verified with public key (kid: {kid})")
5656

57-
# Ensure `scp` is a list
58-
if "scp" in verified_payload and isinstance(verified_payload["scp"], str):
59-
verified_payload["scp"] = [verified_payload["scp"]]
57+
if "scp" in verified_payload:
58+
if isinstance(verified_payload["scp"], str):
59+
# Split the `scp` string into a list of scopes if necessary
60+
verified_payload["scp"] = verified_payload["scp"].split()
61+
logger.info(f"Parsed 'scp' claim into list: {verified_payload['scp']}")
62+
elif isinstance(verified_payload["scp"], list):
63+
logger.info("Token 'scp' claim is already a list.")
64+
else:
65+
logger.error(f"Unexpected 'scp' claim format: {type(verified_payload['scp'])}")
66+
raise HTTPException(
67+
status_code=status.HTTP_401_UNAUTHORIZED,
68+
detail="Invalid JWT: 'scp' claim format is incorrect",
69+
headers={"WWW-Authenticate": "Bearer"},
70+
)
6071

6172
return DecodedToken(**verified_payload)
6273

0 commit comments

Comments
 (0)