未经授权的错误视图django-rest-framework-social-oauth2

时间:2018-04-09 06:32:52

标签: django django-rest-framework django-views python-social-auth django-socialauth

成功社交登录后,我被重定向到

SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/users/ldata/"

但是它给出了未经授权的错误

HTTP 401 Unauthorized
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
WWW-Authenticate: Bearer realm="api"

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

我的settings.py

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
    'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
    'rest_framework_social_oauth2.authentication.SocialAuthentication',
),

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


AUTHENTICATION_BACKENDS = (
# for Google authentication
'social_core.backends.open_id.OpenIdAuth',
'social_core.backends.google.GoogleOpenId',
'social_core.backends.google.GoogleOAuth2',

#linkedin
'social_core.backends.linkedin.LinkedinOAuth',

# django-rest-framework-social-oauth2
'rest_framework_social_oauth2.backends.DjangoOAuth2',

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

中间件:

'social_django.middleware.SocialAuthExceptionMiddleware',

conbtext_processor:

'social_django.context_processors.backends', 'social_django.context_processors.login_redirect',

已安装的应用

'oauth2_provider',

'social_django',

'rest_framework_social_oauth2',

'rest_framework',

'用户',

0 个答案:

没有答案