gpt4 book ai didi

python 社交身份验证未注册域

转载 作者:行者123 更新时间:2023-11-30 23:21:26 27 4
gpt4 key购买 nike

我在 Google 中使用 python-social-auth 的实现时遇到困难。

我收到的错误是400:OpenID 身份验证请求包含未注册的域

我反复检查并要求另一位开发者在 Google 开发者控制台中检查该项目的凭据,一切看起来都不错。

我在过去的 Django 项目中成功使用了 python-social-auth,但这一次我没有找到解决方案。

这个项目和上一个项目之间的唯一区别(据我所知)是:

  1. 此网站当前是一个子域 (test.domain.com)
  2. 它位于 Linode 负载均衡器后面 - 两个应用程序服务器通过静态 IP 响应均衡器,为 doamin/子域配置了 nginx,并且我的 DNS 记录已更新。

我知道Google is in the process of deprecating OpenID ,但通过设置配置为使用 OAuth2:

AUTHENTICATION_BACKENDS = (
'social.backends.open_id.OpenIdAuth',
'social.backends.google.GoogleOAuth2',
'social.backends.google.GoogleOAuth',
'social.backends.google.GoogleOpenId',
'social.backends.facebook.FacebookOAuth2',
'django.contrib.auth.backends.ModelBackend',
# custom password checker - migrating from old rails site, want to preserve old passwords
'auth.authentication.legacy_hasher.LegacyCustomerAuthBackend',
)

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = os.environ.get('SOCIAL_AUTH_GOOGLE_OAUTH2_KEY', 'redacted-key')

SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = os.environ.get('SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET', 'redacted-key')

是否有我遗漏的内容或未能配置的内容?

最佳答案

为了使这项工作顺利进行,我彻底修改了我的身份验证。它不需要调整或 fork 或任何其他类似的东西。问题出在 Google 而不是 python-social-auth。不过,该项目的文档需要更新,以反射(reflect) Google 的变化并描述推荐/测试的策略。

解决方案

解决方案在 python-social-auth's issues under google+ .

  1. 在 Google Developer Apps Console 中,确保您的项目已注册。
  2. API 下,确保您已激活 Google+
  3. 凭据下,生成新的客户端 ID...
  4. 确保您的域/子域/端口在源下全部正确...
  5. 确保回调/重定向 URI 与源地址相同,加上 /complete/google-oauth2/
  6. 在项目的网址中,确保您已正确设置社交身份验证。
  7. 无论您将链接放在模板中的什么位置,请确保使用 {% url 'social:begin' 'google-oauth2' %}

应该可以解决这个问题。

视觉辅助

...无法发布图片,缺乏信誉...imgur 链接啊嘿!

API 和凭证

apis and creds images

urls.py

url(r'^', include('social.apps.django_app.urls', namespace='social')),

settings.py

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

MIDDLEWARE_CLASSES = (
'django.middleware.gzip.GZipMiddleware',
'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',
'social.apps.django_app.middleware.SocialAuthExceptionMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect',
'django.contrib.auth.context_processors.auth',
)

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = os.environ.get(
'SOCIAL_AUTH_GOOGLE_OAUTH2_KEY',
'some_stuff.apps.googleusercontent.com'
)

SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = os.environ.get(
'SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET',
'secret'
)

模板

<div class="container">
<a href="{% url 'social:begin' 'google-oauth2' %}">Login With Google</a>
</div>

关于python 社交身份验证未注册域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24958648/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com