【发布时间】:2018-10-16 23:44:37
【问题描述】:
我对这个错误感到非常沮丧。这是我部署到 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' 并删除所有浏览器缓存。一切都会按预期进行。
【问题讨论】:
-
我的猜测是谷歌不会响应不安全的请求,只是因为你的 url 中有
https并不意味着你有 SSL 证书,你需要为你的应用程序获取一个。更多信息在这里devcenter.heroku.com/articles/…
标签: node.js express passport.js