嗨,我是社交登录的新手。当我点击google按钮时,我可以重定向到有效的社交视图。当我尝试登录时,得到以下引用。
我一直很难理解所有的工作原理,有人可以帮我吗?我尝试了有关Google社交身份验证的多个教程。
Traceback (most recent call last):
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_django\utils.py", line 49, in wrapper
return func(request, backend, *args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_django\views.py", line 33, in complete
*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\actions.py", line 43, in do_complete
user = backend.complete(user=user, *args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\backends\base.py", line 40, in complete
return self.auth_complete(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\utils.py", line 259, in wrapper
return func(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\backends\oauth.py", line 405, in auth_complete
*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\utils.py", line 259, in wrapper
return func(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\backends\oauth.py", line 416, in do_auth
return self.strategy.authenticate(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_django\strategy.py", line 107, in authenticate
return authenticate(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\django\contrib\auth\__init__.py", line 73, in authenticate
user = backend.authenticate(request, **credentials)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\backends\base.py", line 80, in authenticate
return self.pipeline(pipeline, *args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\backends\base.py", line 83, in pipeline
out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\backends\base.py", line 113, in run_pipeline
result = func(*args, **out) or {}
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\pipeline\user.py", line 75, in create_user
'user': strategy.create_user(**fields)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\strategy.py", line 53, in create_user
return self.storage.user.create_user(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_django\storage.py", line 79, in create_user
user = cls.user_model().objects.create_user(*args, **kwargs)
TypeError: create_user() missing 3 required positional arguments: 'first_name', 'last_name', and 'date_of_birth'
[22/Jan/2019 00:30:51] "GET /auth/complete/google-oauth2/?state=9RDDB6MAo3C5i0MDKQuHBX9QOiyEQBcB&code=4/2gDFXySOhdxEVkI4gMXQ9vNUhpuEvqm1rYoCxgM85d6LrNu2HqhnjRNcUs9ZzRql4KMbdWVpXO0NACsS111yhSY&scope=email+profile+https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email HTTP/1.1" 500 184864
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'World1',
'social_django',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware', # <--
]
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.debug.debug',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
'social.pipeline.debug.debug',
)
SOCIAL_AUTH_GOOGLE_OAUTH2_IGNORE_DEFAULT_SCOPE = True
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'
]
# Google+ SignIn (google-plus)
SOCIAL_AUTH_GOOGLE_PLUS_IGNORE_DEFAULT_SCOPE = True
SOCIAL_AUTH_GOOGLE_PLUS_SCOPE = [
'https://www.googleapis.com/auth/plus.login',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'
]
答案 0 :(得分:0)
这里需要的只是设置
SOCIAL_AUTH_GOOGLE_LOGIN_URL='/auth/complete/google-oauth2/'
我将此设置设置为LOGIN_URL
,而不是SOCIAL_AUTH_GOOGLE_LOGIN_URL
。
,然后在验证用户身份后将我的LOGIN_URL
更改为模板,而不是实际的登录模板本身。