mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-03-04 11:11:05 +01:00
Add linkedin support for login
This commit is contained in:
@@ -23,7 +23,8 @@ var UserSchema = new Schema({
|
||||
facebook: {},
|
||||
twitter: {},
|
||||
github: {},
|
||||
google: {}
|
||||
google: {},
|
||||
linkedin: {}
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
5
config/env/development.js
vendored
5
config/env/development.js
vendored
@@ -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
config/env/production.js
vendored
5
config/env/production.js
vendored
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
});
|
||||
}
|
||||
));
|
||||
};
|
||||
BIN
public/img/icons/linkedin.png
Normal file
BIN
public/img/icons/linkedin.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.3 KiB |
Reference in New Issue
Block a user