【发布时间】:2013-07-29 05:11:36
【问题描述】:
我目前正在考虑使用 nodejs 客户端实现一个 google api:
https://github.com/google/google-api-nodejs-client/
我正在尝试使用护照进行身份验证,这似乎可以正常工作@
passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "http://localhost:3000/auth/google/callback"
},
function(accessToken, refreshToken, profile, done) {
process.nextTick(function () {
var user = {
id: profile.id,
email: profile.email,
firstName: profile.given_name,
lastName: profile.family_name,
accessToken: accessToken
};
return done(null, user);
});
}
));
在我的谷歌身份验证回调中:
app.get('/auth/google/callback',
passport.authenticate('google', { failureRedirect: '/login' }),
function(req, res) {
//do something here with the google api
});
我可以得到req.user,这里有accessToken
但是,Google api nodejs 客户端的文档并不清楚如何使用 accessToken。 包含的示例显示 OAauth2Client 检索令牌,但我猜这部分已经使用 Passport 覆盖?
【问题讨论】:
-
是的,一旦 Passport 调用成功回调,它就成功了,并且有
profile,所以我假设它已经完成了所有比较令牌或其他的工作。
标签: node.js google-api passport.js google-api-client