我目前正在尋求實現一個谷歌的API,使用客戶端的NodeJS谷歌PassportJS認證:使用與谷歌的NodeJS 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
不過,對於谷歌API客戶端的NodeJS的文檔是不是在如何使用的accessToken清楚。 包含的示例顯示OAauth2Client檢索標記,但我猜這部分已經使用Passport進行了覆蓋?
是的,一旦Passport調用成功回調,它成功並具有'profile',所以我認爲它已經完成了所有比較令牌或其他任務的工作。 – Plato