我正在尝试自定义social_auth.backends.contrib.vk.VKOAuth2Backend 但是当我启用自定义后端时会出现此错误
WrongBackend at / login / vk-oauth /
身份验证服务不正确" vk-oauth"
来自设置的authentication_backends
AUTHENTICATION_BACKENDS = (
'social_auth.backends.facebook.FacebookBackend',
'social_auth.backends.contrib.vk.VKOAuth2Backend',
'social_auth.backends.google.GoogleOAuth2Backend',
'social_auth.backends.contrib.odnoklassniki.OdnoklassnikiBackend',
# '_auth.backends.CustomVKOAuth2Backend',
'profiles.backends.ModelBackend',
)
如果我取消注释我的CustomVKOAuth2Backend会出现问题,但是使用VKOAuth2Backend时,一切都会按预期运行。
from social_auth.backends.contrib.vk import VKOAuth2Backend
class CustomVKOAuth2Backend(VKOAuth2Backend):
"""Custom VKOAuth2 authentication backend"""
def get_user_details(self, response):
"""Return user details from VK account"""
lname = response.get('last_name', '')
fname = response.get('first_name', '')
name = fname + lname
email = response.get('email', '')
return {
'username': response.get('screen_name'),
'email': email,
'first_name': fname,
'last_name': lname,
'name': name
}
它们几乎是一致的,所以我无法理解问题出在哪里
这是有效的后端
class VKOAuth2Backend(OAuthBackend):
"""VKOAuth2 authentication backend"""
name = 'vk-oauth'
EXTRA_DATA = [
('id', 'id'),
('expires', 'expires')
]
def get_user_id(self, details, response):
"""OAuth providers return an unique user id in response"""
return response['user_id']
def get_user_details(self, response):
"""Return user details from VK account"""
return {
'username': response.get('screen_name'),
'email': '',
'first_name': response.get('first_name'),
'last_name': response.get('last_name')
}