You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'}]}
The text was updated successfully, but these errors were encountered:
What worked for me is to create a custom authentication backend:
fromaxes.backendsimportAxesBackendclassCustomAxesBackend(AxesBackend):
defauthenticate(self, request=None, username=None, password=None, **kwargs):
ifrequestisNone:
# Create a minimal request object if it's not providedclassMinimalRequest:
META= {'REMOTE_ADDR': 'unknown'}
request=MinimalRequest()
# Call the original authenticate methodreturnsuper().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.
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.
The text was updated successfully, but these errors were encountered: