Django Rest Framework - Authentication credentials were not provided

前端 未结 12 1678
野性不改
野性不改 2020-12-04 07:12

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:

<
相关标签:
12条回答
  • 2020-12-04 07:52

    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'
       ),
    }
    
    0 讨论(0)
  • 2020-12-04 07:53

    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',
        )
        ...
        ..
    }
    
    0 讨论(0)
  • 2020-12-04 07:59

    I was having this problem with postman.Add this to the headers...

    0 讨论(0)
  • 2020-12-04 08:04

    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.

    0 讨论(0)
  • 2020-12-04 08:04

    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

    0 讨论(0)
  • 2020-12-04 08:06

    Adding SessionAuthentication in settings.py will do the job

    REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.SessionAuthentication', ), }

    0 讨论(0)
提交回复
热议问题