我已经使用基本模板设置了MEAN.IO应用程序,并尝试添加Windows Live和Yahoo passport身份验证依赖项。
我有npm安装了两个依赖项并设置了代码(见下文),就像其他护照方案一样,如Facebook和谷歌(已预先安装并正在运行)。
passport.js:
YahooStrategy = require('passport-yahoo-oauth').Strategy,
WindowsLiveStrategy = require('passport-windowslive').Strategy,
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy,
// Use windows live strategy
passport.use(new WindowsLiveStrategy({
clientID: config.strategies.windowslive.clientID,
clientSecret: config.strategies.windowslive.clientSecret,
callbackURL: config.strategies.windowslive.callbackURL
},
function(accessToken, refreshToken, profile, done) {
User.findOne({
'windowslive.id': profile.id
}, function(err, user) {
if (user) {
return done(err, user);
}
user = new User({
name: profile.displayName,
email: profile.emails[0].value,
username: profile.emails[0].value,
provider: 'windowslive',
windowslive: profile._json,
roles: ['authenticated']
});
user.save(function(err) {
if (err) {
console.log(err);
return done(null, false, {message: 'Windows Live login failed, email already used by other login strategy'});
} else {
return done(err, user);
}
});
});
}
));
用户路由(server / users / routes.js)
// Setting the windows live oauth routes
app.route('/api/auth/windowslive')
.get(passport.authenticate('windowslive', {
failureRedirect: '/login',
scope: ['wl.signin','wl.basic']
}), users.signin);
app.route('/api/auth/windowslive/callback')
.get(passport.authenticate('windowslive', {
failureRedirect: '/login'
}), users.authCallback);
我一直收到错误:未知的身份验证策略“windowslive”和错误:未知的身份验证策略“yahoo”但Facebook和谷歌路由工作正常。知道为什么吗?是否还需要其他步骤来配置新的Passport策略?
答案 0 :(得分:6)
尝试将此添加到passport.use声明中:
passport.use('windowslive', new WindowsLiveStrategy({
...