【问题标题】:How to connect accounts with Django rest auth / all auth?如何将帐户与 Django rest auth / all auth 连接?
【发布时间】:2019-02-14 04:54:03
【问题描述】:

我正在使用 Django rest-auth 通过 Django rest 框架进行身份验证和帐户创建。目前,我设置了六个提供商,我想开始连接它们。

从文档(rest-auth 或 all-auth)中不清楚我必须做什么才能连接帐户。

例如,如果我尝试将 Google 帐户连接到 LinkedIn 帐户(相同的电子邮件地址),即使我使用 Google 提供商的正确访问令牌向 /rest-auth/linkedin/connect/ 发出 POST 请求,我也会收到 400 响应说:"non-field-errors": [ "Incorrect value" ]。

我正在使用 JWT 进行身份验证,并在 Authorization 标头中提供正确的令牌。

views.py

class GoogleConnect(SocialConnectView):
    adapter_class = GoogleOAuth2Adapter

class LinkedInConnect(SocialConnectView):
    adapter_class = LinkedInOAuth2Adapter

【问题讨论】:

  • 我猜这个包几乎没用了。我也可以自己实现它。

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


【解决方案1】:

我已经写了一个教程来解决你的问题。 This 应该是您要查找的部分。

简而言之:您必须编写自己的 ConnectView,它继承自 rest_auth 视图,如下所示:

class GoogleCallbackConnect(SocialConnectView):
    """
    Connects the provider's user account to the currently logged in user.
    """
    adapter_class = GoogleOAuth2Adapter
    client_class = OAuth2Client

    @property
    def callback_url(self):
        url = self.adapter_class(self.request).get_callback_url(
            self.request,
            None,
        )
        return url

【讨论】:

    猜你喜欢
    • 2020-10-03
    • 2014-05-13
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多