I have a web application using Angular+Node+Express+Mongo and I have implemented an OAuth using passport.js for users to sign in to my app. At the moment I can type send a GET request and passport will handle the authentication and the google "sign in with google" will show up.
That works but I'm still having a hard time understanding how can I integrate this authentication to the angular app (the frontend). This is what I have so far:
// In the server passport is taking care of the authentication
passport.use(new GoogleStrategy({
clientID: config.googleClientID,
clientSecret: config.googleClientSecret,
callbackURL: '/api/authentication/google/redirect'}, function someCallback(){})
innerRouter.get('/google', passport.authenticate('google', { scope: ['profile'] }))
I tried in my frontend to send a get request like this:
loginWithGoogle() {
this.http.get('http://localhost:3000/api/authentication/google').subscribe(data => alert('WORKED')
But i got a cross origin
error, probably because of the redirect URL.
After some reading, I found this link Google sign in tutorial and it shows how to integrate a sign-in in the frontend.
But at this point I'm lost, what is the difference between what I did in the server to this tutorial?
How can i access my http://localhost:3000/api/authentication/google
without a cross origin error?
Am I even on the right way?
Edit: This is the cross origin
error
Access to XMLHttpRequest at 'https://accounts.google.com/o/oauth2/v2/auth?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Fauthentication%2Fgoogle%2Fredirect&scope=profile&client_id=783372588251-bkdsfh89a0riisdk7i0oirpch7g3dvoj.apps.googleusercontent.com' (redirected from 'http://localhost:3000/api/authentication/google') from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.