Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Add linkedin support for login
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshad Kale committed Jan 25, 2014
1 parent d59bf86 commit 58d2cbf
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ var UserSchema = new Schema({
facebook: {},
twitter: {},
github: {},
google: {}
google: {},
linkedin: {}
});

/**
Expand Down
10 changes: 10 additions & 0 deletions app/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

};
2 changes: 2 additions & 0 deletions app/views/users/auth.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 5 additions & 0 deletions config/env/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
30 changes: 30 additions & 0 deletions config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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)
}
});
}
));
};
Binary file added public/img/icons/linkedin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 58d2cbf

Please sign in to comment.