我使用的是用于passportjs的Google登录策略。 (我尝试过同时使用google-oauth2和google-plus-login)。
我正在尝试使用承载访问令牌为经过身份验证的调用构建一个restful无状态API。因此,我不想使用passportjs会话。
以下是我的Web应用程序的流程(使用Angular):
我的问题是我不确定passportjs是为此而建的。我找不到不的方式来使用会话。
passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: config.getGoogleLoginCallback()
},
function(accessToken, refreshToken, profile, callback) {
callback(null, profile);
}));
function googleLoginCallback() {
// using req.user (The Google profile) to check my
// database if user's email exists in the database.
// If it does, generate an access token, save it to
// my database for the user, then return it back:
res.send(new User(access_token)); // use User to send back json
}
我与护照开会:passport.authenticate('google', {failureRedirect: config.getGoogleLoginFailureRedirect, session: false})
。
似乎一切都会很好,因为它运作良好。但是,行res.send(access_token);
是一行不起作用。在我的Web应用程序中,不会发回访问令牌。我的想法是res.send(access_token)
正在向谷歌发送回称为我的回调函数的谷歌?
如何以JSON格式向用户发送访问令牌以保持我的API无状态?