Python 社交身份验证“AuthForbidden”

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

我正在尝试使用社交身份验证让谷歌身份验证与 django 一起使用,但到目前为止我还没有任何运气。具有类似错误消息的其他问题表明这可能是由白名单引起的,但我想接受我的应用程序中的所有 gmail 后缀。 (无需白名单)

INSTALLED_APPS = [
    'livereload',  # TODO Remove when finished
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'dashboard.apps.DashboardConfig',
    'user.apps.UserConfig',
    'social_django'
]

'social_django.context_processors.backends'
'social_django.context_processors.login_redirect'
都在settings.py中的上下文处理器中。

AUTHENTICATION_BACKENDS = (
 'social_core.backends.open_id.OpenIdAuth',  # for Google authentication
 'social_core.backends.google.GoogleOpenId',  # for Google authentication
 'social_core.backends.google.GoogleOAuth2',  # for Google authentication
 'django.contrib.auth.backends.ModelBackend',
)
urlpatterns = [
    path('dashboard/', include("dashboard.urls", namespace="dashboard")),
    path('admin/', admin.site.urls),
    path('login/', auth_views.LoginView.as_view(), name="login"),
    path('logout/', auth_views.LogoutView.as_view(), name="logout"),
    path('auth/', include("social_django.urls", namespace="social")),
]

当我使用 google 登录并重定向到我的身份验证网址时,我收到消息:

AuthForbidden at /auth/complete/google-oauth2/
Your credentials aren't allowed

如何让它正常工作?

编辑:我正在查看错误消息并发现了这一点,如果这对任何人有任何帮助。

http_error_msg = ('401 Client Error: Unauthorized for url: 'https://accounts.google.com/o/oauth2/token')

reason = 'Unauthorized'

self = <Response [401]>
python django python-social-auth
2个回答
1
投票

经过几天漫长的故障排除,归结为一些我应该更加关注的问题。

  1. 确保您的客户端 ID 和密码正确,末尾没有空格。
  2. 确保在凭证屏幕(在 Google 的云控制台上)您提供了 javascript 和重定向 URL,这似乎是让我困惑的地方。

0
投票

就我而言,我需要删除数据库并重新运行所有迁移

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