我正在尝试将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",
],
},
},
]
从我的网页登录后,我一直收到此错误:
404: That’s an error.
Error: invalid_request
Permission denied to generate login hint for target domain.
答案 0 :(得分:6)
我在javascript中遇到了类似的错误。
在我的情况下,它是授权的JavaScript起源不匹配。在开发人员控制台中根据您的OAuth2 clientID检查您的授权JavaScript来源。如果您正在使用localhost,请确保添加该应用并使用localhost
代替127.0.0.1
OR 0.0.0.0
希望这有助于。