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
I am having problems setting the default rest framework authentication class to knox.auth.TokenAuthentication. It seems that in the views I have to explicitly set authentication_classes = (TokenAuthentication,):
settings.y
REST_FRAMEWORK= {
# This is not having an effect at all."DEFAULT_AUTHENTICATION_CLASSES": ("knox.auth.TokenAuthentication",)
}
views.py
fromknox.authimportTokenAuthenticationclassUserProfileView(generics.RetrieveUpdateAPIView):
serializer_class=UserProfileSerializerauthentication_classes= (TokenAuthentication,) # It won't work without this linepermission_classes= (permissions.IsAuthenticated,)
defget_object(self):
returnself.request.user
And if I comment authentication_classes = (TokenAuthentication,) I get:
{
"detail": "Authentication credentials were not provided."
}
I may be missing something, but I can't figure it out. Thank you!
The text was updated successfully, but these errors were encountered:
From the docs
"
You can activate TokenAuthentication on all your views by adding it to REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"].
If it is your only default authentication class, remember to overwrite knox's LoginView, otherwise it'll not work, since the login view will require a authentication token to generate a new token, rendering it unusable.
For instance, you can authenticate users using Basic Authentication by simply overwriting knox's LoginView and setting BasicAuthentication as one of the acceptable authentication classes, as follows:
"
I am having problems setting the default rest framework authentication class to
knox.auth.TokenAuthentication
. It seems that in the views I have to explicitly setauthentication_classes = (TokenAuthentication,)
:settings.y
views.py
And if I comment
authentication_classes = (TokenAuthentication,)
I get:I may be missing something, but I can't figure it out. Thank you!
The text was updated successfully, but these errors were encountered: