[英]PassportJs Google OAuth2 callback throws this site cant be reached error
i'm trying to set up "Sign In with Google" in a personal project and when i call the google auth route i get a "this site cant be reached error" on callback. 我正在尝试在个人项目中设置“使用Google登录”,当我调用Google Auth路由时,在回调中出现“无法访问此网站错误”。
app.get(
"/user/auth/google",
passport.authenticate("google", {
scope: [
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email"
]
})
);
app.get(
"/user/auth/google/callback",
passport.authenticate("google", {
successRedirect: "/wsup",
failureRedirect: "/login"
}),
(req, res) => {
console.log("callback called");
}
);
passport.use(
new googleStrategy(
{
clientID: process.env.googleClientID,
clientSecret: process.env.googleClientSecret,
callbackURL: "https://localhost:3000/user/auth/google/callback",
proxy: true
},
(accessToken, refreshToken, profile, done) => {
console.log(profile.emails[0].value);
User.findOne({ googleId: profile.id }).then(user => {
if (user) {
console.log("existing");
done(null, user);
} else {
new User({ googleId: profile.id })
.save()
.then(newUser => done(null, newUser));
}
});
}
)
);
Response Text: 回应文字:
This site can’t be reached. localhost unexpectedly closed the connection.
i would like to add that i am testing this on localhost and i can see the code from google appended in the callback URl 我想补充一点,我正在本地主机上对此进行测试,我可以在回调URl中看到来自Google的代码
i figured it out . 我想到了 。 the callback was trying to access https://localhost all i had to do was to change https to http in google Api console and it works like a charm 回调试图访问https:// localhost,我要做的就是在Google Api控制台中将https更改为http,它的工作原理就像一个超级按钮
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.