【发布时间】:2019-04-06 07:01:59
【问题描述】:
我在 Google 应用上的操作的帐户关联中使用“OAuth 和 Google 登录”和“授权代码流”。我已经使用Passport js 编写了自己的服务器,并在其中实现了 Google 身份验证,并将其部署到 Heroku。 我在浏览器中对其进行了测试,它工作正常并成功提供了访问令牌和刷新令牌,但我面临的问题是当我将它与我在谷歌应用程序上的操作集成时,它正确执行身份验证并且没有将 accessToken 发送回我的应用程序,我不明白我应该在“令牌 URL”字段中输入什么。下面是服务器的代码。
passport.use(new GoogleStrategy({
// authorizationURL: 'https://accounts.google.com/o/oauth2/auth',
// tokenURL: 'https://www.googleapis.com/oauth2/v3/token',
clientID: keys.googleClientID,
clientSecret: keys.googleClientSecret,
callbackURL: '/auth/google/callback'
},
(accessToken, refreshToken, profile, done) => {
return done(null, {
token: accessToken
})
}
));
app.get(
'/auth/google',
passport.authenticate('google', {
scope: ['profile', 'email']
})
);
app.get('/auth/google/callback',
passport.authenticate('google', {
failureRedirect: '/login'
}),
function(req, res) {
console.log(req.user.token)
res.send(req.user.token)
});
app.get('/', (req, res) => {
res.send('<h1>Hello express</h1>');
});
【问题讨论】:
标签: passport.js actions-on-google