I have a loopback API server configured with Passport running on port 3000. My UI is composed by react JS which is being served from port 3080. I want to implement authentication with Google. For this, from my react application, I am making a call to
localhost:3000/auth/google
But the call is not getting redirected to google because of the CORS error :
Fetch API cannot load http://localhost:3000/auth/google. Redirect from 'http://localhost:3000/auth/google' to 'https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=h…d=584602753475-1kk345gd8trcn31pbg1v2gncajhpakk8.apps.googleusercontent.com' has been blocked by CORS policy: Request requires preflight, which is disallowed to follow cross-origin redirect.
When I hit http://localhost:3000/auth/google
url from a fresh browser tab, everything is working fine.
Can anyone tell where should I enable the cors ?
Edit
I could see that, the browser is making an options request to localhost:3000/auth/google
This is what I got when I made an options request with curl :
HTTP/1.1 204 No Content
X-Powered-By: Express
Vary: Origin
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET,HEAD,PUT,PATCH,POST,DELETE
Access-Control-Max-Age: 86400
Date: Mon, 20 Feb 2017 14:05:53 GMT
Connection: keep-alive