Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passport-google-oauth20 passport.authenticate doesn't run #989

Open
t845270g opened this issue Jul 6, 2023 · 9 comments
Open

passport-google-oauth20 passport.authenticate doesn't run #989

t845270g opened this issue Jul 6, 2023 · 9 comments

Comments

@t845270g
Copy link

t845270g commented Jul 6, 2023

When I visit the Google oauth authentication page:

app.get('/user/auth/google', (req, res, next) => {
  passport.authenticate('google', {
    scope: ['profile', 'email'],
  })(req, res, next);
});

My passport about Google oauth authentication strategy:

passport.use(
    new GoogleStrstedy({
    clientID: GOOGLE_CLIENT_ID,
    clientSecret: GOOGLE_CLIENT_SECRET,
    callbackURL: `/auth/google/callback`,
    scope: ['profile', 'email'],
},(accessToken,refreshToken,profile,done)=>{... })  
    
))

redirect page:

app.get("/auth/google/callback",passport.authenticate("google", { session: false, failureRedirect: CLIENT_IP+ "error" }),(req, res) => {
      if (req.user.success) {
                    res.redirect(CLIENT_IP);
            });
      } else {
        res.redirect(CLIENT_IP + "/Register_google?mail=" + req.user.data.mail);
      }
    }
);

When I use Google authentication with localhost:5000 as the backend server, it successfully redirects to the specified page after selecting the authentication account in Google. However, when I upload the frontend of the website to AWS S3 and configure it with CloudFront, and upload the backend to a public EC2 and also configure it with CloudFront, and access the backend server through the HTTPS link generated by CloudFront, the callback function (accessToken, refreshToken, profile, done) => {...} in Google authentication is not executed on the backend server hosted on CloudFront. Instead, the response header redirects to the authentication page: https://accounts.google.com/o/oauth2/v2/auth...
Should I adjust the backend code, Google OAuth settings, or AWS configuration
to successfully execute the authentication process?

未命名-1-01

@t845270g t845270g changed the title google oauth passport.authenticate doesn't run passport-google-oauth20 passport.authenticate doesn't run Jul 6, 2023
@YasharF
Copy link

YasharF commented Jul 21, 2023

This doesn't seem to be a passport issue. It seems like you are not configuring your oauth callback properly, since you said the code works in your dev environment but not production.

@t845270g
Copy link
Author

t845270g commented Jul 22, 2023

看來不是護照問題。看來您沒有正確配置 oauth 回調,因為您說代碼可以在您的開發環境中運行,但不能在生產環境中運行。

But I only changed the environment variables used locally to the ones used for the online website, without modifying any other code.

Moreover, the Google OAuth API settings are also directed to the corresponding URL.

@YasharF
Copy link

YasharF commented Jul 23, 2023

The docs explain it.

@t845270g
Copy link
Author

t845270g commented Jul 24, 2023

The docs explain it.
Could you please share where in the documentation this is explained? I have been trying to figure out the answer to this issue for almost a month, but still haven't found it. Thank you. : )

@YasharF
Copy link

YasharF commented Jul 24, 2023

@t845270g
Copy link
Author

t845270g commented Aug 2, 2023

https://developers.google.com/identity/protocols/oauth2/web-server

I have solved the issue. My Passport Google OAuth 2.0 is not the problem. The issue lies in the deployment on CloudFront, where the cache is not accepting the req.query parameters. This caused an error in the redirected route as it couldn't retrieve the code parameter. Still, thank you very much for your help.

https://developers.google.com/identity/protocols/oauth2/web-server

@tmt203
Copy link

tmt203 commented Jan 18, 2024

where the cache is not accepting the req.query parameters. This caused an error in the redirected route as it couldn't retrieve the code parameter. Still, thank you very much for your help.

I have the same problem with you. How do you solve that ?

@t845270g
Copy link
Author

其中快取不接受 req.query 參數。這導致重定向路由出現錯誤,因為它無法檢索程式碼參數。不過,非常感謝您的幫忙。

我跟你有同樣的問題。你怎麼解決這個問題?
#989 (comment)

@17prateek12
Copy link

can you tell how you figure that issue and resolve exactly i have same problem my google oauth working in development but not in production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants