Skip to content

Commit fde01a0

Browse files
authored
Fix: Request Missing During Authentication (#89)
* fixed authentication with request #88 * revert commented code
1 parent 9c22551 commit fde01a0

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

ninja_jwt/controller.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
schema = SchemaControl(api_settings)
2626

2727

28-
class TokenVerificationController(ControllerBase):
28+
class TokenVerificationController:
2929
auto_import = False
3030

3131
@http_post(
@@ -38,7 +38,7 @@ def verify_token(self, token: schema.verify_schema):
3838
return token.to_response_schema()
3939

4040

41-
class TokenBlackListController(ControllerBase):
41+
class TokenBlackListController:
4242
auto_import = False
4343

4444
@http_post(
@@ -51,7 +51,7 @@ def blacklist_token(self, refresh: schema.blacklist_schema):
5151
return refresh.to_response_schema()
5252

5353

54-
class TokenObtainPairController(ControllerBase):
54+
class TokenObtainPairController:
5555
auto_import = False
5656

5757
@http_post(
@@ -98,15 +98,17 @@ def refresh_token(self, refresh_token: schema.obtain_sliding_refresh_schema):
9898

9999

100100
@api_controller("/token", permissions=[AllowAny], tags=["token"], auth=None)
101-
class NinjaJWTDefaultController(TokenVerificationController, TokenObtainPairController):
101+
class NinjaJWTDefaultController(
102+
ControllerBase, TokenVerificationController, TokenObtainPairController
103+
):
102104
"""NinjaJWT Default controller for obtaining and refreshing tokens"""
103105

104106
auto_import = False
105107

106108

107109
@api_controller("/token", permissions=[AllowAny], tags=["token"], auth=None)
108110
class NinjaJWTSlidingController(
109-
TokenVerificationController, TokenObtainSlidingController
111+
ControllerBase, TokenVerificationController, TokenObtainSlidingController
110112
):
111113
"""
112114
NinjaJWT Sliding controller for obtaining and refreshing tokens
@@ -186,7 +188,7 @@ async def refresh_token(self, refresh_token: schema.obtain_sliding_refresh_schem
186188

187189
@api_controller("/token", permissions=[AllowAny], tags=["token"], auth=None)
188190
class AsyncNinjaJWTDefaultController(
189-
AsyncTokenVerificationController, AsyncTokenObtainPairController
191+
ControllerBase, AsyncTokenVerificationController, AsyncTokenObtainPairController
190192
):
191193
"""NinjaJWT Async Default controller for obtaining and refreshing tokens"""
192194

@@ -195,7 +197,7 @@ class AsyncNinjaJWTDefaultController(
195197

196198
@api_controller("/token", permissions=[AllowAny], tags=["token"], auth=None)
197199
class AsyncNinjaJWTSlidingController(
198-
AsyncTokenVerificationController, AsyncTokenObtainSlidingController
200+
ControllerBase, AsyncTokenVerificationController, AsyncTokenObtainSlidingController
199201
):
200202
"""
201203
NinjaJWT Async Sliding controller for obtaining and refreshing tokens

ninja_jwt/schema.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.conf import settings
66
from django.contrib.auth import authenticate, get_user_model
77
from django.contrib.auth.models import AbstractUser, update_last_login
8+
from django.http import HttpRequest
89
from django.utils.translation import gettext_lazy as _
910
from ninja import ModelSchema, Schema
1011
from ninja.schema import DjangoGetter
@@ -52,7 +53,7 @@ def check_user_authentication_rule(self) -> None:
5253
)
5354

5455
@classmethod
55-
def validate_values(cls, values: Dict) -> Dict:
56+
def validate_values(cls, request: HttpRequest, values: Dict) -> Dict:
5657
if user_name_field not in values and "password" not in values:
5758
raise exceptions.ValidationError(
5859
{
@@ -69,7 +70,7 @@ def validate_values(cls, values: Dict) -> Dict:
6970
if not values.get("password"):
7071
raise exceptions.ValidationError({"password": "password is required"})
7172

72-
_user = authenticate(**values)
73+
_user = authenticate(request, **values)
7374
cls._user = _user
7475

7576
if not (_user is not None and _user.is_active):
@@ -103,8 +104,11 @@ class Config:
103104
@model_validator(mode="before")
104105
def validate_inputs(cls, values: DjangoGetter) -> DjangoGetter:
105106
input_values = values._obj
107+
request = values._context.get("request")
106108
if isinstance(input_values, dict):
107-
values._obj.update(cls.validate_values(input_values))
109+
values._obj.update(
110+
cls.validate_values(request=request, values=input_values)
111+
)
108112
return values
109113
return values
110114

0 commit comments

Comments
 (0)