当使用django allauth从facebook登录时,用户是admin

时间:2015-01-08 10:42:51

标签: python django django-allauth

我正在使用python 2.7.6和django 1.6.5,我已经安装了django allauth,当我使用facebook登录时。 request.user是admin如何重新登录并显示通过facebook登录的用户的个人资料。并且此登录仅适用于我的计算机,我也想让它在其他人上工作

我在views.py中使用permission_classes 我的设置文件

SITE_ID = 3

INSTALLED_APPS = (
    .
    .
    .
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    #'allauth.socialaccount.providers.google',
)

REST_FRAMEWORK = {
    #'DEFAULT_PERMISSION_CLASSES': (
        #'rest_framework.permissions.IsAuthenticated',
    #),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
        'allauth.account.auth_backends.AuthenticationBackend',

    )
}

SOCIAL_AUTH_PIPELINE = (
    'social_auth.backends.pipeline.social.social_auth_user',
    'social_auth.backends.pipeline.social.associate_user',
    'social_auth.backends.pipeline.social.load_extra_data',
    'social_auth.backends.pipeline.user.update_user_details'
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
    'django.contrib.auth.context_processors.auth',
    'allauth.account.context_processors.account',
    'allauth.socialaccount.context_processors.socialaccount'
)

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
SITE_ID = 1
LOGIN_REDIRECT_URL = "http://192.168.100.7/userprofile/"
FACEBOOK_APP_ID='my_app_id'
FACEBOOK_API_SECRET='my_app_secret_id'
FACEBOOK_EXTENDED_PERMISSIONS = ['email']
SOCIAL_AUTH_UID_LENGTH = 16
SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 16
SOCIAL_AUTH_NONCE_SERVER_URL_LENGTH = 16
SOCIAL_AUTH_ASSOCIATION_SERVER_URL_LENGTH = 16
SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 16

SOCIALACCOUNT_PROVIDERS = \
{
    'facebook':
        {
            'SCOPE': ['email'],
            'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
            'METHOD': 'oauth2',
        },
}

我添加了这行un url.py     “url(r'^ accounts /',include('allauth.urls')),”

1 个答案:

答案 0 :(得分:0)

我的问题通过以下某些更改解决了

我更改了模板上下文处理器

"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages",
"django.contrib.auth.context_processors.auth",
"allauth.account.context_processors.account",
"allauth.socialaccount.context_processors.socialaccount",

并从rest框架中的默认身份验证类中删除了'allauth.account.auth_backends.AuthenticationBackend'

添加了

AUTHENTICATION_BACKENDS = (
   # 'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
)

并上传到实时服务器并且工作正常。