ArkeologeN / node-linkedin

LinkedIn 2.0 wrapper in Node.js
MIT License
163 stars 79 forks source link

CORS #71

Closed sohaib-khan closed 7 years ago

sohaib-khan commented 7 years ago

Hi, I have a expressjs server behind nginx running on port 3000. Instead of using localhost I am using app.localhost.co (entry in the hosts file against 127.0.0.1).

On the angular client when I press the Authenticate button, rest call is made to expressjs. I get the following error

XMLHttpRequest cannot load https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client…allback&scope=r_basicprofile%20r_emailaddress%20rw_company_admin%20w_share. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://app.localhost.co' is therefore not allowed access.

I added nodejs cors package and created middleware but still the same issue.

The interesting part is that in dev tools on chrome/firefox is I hit the rest api directly it takes me to the Linkedin authenticate page and redirect url works well but call made via angular client results in error related to No 'Access-Control-Allow-Origin' header is present.

Any idea if your package works with angular client?

ArkeologeN commented 7 years ago

Hi,

This package is normally used on the backend for making the API calls. However, it is agnostic because being written in node. Generally, CORS has nothing to do with the wrapper because we are not initiating your API Server (i.e express server).

Therefore, please take a look on adding middleware of CORS in your backend as well as allow the cross-origins in your angular client. Also, take a look at jsonp as it prevents the CORS too.