Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BadJWTTokenProvidedException exception handling in all endpoints that use JWT #329

Open
AntonioMrtz opened this issue Feb 8, 2025 · 1 comment
Labels
backend Backend related issues good first issue Good for newcomers help-wanted Help is wanted

Comments

@AntonioMrtz
Copy link
Owner

Description

Add exception handling on endpoints that use JWT for authentication

Context

Class JWTBearer raises BadJWTTokenProvidedError exception when JWT provided is invalid. We need to catch that error in the endpoints that use token authentication.

How to do it

Add exception handling at controller level for all endpoints that use token: Annotated[TokenData, Depends(JWTBearer())], for authentication. Try to put this exception handling sorted based on exception code. Example: 401 then 402, 403 ....

except BadJWTTokenProvidedError:
    return Response(
        status_code=HTTP_401_UNAUTHORIZED,
        content=PropertiesMessagesManager.tokenInvalidCredentials,
        headers={"WWW-Authenticate": "Bearer"},
    )

Testing

How to test the feature


🖐️ Learn how to CONTRIBUTE, all help is welcomed :)

📚 Check out the project documentation for more info

⭐ Help this project grow by giving it a star if you like it!

😵 Trello links are used for traceability, do not ask to join the board before leaving a comment in the related issue

@AntonioMrtz AntonioMrtz added backend Backend related issues good first issue Good for newcomers help-wanted Help is wanted labels Feb 8, 2025
@AntonioMrtz
Copy link
Owner Author

@AntonioMrtz AntonioMrtz pinned this issue Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Backend related issues good first issue Good for newcomers help-wanted Help is wanted
Projects
None yet
Development

No branches or pull requests

1 participant