【问题标题】:Django Rest Framework Authentication deniedDjango Rest 框架身份验证被拒绝
【发布时间】:2015-02-18 11:39:01
【问题描述】:

我已经使用 PSA 在 Django 上验证了我的用户,并在用户模型中注册了用户,甚至令牌模型也注册了用户和令牌。

但是当我发送这个请求时:

curl -X POST -H "Authorization:Token 87e939184457ccc064485444a90e3ebf417xxxxx" http://192.168.x.x:8000/user-profiles/>error.html 

我明白了

{"detail":"您无权执行此操作。"}

如果我发送这个:

curl -X POST --user "VedantDasSwain:87e939184457ccc064485444a90e3ebf417xxxxx" http://192.168.x.x:8000/user-profiles/>error.html 

我明白了

{"detail":"无效的用户名/密码"}

这些是我的设置文件中的相关 sn-ps:

'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',
        'rest_framework.permissions.IsAdminUser',),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',
    ),

这是 PSA 设置的一部分:

AUTHENTICATION_BACKENDS = (
    'social.backends.facebook.FacebookOAuth2',

    'django.contrib.auth.backends.ModelBackend',
)

以前有没有人遇到过这种情况?有什么办法解决这个问题?

【问题讨论】:

    标签: python django django-rest-framework


    【解决方案1】:

    我的印象是这个元组意味着用户要么是经过身份验证的,要么是管理员。

    'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',
            'rest_framework.permissions.IsAdminUser',)
    

    但是,我从元组中删除了“rest_framework.permissions.IsAdminUser”,然后它给了我正确的结果

    curl -X POST -H "Authorization:Token 87e939184457ccc064485444a90e3ebf417xxxxx" http://192.168.x.x:8000/user-profiles/>error.html 
    

    我不知道为什么会这样。这几乎是一个侥幸的修复。如果有人知道为什么会这样,请告诉我

    【讨论】:

      猜你喜欢
      • 2013-06-29
      • 2017-09-26
      • 2017-11-02
      • 2019-03-01
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      相关资源
      最近更新 更多