谷歌登录网站Django:拒绝生成目标域的登录提示权限

ver*_*sim 1 html django google-login web django-allauth

我正在尝试将Google登录信息整合到我的网站中.我正在关注此示例:https://developers.google.com/identity/sign-in/web/

我也关注了http://www.marinamele.com/user-authentication-with-google-using-django-allauth,

我为我的项目生成了客户端ID并将其替换为上面的代码,我的settings.py如下:

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)

SITE_ID = 1
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_EMAIL_VERIFICATION = "none"
LOGIN_REDIRECT_URL = '/'
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = \
{
'google': {
    'SCOPE': ['profile','email'],
    'AUTH_PARAMS': {'auth_type': 'reauthenticate', 'access_type':'online'},
    'METHOD': 'oauth2',
    'VERIFIED_EMAIL': False
}
}
TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, "templates")],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.contrib.auth.context_processors.auth',
            'django.template.context_processors.debug',
            'django.template.context_processors.i18n',
            'django.template.context_processors.media',
            'django.template.context_processors.static',
            'django.template.context_processors.tz',
            'django.contrib.messages.context_processors.messages',
            # Required by allauth template tags
            "django.core.context_processors.request",
            # allauth specific context processors
            "allauth.account.context_processors.account",
            "allauth.socialaccount.context_processors.socialaccount",
        ],
    },
   },
]
Run Code Online (Sandbox Code Playgroud)

从我的页面登录时我一直收到此错误:

404: That’s an error.

Error: invalid_request

Permission denied to generate login hint for target domain.
Run Code Online (Sandbox Code Playgroud)

小智 6

我在javascript中遇到了类似的错误.

在我的情况下,它是授权的JavaScript起源不匹配.在开发人员控制台中根据您的OAuth2 clientID检查您的授权JavaScript来源.如果您正在使用localhost,请务必添加并运行您的应用程序 localhost而不是127.0.0.1 OR0.0.0.0

希望这可以帮助.