Django allauth google OAuth redirect_uri_mismatch 错误

Django allauth google OAuth redirect_uri_mismatch error

我正在为我的 Django 应用程序使用 Google OAuth(通过 allauth 包)

我已遵循所有标准配置步骤。在 Google 开发者控制台中,这是我所拥有的:

授权JavaScript来源

https://example.com  

授权的重定向 URI

https://example.com/accounts/google/login/callback/ - login fails
http://example.com/accounts/google/login/callback/ - login succeeds

我观察到,如果我在授权重定向 URI 中有一个 https 重定向 URL,它不允许登录并且失败 redirect_uri_mismatch 错误。如果我有 http 重定向 URL 则登录成功。

我需要做什么才能启用 https 重定向 URL?

在生产中添加以下内容 settings.py 解决了我的问题:

ACCOUNT_DEFAULT_HTTP_PROTOCOL='https'

**这对我有用 :

  1. 转到https://console.developers.google.com
  2. 无端口添加http://127.0.0.1/accounts/google/login/callback/
  3. 同时添加 http:///localhost/accounts/google/login/callback/
  4. 详情见link中的图片

See image by opening link

就我而言,问题如下:

  1. 我的网站将访问权限切换为仅 HTTPS 连接,而在 Google API 仪表板中是 http://profile.example.com/accounts/google/login/callback/
  2. 所以,我改变了: 从 http -> https 开始正常工作。