python - social-app-django - 为 GoogleOAuth2 设置重定向 URL 不起作用?
问题描述
我正在使用 social-app-django GoogleOAuth2 后端并遇到了 redirect_uri 的问题
我设法设置 INSTALLED_APP、AUTHENTICATION_BACKENDS、url.py 并在设置中添加以下 3
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY='MY KEY'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET='MY SECRET'
LOGIN_REDIRECT_URL='http://localhost:8000/api/auth/complete/google-oauth2/'
我已将http://localhost:8000/api/complete/google-oauth2/添加到我的 google 授权重定向 URI 中。
我通过访问http://127.0.0.1:8000/login/google-oauth2/触发了身份验证登录(是的,我的项目使用前端反应,所以不使用 Django 模板)。
Problem is I always get this error
Error: redirect_uri_mismatch
The redirect URI in the request, http://127.0.0.1:8000/complete/google-oauth2/, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: ....
生成的身份验证 url 中的 redirect_url 始终为http://127.0.0.1:8000/complete/google-oauth2/,如果我将其替换为我在 Google 控制台中配置的 on ,则它可以工作。所以我猜它一定与设置有关。
看起来重定向 url 设置确实有效,知道有什么问题吗?请帮忙!
解决方案
您可以redirect_uri
在 auth_params 以及access_type
设置文件中添加。
SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': [
'profile',
'email',
],
'AUTH_PARAMS': {
'access_type': 'online',
'redirect_uri': 'http://127.0.0.1:8000/<custom-url>'
}
}
}
推荐阅读
- c# - 如何从位图垫将黑色更改为透明?
- css - Bootstrap 4在col中居中列表并在列表中左对齐文本
- java - 在父类中的方法受保护的情况下,“对对象的引用”如何在动态方法调度中发挥作用?
- c# - 我想将下拉列表中的所有值保存在 .cs 文件的列表中
- php - 将公式存储在 SQL Server 中,然后 PHP 计算并存储结果的最有效方法是什么?
- swift - “AuthDataResult”类型的值没有成员“providerID”
- splunk - 使用 Splunk 调用多个 REST API
- java - 如何在不转换为字符串的情况下完成/修复附加持久性算法?
- python - 如何在 python 中迭代 JSON 子节点?
- c# - ASP.NET Core 发布和启动设置