markomirosavljev / fastapi-cognito

Basic Cognito-Auth library for Python and FastAPI.
MIT License
48 stars 15 forks source link

fix: Handle potential KeyError when decoding the token #15

Closed benmoveai closed 3 months ago

benmoveai commented 1 year ago

cognitojwt/jwt_sync.py#get_public_key could raise a KeyError if the provided access token is malformed.

Such an error would look something like:

File "/opt/python/cognitojwt/jwt_sync.py", line 31, in get_public_key
    kid = headers['kid']
KeyError: 'kid'

Therefore, catch this KeyError and return a 401 unauthorised to the user.