【发布时间】:2017-07-15 04:00:57
【问题描述】:
我正在使用以下库:
passport-oauth2-password-grant
我想要做的是:
- 对 API 进行身份验证(用户名/密码)
- 获取访问令牌
- 从 API 获取用户配置文件
- 使用护照登录用户
我正在使用以下实现:
PasswordGrantStrategy.prototype.userProfile = function(accessToken, done) {
return done(null, { real_name: 'Foo Baz', email: 'test@test.com' });
}
passport.use(new PasswordGrantStrategy({
tokenURL: 'http://api.local/oauth/token',
clientID: "2",
clientSecret: "",
grantType: "password",
},
function(accessToken, refreshToken, profile, done) {
return done(null, profile);
}));
function authenticate() {
return function(req, res, next) {
var username = "email@email.com";
var password = "password";
passport.authenticate('password-grant', {
username: username,
password: password
})(req, res, next);
};
}
使用用户名/密码登录 API
它正在将配置文件传递给passport.use(new PasswordGrantStrategy 的回调函数但是,我收到以下错误:
无法将用户序列化到会话中
它应该是序列化的,因为我正在传递一个配置文件并且一切看起来都很好。现在这是否意味着会话可能存在问题?
【问题讨论】:
标签: node.js passport.js