I\'m developing an API using Django Rest Framework. I\'m trying to list or create an \"Order\" object, but when i\'m trying to access the console gives me this error:
<Solved by adding "DEFAULT_AUTHENTICATION_CLASSES" to my settings.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAdminUser'
),
}
Probably this could work
In settings.py
SIMPLE_JWT = {
....
...
# Use JWT
'AUTH_HEADER_TYPES': ('JWT',),
# 'AUTH_HEADER_TYPES': ('Bearer',),
....
...
}
Add this too
REST_FRAMEWORK = {
....
...
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
)
...
..
}
I was having this problem with postman.Add this to the headers...
If you are runnig Django on Apache using mod_wsgi you have to add
WSGIPassAuthorization On
in your httpd.conf. Otherwise authorization header will be stripped out by mod_wsgi.
For me, I had to prepend my Authorization header with "JWT" instead of "Bearer" or "Token" on Django DRF. Then it started working. eg -
Authorization: JWT asdflkj2ewmnsasdfmnwelfkjsdfghdfghdv.wlsfdkwefojdfgh
Adding SessionAuthentication in settings.py will do the job
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
),
}