我对这个错误感到非常沮丧。这是我部署到 heroku https://emm-samrat.herokuapp.com 的应用程序。如果您单击登录按钮,它会显示一个空白页面。但是,如果将 https 更改为 http,一切都会按预期工作。你能告诉我发生了什么事吗?
这是我的passport.js代码
passport.use(
new GoogleStrategy(
{
clientID: keys.googleClientId,
clientSecret: keys.googleClientSecret,
//this is for production
callbackURL: "/auth/google/callback",
proxy: true
},
async (req, accessToken, refreshToken, profile, done) => {
done(null, profile);
}
)
);
app.get(
"/auth/google",
passport.authenticate("google", {
prompt: "select_account",
session: false,
scope: ["openid", "profile", "email"]
})
);
app.get(
"/auth/google/callback",
passport.authenticate("google", { session: false }),
async (req, res) => {
const user = await User.findOne({ authId: req.user.id });
//Stores the User Google Profile ID in session
req.session.authId = req.user.id;
if (user) {
res.redirect("/");
}
//If the user is visiting for the first time,
//he/she should fill the additional form
res.redirect("/signup");
}
);
编辑:如果您的应用程序使用 React。确保删除index.js上的import registerServiceWorker from './registerServiceWorker'
并删除所有浏览器缓存。一切都会按预期进行。
最佳答案
您需要获取 SSL 证书,有一些免费的证书
关于node.js - Node JS Passport google oauth 无法在 https 上工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52819947/