【问题标题】:Setup redirect URL with correct port for django-allauth为 django-allauth 设置正确端口的重定向 URL
【发布时间】:2018-08-21 19:19:48
【问题描述】:

我尝试按照https://wsvincent.com/django-allauth-tutorial-custom-user-model/的教程进行操作

我授权的所需回调 URL 是

https://localhost:2053/accounts/google/login/callback/

网站下,我填写如下

这就是表格的样子

snapweb=# select * from django_site
snapweb-# ;
 id |  domain   |    name
----+-----------+-------------
  1 | 127.0.0.1 | example.com
(1 row)

我在settings.py中有以下代码

# DJANGO-ALLAUTH SETTINGS
# Site id required for using 'sites' framework with django-allauth
SITE_ID = 1    # 1 is for 127.0.0.1
ACCOUNT_DEFAULT_HTTP_PROTOCOL='https'

然后,我尝试通过点击以下链接登录 Google

<p><a href="{% provider_login_url 'google' %}">Log In with Gmail</a></p>

但是,我从 Google 收到以下错误

似乎django-allauth 传递了错误的重定向 URL 而没有正确的端口 (https://localhost/accounts/google/login/callback/)。

正确的网址应该是

https://localhost:2053/accounts/google/login/callback/

但是 django-allauth 正在过去

https://localhost/accounts/google/login/callback/

我可以知道如何将正确的重定向 URL 传递给 Google 吗?


我尝试了什么?

对于Site,我尝试过各种值,例如

snapweb=# select * from django_site
snapweb-# ;
 id |  domain        |    name
----+----------------+-------------
  1 | 127.0.0.1:2053 | example.com
(1 row)

snapweb=# select * from django_site
snapweb-# ;
 id |  domain        |    name
----+----------------+-------------
  1 | localhost:2053 | example.com
(1 row)

但是,谷歌仍然抱怨收到https://localhost/accounts/google/login/callback/

【问题讨论】:

    标签: django django-allauth


    【解决方案1】:

    Aniket A. Aryamanethis url 的评论说明了如何解决问题:

    在创建 Oauth 2.0 客户端 ID 时,请提及“授权重定向 URI”为:“http://localhost:8000/accounts/google/login/callback/” 而不是“http://127.0.0.1:8000/accounts/google/login/callback/

    2) 更新 Django admin - "Sites" 域名为 "localhost" 而不是“127.0.0.1”

    然后它将按预期工作。

    【讨论】:

      【解决方案2】:

      据我了解,问题是 facebook、google 或任何其他社交媒体登录不支持 localhost。您需要明确定义子域或特定的专用 IP 地址。您可以尝试使用特定域或专用 IP 吗?

      否则你可以使用这个网站进行开发https://tolocalhost.com/ 然后根据您的开发环境对其进行配置。即端口和主机名。

      【讨论】:

        猜你喜欢
        • 2014-05-06
        • 2015-10-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-23
        • 1970-01-01
        • 2013-07-24
        • 2014-10-02
        • 2014-06-09
        相关资源
        最近更新 更多