【问题标题】:django-rest-auth google social auth by access tokendjango-rest-auth google social auth by access token
【发布时间】:2019-06-26 01:08:52
【问题描述】:

我正在通过 API 使用 django-rest-auth 进行社交身份验证。 我已经配置了 Facebook,它运行良好,但我在 Google 社交身份验证方面遇到了一些问题。

  1. 我已经添加到INSTALLED_APPS
allauth.socialaccount.providers.google',
  1. 创建的视图:

from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter
from allauth.socialaccount.providers.oauth2.client import OAuth2Client

class CustomGoogleOAuth2Adapter(GoogleOAuth2Adapter):
    basic_auth = False


class GoogleLogin(SocialLoginView):
    adapter_class = CustomGoogleOAuth2Adapter
    client_class = OAuth2Client
  1. 由管理面板创建的应用程序
  2. 我收到了来自https://developers.google.com/oauthplayground/access_token
  3. 当我尝试通过端点登录时出现错误:
Reverse for 'redirect' not found. 'redirect' is not a valid view function or pattern name.

【问题讨论】:

  • 这是您的views.py 文件的全部内容吗?
  • 检查这是否对您有任何帮助stackoverflow.com/a/48182227/2560466
  • @Ernst 分享你的根urls.py
  • 我也是用access_token,没有设置回调url。

标签: django django-allauth django-rest-auth


【解决方案1】:

由于您没有包含其余代码,因此很难确定错误。该错误仅意味着它找不到名称为“重定向”的网址。所以你可以检查两件事:

urlpatterns = [
    ...,
    url(r'^rest-auth/', include('rest_auth.urls'))
]

在“APIs & auth”下,转到“Credentials”并创建一个新的客户端 ID。 您可能需要一个“Web 应用程序”客户端 ID。提供您的 “Authorized JavaScript origins”中的域名或测试域名。 最后填写http://127.0.0.1:8000/accounts/google/login/callback/ 在“授权重定向 URI”字段中。您可以填写多个网址, 每个测试域一个。创建客户 ID 后,您会发现 此页面上 Django 配置的所有详细信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-13
    • 2019-06-07
    • 2020-05-16
    • 2018-07-31
    • 2017-04-30
    • 2015-01-12
    • 1970-01-01
    • 2014-05-13
    相关资源
    最近更新 更多