Django Rest Framework and React Linkedin Social Authentication OAuth2Error

Viewed 385

I am building web app with Django Rest Framework as backend and React as frontend.

using below libraries

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

I am trying to implement Linkedin authentication but getting bellow error as mentioned

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"}'

Backend code in django rest framework

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

and frontend code like

<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>)}

and CALL_BACK_URL which is already added under redirect urls in linkedin developers.

Frontend api will generated code and pass it to backend api and DRF uses code and generate access_token and call linkedin profile api (internally)

We have Backend running in different domain and frontend is running on different domain.

Can anybody please help me to understand what would be CALL_BACK_URL in backend and what would be in frontend ?

If anybody can share some reference links or code would be appreciated.

0 Answers
Related