【问题标题】:Django Rest Framework allauth Authentication credentials were not provided未提供 Django Rest Framework allauth 身份验证凭据
【发布时间】:2021-06-15 04:21:13
【问题描述】:

我正在使用 django allauth 进行身份验证

这是我的settings.py

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ],
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated'
    ],
}

已安装的应用程序如下:

'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'rest_auth.registration',
'allauth',
'allauth.account',

我正在尝试这样的方式:

curl -X POST "http://127.0.0.1:8000/api/v1/cinema-hall/" -H 'Authorization: Token 44eba1cdb1ecde6d3a55d6c85d7c4f44315f2c44'

我得到这个错误:

{"detail":"Authentication credentials were not provided."}

我看到很多类似的帖子是这样的:Django Rest Framework Authentication credentials were not provided

但这些都没有解决我的问题。

谁能告诉我遇到此错误的可能原因是什么?

【问题讨论】:

    标签: django django-rest-framework django-allauth


    【解决方案1】:

    我对使用 CURL 测试 api 不是很有经验,但是“Authorization”是否可能被拼写为“Authorizaion”?

    编辑:在您确认不是这种情况后,我注意到您在默认身份验证类中同时具有 TokenAuthentication 和 SessionAuthentication 。删除 SessionAuthentication 或添加所需的凭据(包含会话详细信息和 csrf 令牌的 cookie)。

    【讨论】:

    • 不,在真正的卷曲中没有错漏。我已经编辑了帖子,请检查
    猜你喜欢
    • 2015-05-16
    • 2019-04-29
    • 2015-01-10
    • 2015-02-05
    • 2018-02-25
    • 2019-02-19
    • 2022-11-10
    • 1970-01-01
    • 2020-07-17
    相关资源
    最近更新 更多