![](/img/trans.png)
[英]Getting a 500 Internal server error when redirecting to the callback url using google OAuth2 with Passportjs
[英]PassportJs Google OAuth2 callback throws this site cant be reached error
我正在嘗試在個人項目中設置“使用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));
}
});
}
)
);
回應文字:
This site can’t be reached. localhost unexpectedly closed the connection.
我想補充一點,我正在本地主機上對此進行測試,我可以在回調URl中看到來自Google的代碼
我想到了 。 回調試圖訪問https:// localhost,我要做的就是在Google Api控制台中將https更改為http,它的工作原理就像一個超級按鈕
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.