Reputation: 1084
I have setup a MEAN.IO app using the base template and am attempting to add Windows Live and Yahoo passport authentication dependencies.
I have npm installed both dependencies and set up the code (see below) just like the other passport schemes like Facebook and Google (which came pre-installed and are working).
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);
}
});
});
}
));
user routes (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);
I keep getting Error: Unknown authentication strategy "windowslive" and Error: Unknown authentication strategy "yahoo" however the facebook and google routes work fine. Any idea why? Are there any other steps needed to configure new Passport strategies?
Upvotes: 4
Views: 4618
Reputation: 960
Try adding this to your passport.use statement:
passport.use('windowslive', new WindowsLiveStrategy({
...
Upvotes: 8