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

Django Ninja JWT Integration #984

Open
jonnyhoff opened this issue Jan 12, 2023 · 3 comments
Open

Django Ninja JWT Integration #984

jonnyhoff opened this issue Jan 12, 2023 · 3 comments

Comments

@jonnyhoff
Copy link

Django Axes works great when logging in normally but I've implemented Django Ninja JWT and when making REST API requests using the default Django Ninja JWT controller api.register_controllers(NinjaJWTDefaultController), I get the below error.

It's obvious that the authentication method needs to include the request as an argument but I'm unable to find where in Django Ninja JWT's code this needs to be done.

"POST - AsyncNinjaJWTSlidingController[obtain_token] /api/token/pair" ()
Unprocessable Entity: /api/token/pair
Error: 422 - {'detail': [{'loc': ['body', 'user_token', '__root__'], 'msg': 'AxesBackend requires a request as an argument to authenticate', 'type': 'value_error.axesbackendrequestparameterrequired'}]}
@chemsedd
Copy link

chemsedd commented May 8, 2024

Hello,
I'm facing the exact same issue, I guess no fix has been submitted yet!

@robertvy
Copy link

robertvy commented Aug 18, 2024

What worked for me is to create a custom authentication backend:

from axes.backends import AxesBackend

class CustomAxesBackend(AxesBackend):
    def authenticate(self, request=None, username=None, password=None, **kwargs):
        if request is None:
            # Create a minimal request object if it's not provided
            class MinimalRequest:
                META = {'REMOTE_ADDR': 'unknown'}
            request = MinimalRequest()

        # Call the original authenticate method
        return super().authenticate(request, username, password, **kwargs)

This approach should help bypass the issue where the AxesBackend requires a request object, allowing your Django Ninja JWT integration to function correctly.

@eadwinCode
Copy link

eadwinCode commented Aug 21, 2024

This has been resolved in django-ninja-jwt new release v5.3.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants