django-rest-auth 通过访问 token 进行谷歌社交身份验证

标签 django django-allauth django-rest-auth

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

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

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.

最佳答案

很难查明错误,因为您没有包含其余代码。该错误仅表示它找不到名称为“redirect”的 url。因此,您可以检查两件事:

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

Under “APIs & auth” go to “Credentials” and create a new Client ID. Probably you will want a “Web application” Client ID. Provide your domain name or test domain name in “Authorized JavaScript origins”. Finally fill in http://127.0.0.1:8000/accounts/google/login/callback/ in the “Authorized redirect URI” field. You can fill multiple URLs, one for each test domain. After creating the Client ID you will find all details for the Django configuration on this page.

关于django-rest-auth 通过访问 token 进行谷歌社交身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54479789/

相关文章:

django - 如何使 Django 模型仅在 Django Admin 中查看(只读)?

reactjs - 前端和后端的 Nginx 配置在同一个文件中

django-allauth HTML 电子邮件不发送

facebook-login - Django-Allauth 和 Facebook URL 被阻止挑战

python - Django AllAuth 自定义模板不被识别

django - 对多种用户类型使用 django-rest-auth 注册

python - PyCharm 无缘无故运行测试时抛出 "AttributeError: ' 模块“对象没有属性”

python - Factory-boy属性属性?

django - Django 中单元测试的 auth_token

python - Django、Angular 和 DRF : Authentication to Django backend vs. API