This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
var passport = require('passport'), | ||
FacebookStrategy = require('passport-facebook').Strategy, | ||
User = require('mongoose').model('User'), | ||
config = require('../config'); | ||
|
||
module.exports = function() { | ||
// Use facebook strategy | ||
passport.use(new FacebookStrategy({ | ||
clientID: config.facebook.clientID, | ||
clientSecret: config.facebook.clientSecret, | ||
callbackURL: config.facebook.callbackURL, | ||
}, | ||
function(accessToken, refreshToken, profile, done) { | ||
User.findOne({ | ||
'providerData.id': profile.id | ||
}, function(err, user) { | ||
if (err) { | ||
return done(err); | ||
} | ||
if (!user) { | ||
user = new User({ | ||
firstName: profile.name.givenName, | ||
lastName: profile.name.familyName, | ||
displayName: profile.displayName, | ||
email: profile.emails[0].value, | ||
username: profile.username, | ||
provider: 'facebook', | ||
providerData: profile._json | ||
}); | ||
user.save(function(err) { | ||
if (err) console.log(err); | ||
return done(err, user); | ||
}); | ||
} else { | ||
return done(err, user); | ||
} | ||
}); | ||
} | ||
)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
var passport = require('passport'), | ||
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy, | ||
User = require('mongoose').model('User'), | ||
config = require('../config'); | ||
|
||
module.exports = function() { | ||
// Use google strategy | ||
passport.use(new GoogleStrategy({ | ||
clientID: config.google.clientID, | ||
clientSecret: config.google.clientSecret, | ||
callbackURL: config.google.callbackURL | ||
}, | ||
function(accessToken, refreshToken, profile, done) { | ||
User.findOne({ | ||
'providerData.id': profile.id | ||
}, function(err, user) { | ||
if (!user) { | ||
user = new User({ | ||
firstName: profile.name.givenName, | ||
lastName: profile.name.familyName, | ||
displayName: profile.displayName, | ||
email: profile.emails[0].value, | ||
username: profile.username, | ||
provider: 'google', | ||
providerData: profile._json | ||
}); | ||
user.save(function(err) { | ||
if (err) console.log(err); | ||
return done(err, user); | ||
}); | ||
} else { | ||
return done(err, user); | ||
} | ||
}); | ||
} | ||
)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
var passport = require('passport'), | ||
LinkedInStrategy = require('passport-linkedin').Strategy, | ||
User = require('mongoose').model('User'), | ||
config = require('../config'); | ||
|
||
module.exports = function() { | ||
// Use linkedin strategy | ||
passport.use(new LinkedInStrategy({ | ||
consumerKey: config.linkedin.clientID, | ||
consumerSecret: config.linkedin.clientSecret, | ||
callbackURL: config.linkedin.callbackURL, | ||
profileFields: ['id', 'first-name', 'last-name', 'email-address'] | ||
}, | ||
function(accessToken, refreshToken, profile, done) { | ||
User.findOne({ | ||
'providerData.id': profile.id | ||
}, function(err, user) { | ||
if (!user) { | ||
user = new User({ | ||
firstName: profile.name.givenName, | ||
lastName: profile.name.familyName, | ||
displayName: profile.displayName, | ||
email: profile.emails[0].value, | ||
username: profile.username, | ||
provider: 'linkedin', | ||
providerData: profile._json | ||
}); | ||
user.save(function(err) { | ||
if (err) console.log(err); | ||
return done(err, user); | ||
}); | ||
} else { | ||
return done(err, user); | ||
} | ||
}); | ||
} | ||
)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
var passport = require('passport'), | ||
LocalStrategy = require('passport-local').Strategy, | ||
User = require('mongoose').model('User'); | ||
|
||
|
||
module.exports = function() { | ||
// Use local strategy | ||
passport.use(new LocalStrategy({ | ||
usernameField: 'email', | ||
passwordField: 'password' | ||
}, | ||
function(email, password, done) { | ||
User.findOne({ | ||
email: email | ||
}, function(err, user) { | ||
if (err) { | ||
return done(err); | ||
} | ||
if (!user) { | ||
return done(null, false, { | ||
message: 'Unknown user' | ||
}); | ||
} | ||
if (!user.authenticate(password)) { | ||
return done(null, false, { | ||
message: 'Invalid password' | ||
}); | ||
} | ||
return done(null, user); | ||
}); | ||
} | ||
)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
var passport = require('passport'), | ||
TwitterStrategy = require('passport-twitter').Strategy, | ||
User = require('mongoose').model('User'), | ||
config = require('../config'); | ||
|
||
module.exports = function() { | ||
// Use twitter strategy | ||
passport.use(new TwitterStrategy({ | ||
consumerKey: config.twitter.clientID, | ||
consumerSecret: config.twitter.clientSecret, | ||
callbackURL: config.twitter.callbackURL | ||
}, | ||
function(token, tokenSecret, profile, done) { | ||
console.log(profile); | ||
User.findOne({ | ||
'providerData.id_str': profile.id | ||
}, function(err, user) { | ||
if (err) { | ||
return done(err); | ||
} | ||
if (!user) { | ||
user = new User({ | ||
displayName: profile.displayName, | ||
username: profile.username, | ||
provider: 'twitter', | ||
providerData: profile._json | ||
}); | ||
user.save(function(err) { | ||
if (err) console.log(err); | ||
return done(err, user); | ||
}); | ||
} else { | ||
return done(err, user); | ||
} | ||
}); | ||
} | ||
)); | ||
}; |