eadwinCode / django-ninja-jwt

A JSON Web Token authentication plugin for the Django REST Framework.
https://eadwincode.github.io/django-ninja-jwt/
MIT License
149 stars 21 forks source link

`AuthenticationFailed` exception class does not return correct error code #78

Open erdem opened 5 months ago

erdem commented 5 months ago

I couldn't create a pull request for the issue due to limited time but it seems like built-in AuthenticationFailed exception class has an inheritance order issue.

https://github.com/eadwinCode/django-ninja-jwt/blob/master/ninja_jwt/exceptions.py#L35

This class doesn't get default_code attribute from AuthenticationFailed exception, instead it gets from DetailDictMixin class which is empty string.

my implementation:

@api_controller("/auth", tags=["auth"])
class UserTokenController(TokenObtainSlidingController):
    auto_import = True

    @route.post("/login", response=UserTokenOutSchema, url_name="login")
    def obtain_token(self, user_token: jwt_schemas.TokenObtainSlidingInputSchema):
        user = user_token._user
        token = SlidingToken.for_user(user)
        return UserTokenOutSchema(
            user=user,
            token=str(token),
            token_exp_date=datetime.fromtimestamp(token["exp"], tz=timezone.utc),
        )
{
  "detail": "No active account found with the given credentials",
  "code": ""
}

Thanks