passport
passport copied to clipboard
passport-google-oauth20 passport.authenticate doesn't run
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?
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.
看來不是護照問題。看來您沒有正確配置 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.
The docs explain it.
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. : )
https://developers.google.com/identity/protocols/oauth2/web-server
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
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 ?
其中快取不接受 req.query 參數。這導致重定向路由出現錯誤,因為它無法檢索程式碼參數。不過,非常感謝您的幫忙。
我跟你有同樣的問題。你怎麼解決這個問題? https://github.com/jaredhanson/passport/issues/989#issuecomment-1662738087
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