0
I have an Ionic-angular project with server developed in nodejs. I’m trying to do a user authentication by sending a request to the google api through the framework Passport using the Google-Strategy.
When making the request, the following error occurs:
"Failed to load https://accounts.google.com/o/oauth2/v2/auth?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fuser%2Fgoogle%2Fredirect&scope=profile&client_id=976813214537-0a1kl69viqpgg5ibtcgt743secpsmrld.apps.googleusercontent.com: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 405"
On my server, I’m already granting permission to all request sources. So I can’t understand why I’m having this problem.
The problem seems to happen because I am using the browser to test the application through the command ionic serve
. I’ve even added an extension to Chrome that grants permission to origins, but hasn’t solved my problem.
In my request, Ionic calls a "router" that is encoded in my nodejs server and the server requests the google api. In both solutions you gave me, the request is made directly from Ionic to the google api, without calling the Beck-end server. The answer you gave me makes perfect sense, however, how do I do this procedure so that the request is made by the server? Because there is the Google-Strategy set up to do the authentication. It would look like this: Ionic -> nodejs server -> Google Api.
– Cristian Quadros
Can you include the proxy on your server? So, the sending address of the request would be proxy + Google-Strategy address.
– Renata
I’ve never done this, but I can research it. Thank you very much
– Cristian Quadros