Open haccks opened 3 years ago
Not sure if this is the best way, but to my understanding for some reason the Login API is requesting credentials. My solution was to override the default class and remove any authentication requirements.
from dj_rest_auth.views import LoginView
class Login(LoginView):
authentication_classes = []
And in the urls file
# ...
urlpatterns = [
path("auth/login/", core_api.Login.as_view()),
path("auth/", include("dj_rest_auth.urls")),
]
# ...
I found that I can get this to work only if I use DRF's Token Authentication as well:
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
'dj_rest_auth.jwt_auth.JWTCookieAuthentication'
),
I think Simple JWT must rely on this code to work.
It seems this app can work with JWT Token or DRF Token Auth only. If I tried to use DRF SessionAuthentication only I got server errors.
REST_USE_JWT = False
...
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
),
...
INSTALLED_APPS = [
...
'rest_framework',
#'rest_framework.authtoken'
]
error:
File "/usr/local/lib/python3.7/dist-packages/dj_rest_auth/views.py" in post
127. self.login()
File "/usr/local/lib/python3.7/dist-packages/dj_rest_auth/views.py" in login
79. self.serializer,
File "/usr/local/lib/python3.7/dist-packages/dj_rest_auth/utils.py" in default_create_token
16. token, _ = token_model.objects.get_or_create(user=user)
Exception Type: AttributeError at /api/v1/profiles/rest-auth/login/
Exception Value: type object 'Token' has no attribute 'objects'
Related issue https://github.com/iMerica/dj-rest-auth/issues/161
I am still facing this problem with version 5.1.0. Any workaround?
I am not sure why, but switching the order of these classes seem to work for now
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
'dj_rest_auth.jwt_auth.JWTCookieAuthentication',
],
I am using both of these authentication classes in
settings.py
file asDEFAULT_AUTHENTICATION_CLASSES
.With this setting if I use browsable API then I get this error: