Linkedin OAuth2 invalid access token

43 views Asked by At

I have a React app on frontend, using https://github.com/nvh95/react-linkedin-login-oauth2

My code:

import React from 'react'
import { LinkedIn } from 'react-linkedin-login-oauth2'
import linkedin from 'react-linkedin-login-oauth2/assets/linkedin.png'
import API from '@src/API'
import axios from 'axios'

export const LinkedInPage = () => {
  const redirectUri = `${window.location.origin}/linkedin`

  return (
    <LinkedIn
      clientId='*****'
      redirectUri={redirectUri}
      scope='profile,email'
      onSuccess={(code) => {
        console.log(code)
      }}
      onError={(error) => {
        console.log(error)
      }}
    >
      {({ linkedInLogin }) => (
        <img
          onClick={linkedInLogin}
          src={linkedin}
          alt='Sign in with Linked In'
          style={{ maxWidth: '180px', cursor: 'pointer' }}
        />
      )}
    </LinkedIn>
  )
}

When I get the token (code) as a response of successful auth I copy it and try to get user info sending the request (using Postman, Authorization Bearer Token) to: GET https://api.linkedin.com/v2/userinfo with Bearer (my token). I do it in under 10 sec and always I get

{
    "serviceErrorCode": 65600,
    "message": "Invalid access token",
    "status": 401
}

I need to send this token to the Laravel backend and then get the user from the Token. But it always fails.

Any suggestions? What should I try to do next? I am out of ideas.

0

There are 0 answers