I am currently using the OAuth login with LinkedIn in my React and Play application and throwing a CORS error when trying to redirect to the authorization page in my dev environment:
XMLHttpRequest cannot load https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_i…basicprofile&redirect_uri=http%3A%2F%2Flocalhost%3A9000%2Fusers%2Flinkedin. Redirect from 'https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_i…basicprofile&redirect_uri=http%3A%2F%2Flocalhost%3A9000%2Fusers%2Flinkedin' to 'https://www.linkedin.com/uas/login?session_redirect=%2Foauth%2Fv2%2Flogin-s…' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
I have the following setup:
- Playback server running on localhost: 9000
- Responsive application (created through create-response-app) running on localhost: 3000
My JS code calls the endpoint /auth/linkedin, which is implemented as follows:
Action { implicit req: RequestHeader =>
val csrfToken = CSRF.getToken.get.value
Redirect(linkedinUrl(oauthConfig.linkedinClientId, csrfToken)).withSession("state" -> csrfToken)
}
I have a Play application installed to properly handle CORS.
My response application simply sends a request to the above endpoint via Axios:
axios.get('/auth/linkedin')
303 LinkedIn, .
CORS dev? package.json, create-react-app :
"proxy": "http://localhost:9000",
"Access-Control-Allow-Origin" : "*" .
, localhost: 9000/auth/linkedin .