#NestJS OAuth Redirection Doubt

3 messages · Page 1 of 1 (latest)

serene perch
#

Good community, I have a question for you, it turns out that I am doing authentication in my backend with providers such as Google and Facebook. I do the implementation well and I get to the point where the provider generates the redirection to indicate that the authentication was successful.

In the Frontend, what should I do in that case so as not to show that redirect to the end user?

The Frontend must use the token that gives the redirect endpoint (the endpoint gives me the token and user data) but what I want to achieve is that the Frontend only gets that data and then shows the home of the application

serene perch
#

I found a way to do it, simply when the authentication provider (whether Google, Facebook, etc.) redirects me indicating the success of the operation because instead of returning the token and that’s it, I can send it to the Frontend so that it can capture it.

silver shale
#

So, the reply you get with the redirect URL only entails the authorization code. Your backend must then send the authorization code with the clientId and clientSecret to the Oauth provider (Google or Facebook) and that request, should the authorization code and the client credentials all be valid, will return the access and refresh tokens from that provider saying that user is also "valid" to access your site. It is up to you then to decide how to handle that user's session in your system. So, you are only half way there. 🙂