This is the frontend code to send get request for the access token, where code is the parameter which we get after signing in from LinkedIn, I have checked that this code variable is getting sent properly so it has no issues.
const getAccessToken = async (code) => {
const response = await fetch(`http://localhost:8000/api/getaccesstoken/${code}`)
console.log(response)
}
This is the backend code
router.get('/getaccesstoken/:code', async (req, res)=>{
axios({
method: "post",
mode: 'no-cors',
headers: { "Content-type": "x-www-form-urlencoded"},
url: `https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code=${req.params.code}&client_id=${process.env.client_id}&client_secret={process.env.client_secret}&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fdashboard`
})
.then(function (response) {
console.log(response)
res.send(response)
})
.catch(function(error){
console.log(error)
res.send(error)
})
})
The error I am getting is the console of backend is very big but the last part says this:
{
"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"
} but I am sending the request as soon as it is redirected so the code can't be expired so soon. And when I directly try doing this by passing code using thunderclient request it works fine. Please let me know solutions to this if possible