Django linkedin认证编程报错

Django linkedin authentication programming error

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

我在网上搜索过,没有看到关于 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

这是我的重要 urls

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'),

这是 url 我希望用户在使用 linkedin

进行身份验证后被重定向到
path(r'<str:username>/', views.dashboard, name='dashboard'),

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

class CaseInsensitiveModelBackend(ModelBackend):
    def authenticate(self, request, username=None, password=None, **kwargs):