Django Rest Framework 和 React Linkedin 社会认证 OAuth2Error

时间:2021-02-19 14:34:36

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

我正在使用 Django Rest Framework 作为后端和 React 作为前端构建 Web 应用程序。

使用以下库

  • Django==3.1.5
  • djangorestframework==3.12.2
  • dj-rest-auth==2.1.3
  • django-allauth==0.44.0

我正在尝试实施 Linkedin 身份验证,但如上所述出现以下错误

OAuth2Error at /api/v1/appname/linkedin/
Error retrieving access token: b'{"error":"invalid_request","error_description":"Unable to retrieve access token: appid/redirect uri/code verifier does not match authorization code. Or authorization code expired. Or external member binding exists"}'

django rest 框架中的后端代码

class LinkedInLoginView(CustomLoginView):
    """
    LinkedIn login
    """
    adapter_class = LinkedInOAuth2Adapter
    callback_url = "CALL_BACK_URL"
    client_class = OAuth2Client

和前端代码如

<LinkedIn
    clientId="CLIENT_ID"
    callback={callbackLinkedIn}
    scope={["r_liteprofile", "r_emailaddress"]}
    text={rendertext()}
    className='ant-btn LinkdinIcon ant-btn-link'
    redirect_uri="CALL_BACK_URL"
    render={renderProps => (
    <Button type="link" className="LinkdinIcon" onClick={renderProps.onClick}>
<LinkdinIcon /></Button>)}

CALL_BACK_URL 已添加到linkedin 开发者的重定向网址下。

前端 api 将生成 code 并将其传递给后端 api,DRF 使用 code 并生成 access_token 并调用linkedin 配置文件 api(内部)

我们在不同的域中运行后端,而前端在不同的域中运行。

有人可以帮我理解什么是后端CALL_BACK_URL,什么是前端吗?

如果有人可以分享一些参考链接或代码,我们将不胜感激。

0 个答案:

没有答案
相关问题