Django linkedin身份验证编程错误

问题描述 投票:-2回答:1

当我尝试在我的django应用程序中使用linkedin进行身份验证时,它会通过第一阶段,它要求我授予LUN访问我的数据的权限,但在此之后无法进行身份验证并显示此错误。

Django Debug page

我在网上搜索过,我在WSGIRequest上没有看到任何内容。这是我的设置文件中的Linkedin身份验证配置文件

SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = '7756p783kegdt2'
SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = 'irDH1gCxSJKICfhi'
SOCIAL_AUTH_LINKEDIN_OAUTH2_SCOPE = ['r_basicprofile', 'r_emailaddress']
SOCIAL_AUTH_LINKEDIN_OAUTH2_FIELD_SELECTORS = [
'email-address', 'headline', 'industry']
SOCIAL_AUTH_LINKEDIN_OAUTH2_EXTRA_DATA = [
('id', 'id'),
('first-name', 'first_name'),
('last-name', 'last_name'),
('email-address', 'email_address'),
('industry', 'industry'),
]

SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
)

这是我在我的设置文件中调用的登录URL

LOGIN_URL = '/#authenticate'
LOGOUT_URL = '/user/logout'
LOGIN_REDIRECT_URL = '/accounts/'
LOGOUT_REDIRECT_URL = '/'

这是我处理用户身份验证的视图

class CaseInsensitiveModelBackend(ModelBackend):
""" Allows Case insensitive Authentication for Username/emails """

    def authenticate(self, username=None, password=None, **kwargs):
    """ confirm validity of username and password"""

    try:
        user = User.objects.get(username__iexact=username)
        if user.check_password(password):
            return user
    except User.DoesNotExist:
        return None

    def get_user(self, user_id):
    try:
        return User.objects.get(pk=user_id)
    except User.DoesNotExist:
        return None

这是我的重要网址

path(r'accounts/register', views.register, name='register'),
path(
    r'accounts/account-activation-sent/', views.account_activation_sent,
    name='account_activation_sent'
),
path(
    r'accounts/activate/<uidb64>/<token>/', views.activate,
    name='activate'
),
path(r'purchase/<token>/', views.purchase, name='purchase'),
path(r'<str:username>/deactivate/', views.deactivate, name='deactivate'),
path(r'deactivated/', views.deactivated, name='deactivated'),
path(r'accounts/login/', views.user_login, name='login'),

这是我希望用户在使用linkedin进行身份验证后重定向到用户的URL

path(r'<str:username>/', views.dashboard, name='dashboard'),
django python-social-auth django-socialauth
1个回答
0
投票

authenticate的第一个参数是请求,而不是用户名 - 请参阅the docs。您需要保留该签名。

class CaseInsensitiveModelBackend(ModelBackend):
    def authenticate(self, request, username=None, password=None, **kwargs):
© www.soinside.com 2019 - 2024. All rights reserved.