From 58d2cbf70653a7bc6c8b8a9781ccd2646d8ca6e0 Mon Sep 17 00:00:00 2001 From: Harshad Kale Date: Sat, 25 Jan 2014 12:03:26 -0600 Subject: [PATCH] Add linkedin support for login --- app/models/user.js | 3 ++- app/routes/users.js | 10 ++++++++++ app/views/users/auth.jade | 2 ++ config/env/development.js | 5 +++++ config/env/production.js | 5 +++++ config/passport.js | 30 ++++++++++++++++++++++++++++++ public/img/icons/linkedin.png | Bin 0 -> 7505 bytes 7 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 public/img/icons/linkedin.png diff --git a/app/models/user.js b/app/models/user.js index d3bfcbc6e3..e24b0b11e5 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 02793d5b4d..e254d15875 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 a1f8c2cf45..fadb270dd1 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 c726d33355..37b4d7132a 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 d37a2787c8..71c73a4f54 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 9814221b3c..ca873d0fac 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 0000000000000000000000000000000000000000..bbc9f1abaa45bd696e83d3e0e73f002f0574dc1e GIT binary patch literal 7505 zcmV-X9j@YuP)|J}TWmS3qzJ2ao=FT$?l!q4(hRRDGro;zRwXFq9qXlZx#A@2cR7o36|7lE9 zt4-6F*wi$w+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