File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,14 +46,20 @@ def get_user(token: Annotated[HTTPAuthorizationCredentials, Depends(security)]):
4646 openid_configuration = get_openid_configuration ()
4747 jwks_client = get_jwks_client ()
4848
49- signing_key = jwks_client .get_signing_key_from_jwt (token .credentials )
50- decoded_jwt = jwt .decode (
51- token .credentials ,
52- key = signing_key .key ,
53- algorithms = openid_configuration ["id_token_signing_alg_values_supported" ],
54- options = {"verify_aud" : False },
55- )
56- if not decoded_jwt ["media" ]:
49+ try :
50+ signing_key = jwks_client .get_signing_key_from_jwt (token .credentials )
51+ decoded_jwt = jwt .decode (
52+ token .credentials ,
53+ key = signing_key .key ,
54+ algorithms = openid_configuration ["id_token_signing_alg_values_supported" ],
55+ options = {"verify_aud" : False },
56+ )
57+ except (jwt .exceptions .PyJWTError , Exception ) as e :
58+ raise HTTPException (
59+ status_code = status .HTTP_401_UNAUTHORIZED , detail = f"Invalid token"
60+ )
61+
62+ if not decoded_jwt .get ("media" ):
5763 raise HTTPException (
5864 status_code = status .HTTP_401_UNAUTHORIZED , detail = "Not authorized"
5965 )
You can’t perform that action at this time.
0 commit comments