2

I am sending a request by looking at the criteria below. It results successfully, but there is no token in the response. I don't understand what am I missing.

const fetchLinkedinToken = linkedinCode => {
const requestedUrl = `${BASE_LINKEDIN_URL}?grant_type=authorization_code
                        &code=${linkedinCode}
                        &redirect_uri=${window.location.origin}/linkedin&client_id=${LINKEDIN_CLIENT_ID}
                        &client_secret=${LINKEDIN_CLIENT_SECRET}`;
fetch(requestedUrl, {
  mode: 'no-cors',
  method: 'POST',
  'Content-Type': 'application/x-www-form-urlencoded',
})
  .then((resp1, resp2) => {
    console.log(resp1, resp2);
  })
  .catch(error => {
    console.log(error);
  });

enter image description here

enter image description here

enter image description here

If i call url in the web or postman, i can get the access_token Also i tried Content-Type': 'application/x-www-form-urlencoded in header also same result :(

umit
  • 57
  • 2
  • 8
  • So what response do you get, what did those console.log statements output? – CBroe Dec 14 '21 at 07:31
  • i added the question my response. In the network is empty. In the function response is above image – umit Dec 14 '21 at 07:39
  • You are getting an `opaque` response here, check https://stackoverflow.com/q/39109789/1427878 for details if you don't know what that means. This is due to `mode: 'no-cors'` - you need to make an actual CORS request here (_if_ the API endpoint allows for that.) – CBroe Dec 14 '21 at 07:48
  • In that scenario(If i remove no-cors), I am getting CORS error. – umit Dec 14 '21 at 07:54
  • 1
    Which is understandable, since this endpoint requires your client secret - which should of course not be exposed in client-side code to begin with. You will have to make this request from a server then, or check if they offer any other method for a client-side login flow. – CBroe Dec 14 '21 at 07:58

0 Answers0