0

I'm trying to integrate with linkedin but with Authorization param in the header, I followed the docs and i'm stuck in the last step which is Step 4 — Make authenticated requests, I'm using JS so i don't know how to add header to IN.API.Raw("/people/~?format=json").result(onSuccess).error(onError);, So i tried to do it manually with XMLHttpRequest.

n_url = "https://api.linkedin.com/v1/people/~?format=json";
var gg = new XMLHttpRequest();
gg.open("GET", n_url, true);
gg.setRequestHeader("Access-Control-Allow-Origin", "*");
gg.setRequestHeader("Authorization", "Bearer "+[ACCESS_TOKEN]);
gg.send(null);

but this gives OPTIONS https://api.linkedin.com/v1/people/~?format=json error in the console in addition to Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource., So is there any way to use IN.API that allows me to add some headers (this will be simple), Or what should i do to fix my manual request, I'm noticing that the sent request is OPTION not GET, i searched a lot about that but i didn't get a clear answer.

Any help?

Amr Adel
  • 574
  • 1
  • 7
  • 18
  • If you're using client-side JS then follow [their instructions for client side JS](https://developer.linkedin.com/docs/getting-started-js-sdk) and not their generic OAuth instructions. – Quentin Dec 16 '17 at 23:29
  • Access-Control-Allow-Origin is a **response** header, not a request header. – Quentin Dec 16 '17 at 23:29
  • I appreciate your comments, excuse me if my questions is duplicated or i got less knowledge, I have my server side which need uid to login, So at first i get `code` and send it to and end-point in my server which use `code` to get an `access_token` and send it back to front-end, My idea was to use this access_token with /people/~ to get user info and send uid of the user to the server side to login, Is there a better way to do this? – Amr Adel Dec 16 '17 at 23:35
  • Step 4 of the instructions you linked to is for when you are making the HTTP request from your server-side code. You make the request directly from your server-side code. You don't make it with client-side JS and then pass the response back to your server. – Quentin Dec 16 '17 at 23:48
  • It is my bad, Thank you very much. – Amr Adel Dec 16 '17 at 23:50
  • @Amr Adel, can you please guide me how you get the access token. I'm using JavaScript as frontend. – Sankar Dec 17 '17 at 10:20
  • For sure @Sankar, Did you tried send make all the params in the url? Like `https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code...` and put the rest of the params instead of ..., just don't send them as a POST request parameters as we all know, but i don't think it work from JS only you need to make your server-side call it to work ... after you get the access_token, make a call from your server side to the /people/~ too as @Quentin said, Hope this helps. – Amr Adel Dec 17 '17 at 12:19
  • @AmrAdel can you please tell me how did you get **code** from client side? I just used as a link like this `Login` – Sankar Dec 17 '17 at 15:39
  • My requirement is to login from client side (JS), get the **accessToken** and send it to server for process – Sankar Dec 17 '17 at 15:44
  • Actually i don't know if it going to work from your client-side but i think you should not do this because you are using your `secret_key` which is should be something private and not to be something reachable from front-end. – Amr Adel Dec 17 '17 at 22:32

0 Answers0