diff --git a/app/models/user.js b/app/models/user.js index d3bfcbc6..e24b0b11 100755 --- a/app/models/user.js +++ b/app/models/user.js @@ -23,7 +23,8 @@ var UserSchema = new Schema({ facebook: {}, twitter: {}, github: {}, - google: {} + google: {}, + linkedin: {} }); /** diff --git a/app/routes/users.js b/app/routes/users.js index 02793d5b..e254d158 100644 --- a/app/routes/users.js +++ b/app/routes/users.js @@ -63,4 +63,14 @@ module.exports = function(app, passport) { failureRedirect: '/signin' }), users.authCallback); + // Setting the linkedin oauth routes + app.get('/auth/linkedin', passport.authenticate('linkedin', { + failureRedirect: '/signin', + scope: [ 'r_emailaddress' ] + }), users.signin); + + app.get('/auth/linkedin/callback', passport.authenticate('linkedin', { + failureRedirect: '/siginin' + }), users.authCallback); + }; diff --git a/app/views/users/auth.jade b/app/views/users/auth.jade index a1f8c2cf..fadb270d 100755 --- a/app/views/users/auth.jade +++ b/app/views/users/auth.jade @@ -11,6 +11,8 @@ block content img(src="/img/icons/twitter.png") a(href="/auth/google") img(src="/img/icons/google.png") + a(href="/auth/linkedin") + img(src="/img/icons/linkedin.png") .col-md-6 if message && message.length .fade.in.alert.alert-error diff --git a/config/env/development.js b/config/env/development.js index c726d333..37b4d713 100644 --- a/config/env/development.js +++ b/config/env/development.js @@ -24,5 +24,10 @@ module.exports = { clientID: "APP_ID", clientSecret: "APP_SECRET", callbackURL: "http://localhost:3000/auth/google/callback" + }, + linkedin: { + clientID: "API_KEY", + clientSecret: "SECRET_KEY", + callbackURL: "http://localhost:3000/auth/linkedin/callback" } } \ No newline at end of file diff --git a/config/env/production.js b/config/env/production.js index d37a2787..71c73a4f 100644 --- a/config/env/production.js +++ b/config/env/production.js @@ -24,5 +24,10 @@ module.exports = { clientID: "APP_ID", clientSecret: "APP_SECRET", callbackURL: "http://localhost:3000/auth/google/callback" + }, + linkedin: { + clientID: "API_KEY", + clientSecret: "SECRET_KEY", + callbackURL: "http://localhost:3000/auth/linkedin/callback" } } \ No newline at end of file diff --git a/config/passport.js b/config/passport.js index 9814221b..ca873d0f 100755 --- a/config/passport.js +++ b/config/passport.js @@ -6,6 +6,7 @@ var mongoose = require('mongoose'), FacebookStrategy = require('passport-facebook').Strategy, GitHubStrategy = require('passport-github').Strategy, GoogleStrategy = require('passport-google-oauth').OAuth2Strategy, + LinkedinStrategy = require('passport-linkedin').Strategy, User = mongoose.model('User'), config = require('./config'); @@ -174,4 +175,33 @@ module.exports = function(passport) { }); } )); + + // 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({ + 'linkedin.id': profile.id + }, function (err, user) { + if (!user) { + user = new User({ + name: profile.displayName, + email: profile.emails[0].value, + username: profile.emails[0].value, + provider: 'linkedin' + }); + user.save(function (err) { + if (err) console.log(err); + return done(err, user); + }); + } else { + return done(err, user) + } + }); + } + )); }; \ No newline at end of file diff --git a/public/img/icons/linkedin.png b/public/img/icons/linkedin.png new file mode 100644 index 00000000..bbc9f1ab Binary files /dev/null and b/public/img/icons/linkedin.png differ