File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments