Authentication credentials were not provided.

4,832 views
Skip to first unread message

Salima Begum

unread,
Aug 11, 2022, 7:39:21 AM8/11/22
to Django REST framework
Hi,
So, I am creating registration API. I written api for registration, Login and then user profile.
I tested this API's in Postman here it is working. For User authentication I used JWT authentication. When I test in frontend view User Profile API is raising an error with 
```
HTTP 401 Unauthorized Allow: OPTIONS, GET Content-Type: application/json Vary: Accept WWW-Authenticate: Token { "detail": "Authentication credentials were not provided." }
```
How to fix this Please help me out how to fix this.

Thanks
~Salima

Sreebash Chandra Das

unread,
Aug 11, 2022, 8:09:06 AM8/11/22
to django-res...@googlegroups.com
If you properly integrated with the frontend, it should work. I think there are some mistakes. Could you  give some screenshot please?

--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/73944851-58f4-4d55-ba67-b88bd55f1cfdn%40googlegroups.com.


--
Best Regards,

Sreebash C. Das
Graduate in B.Sc in CSE
National University, Bangladesh

Salima Begum

unread,
Aug 11, 2022, 8:54:42 AM8/11/22
to django-res...@googlegroups.com
Hi, Thanks for quick response
I used HTML, CSS as frontend. Here below I attached screenshot


Error_authentication.PNG

Sreebash Chandra Das

unread,
Aug 11, 2022, 9:01:40 AM8/11/22
to django-res...@googlegroups.com
I think you may not have session authentication in your settings file. That is why you won't provide credentials. 

Santosh Rana

unread,
Aug 11, 2022, 9:09:52 AM8/11/22
to django-res...@googlegroups.com
Sreebash is right..
You need to add following code on your settings.py

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ]
}

Salima Begum

unread,
Aug 11, 2022, 9:22:20 AM8/11/22
to django-res...@googlegroups.com
Hi, Thank you for your response
In my project I used JWT authentication. 
 'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ),
}



# JWT Settings
SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(minutes=20),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=1),

    'AUTH_HEADER_TYPES': ('Bearer',),
    'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION',
    'USER_ID_FIELD': 'id',
    'USER_ID_CLAIM': 'user_id',
    'USER_AUTHENTICATION_RULE': 'rest_framework_simplejwt.authentication.default_user_authentication_rule',

    'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
    'TOKEN_TYPE_CLAIM': 'token_type',
    'TOKEN_USER_CLASS': 'rest_framework_simplejwt.models.TokenUser',

    'JTI_CLAIM': 'jti',

}

INSTALLED_APPS = [
    .........
    'rest_framework_simplejwt',
    .........

]

Sreebash Chandra Das

unread,
Aug 11, 2022, 9:33:53 AM8/11/22
to Django REST framework
You have to use multiple authentication class if you would like to authorized in frontend .
Following code will be work for you.

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
       'rest_framework_simplejwt.authentication.JWTAuthentication',
    ]

Salima Begum

unread,
Aug 11, 2022, 10:25:57 AM8/11/22
to django-res...@googlegroups.com
Thank you Sreebash. I will try and let you know

Reply all
Reply to author
Forward
0 new messages