Django Social-auth-app-django 无法登录并显示身份验证过程已取消

问题描述 投票:0回答:1

当我将 Django 应用程序上传到托管时出现问题。就是当我选择Google帐户后使用Google OAuth登录时,突然出现错误

AuthCanceled at /auth/complete/google-oauth2/
。但是,我在登录过程中没有执行任何操作。那么,为什么认证过程被取消了?

在本地主机上运行时,应用程序运行顺利。但是,当在托管上运行时,就会像这样。我不知道发生了什么。

设置.py

DEBUG = True

ALLOWED_HOSTS = ['*', 'siadis.mydomain.sch.id']

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'website.apps.WebsiteConfig',
    'quiz.apps.QuizConfig',
    'django.contrib.humanize',
    'social_django'
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [ BASE_DIR / "templates/" ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.template.context_processors.media',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
            ],
        },
    },
]

AUTHENTICATION_BACKENDS = (
    'social_core.backends.google.GoogleOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'my id client'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'my secret cliend'

LOGIN_REDIRECT_URL = '/'

LOGIN_ERROR_URL = '/login/failed/'

LOGIN_URL = '/login/'

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

SOCIAL_AUTH_GOOGLE_OAUTH2_AUTH_EXTRA_ARGUMENTS = {
    'access_type': 'offline',
    'approval_prompt': 'auto',
    'redirect_uri': 'https://siadis.mydomain.sch.id/auth/complete/google-oauth2/'
}

错误

Request Method: GET
Request URL: http://127.0.0.1:51457/auth/complete/google-oauth2/?state=4XEytKWxSU62AuZjlOr888SjzXe1XjEg&code=4%2F0AfgeXvvepRVcezejl-IwUwh6QVw9-AJnZzaz42my-QDlsEFWko2IFWwRml2UH9TRq_RZXw&scope=email+profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=2&prompt=none

Django Version: 3.2.14
Python Version: 3.8.9
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'website.apps.WebsiteConfig',
 'quiz.apps.QuizConfig',
 'django.contrib.humanize',
 'social_django']
Installed 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']



Traceback (most recent call last):
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/social_core/utils.py", line 247, in wrapper
    return func(*args, **kwargs)
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/social_core/backends/oauth.py", line 392, in auth_complete
    response = self.request_access_token(
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/social_core/backends/oauth.py", line 370, in request_access_token
    return self.get_json(*args, **kwargs)
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/social_core/backends/base.py", line 242, in get_json
    return self.request(url, *args, **kwargs).json()
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/social_core/backends/base.py", line 238, in request
    response.raise_for_status()
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)

During handling of the above exception (400 Client Error: Bad Request for url: https://accounts.google.com/o/oauth2/token), another exception occurred:
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/social_django/utils.py", line 46, in wrapper
    return func(request, backend, *args, **kwargs)
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/social_django/views.py", line 31, in complete
    return do_complete(request.backend, _do_login, user=request.user,
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/social_core/actions.py", line 45, in do_complete
    user = backend.complete(user=user, *args, **kwargs)
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/social_core/backends/base.py", line 40, in complete
    return self.auth_complete(*args, **kwargs)
  File "/home/smpnpen1/.asdf/installs/python/3.8.9/lib/python3.8/site-packages/social_core/utils.py", line 250, in wrapper
    raise AuthCanceled(args[0], response=err.response)

Exception Type: AuthCanceled at /auth/complete/google-oauth2/
Exception Value: Authentication process canceled

在安装 django 应用程序时,我在主机上使用了

http://127.0.0.1:51457
,然后将其重定向到域
siadis.mydomain.sch.id

python django google-oauth social-auth-app-django
1个回答
0
投票

你找到解决办法了吗?我也遇到同样的错误。

© www.soinside.com 2019 - 2024. All rights reserved.