Skip to content

Commit e656c5e

Browse files
committed
done linkedin auth
1 parent ea5b1ad commit e656c5e

13 files changed

Lines changed: 97 additions & 41 deletions

File tree

auth-All/app.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ const flash = require('connect-flash');
55
const cookieParser = require('cookie-parser');
66
const session = require('express-session');
77

8-
// Social config
8+
/*** Social config ***/
99
require('./config/googleConfig')(passport);
1010
require('./config/facebookConfig')(passport);
1111
require('./config/githubConfig')(passport);
12+
require('./config/linkedinConfig')(passport);
1213

14+
/*** Middleware ***/
1315
app.use(cookieParser()); // read cookies (needed for auth)
1416
app.set('view engine', 'ejs'); // set up ejs for templating
1517
app.use(express.static('public'));
@@ -18,7 +20,7 @@ app.use(passport.initialize());
1820
app.use(passport.session()); // persistent login sessions
1921
app.use(flash()); // use connect-flash for flash messages stored in session
2022

21-
// Router
23+
/*** Router ***/
2224
require('./routers/authRouter')(app, passport);
2325

2426
module.exports = app;

auth-All/config/facebookConfig.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const passport = require('passport');
2-
31
let FacebookStrategy = require('passport-facebook').Strategy;
42

53
module.exports = (passport) => {
@@ -13,19 +11,20 @@ module.exports = (passport) => {
1311
cb(null, user);
1412
});
1513

16-
// Goggle
14+
// Facebook
1715
passport.use(new FacebookStrategy(
1816
{
1917
clientID: process.env.FACEBOOK_CLIENT_ID,
2018
clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
21-
callbackURL: process.env.FACEBOOK_CALLBACK_URL
19+
callbackURL: process.env.FACEBOOK_CALLBACK_URL,
20+
profileFields: ['id', 'displayName', 'picture.type(large)', 'email']
2221
},
2322
function(token, refreshToken, profile, cb) {
2423
let user = {};
2524
process.nextTick(() => {
26-
user.name = profile._json.first_name;
25+
user.name = profile._json.name;
2726
user.email = profile._json.email;
28-
user.picture = profile._json.picture;
27+
user.picture = profile.photos[0].value;
2928
user.socialName = "Facebook";
3029
user.socialImg = "./img/facebook.png";
3130
return cb(null, user);

auth-All/config/githubConfig.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
const passport = require('passport');
2-
3-
let GithubStrategy = require('passport-github').Strategy;
1+
let GithubStrategy = require('passport-github2').Strategy;
42

53
module.exports = (passport) => {
64
// used to serialize the user for the session
@@ -13,18 +11,19 @@ module.exports = (passport) => {
1311
cb(null, user);
1412
});
1513

16-
// Goggle
14+
// Github
1715
passport.use(new GithubStrategy(
1816
{
1917
clientID: process.env.GITHUB_CLIENT_ID,
2018
clientSecret: process.env.GITHUB_CLIENT_SECRET,
21-
callbackURL: process.env.GITHUB_CALLBACK_URL
19+
callbackURL: process.env.GITHUB_CALLBACK_URL,
20+
scope: ['user:email']
2221
},
2322
function(token, refreshToken, profile, cb) {
2423
let user = {};
2524
process.nextTick(() => {
2625
user.name = profile._json.name;
27-
user.email = profile._json.email;
26+
user.email = profile.emails[0].value;
2827
user.picture = profile._json.avatar_url;
2928
user.socialName = "Github";
3029
user.socialImg = "./img/github.png";

auth-All/config/googleConfig.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const passport = require('passport');
2-
31
let GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
42

53
module.exports = (passport) => {

auth-All/config/linkedinConfig.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
let LinkedinStrategy = require('passport-linkedin-oauth2').Strategy;
2+
3+
module.exports = (passport) => {
4+
// used to serialize the user for the session
5+
passport.serializeUser((user, cb) => {
6+
cb(null, user);
7+
});
8+
9+
// used to deserialize the user
10+
passport.deserializeUser((user, cb) => {
11+
cb(null, user);
12+
});
13+
14+
// Linkedin
15+
passport.use(new LinkedinStrategy(
16+
{
17+
clientID: process.env.LINKEDIN_CLIENT_ID,
18+
clientSecret: process.env.LINKEDIN_CLIENT_SECRET,
19+
callbackURL: process.env.LINKEDIN_CALLBACK_URL,
20+
scope: ['r_emailaddress', 'r_liteprofile']
21+
},
22+
function(token, refreshToken, profile, cb) {
23+
let user = {};
24+
process.nextTick(() => {
25+
user.name = profile.displayName;
26+
user.email = profile.emails[0].value;
27+
user.picture = profile.photos[3].value;
28+
user.socialName = "Linkedin";
29+
user.socialImg = "./img/linkedin.jpg";
30+
return cb(null, user);
31+
});
32+
}
33+
));
34+
};

auth-All/config/myEnv.env

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ FACEBOOK_CALLBACK_URL=your-callback-url
1616

1717
GITHUB_CLIENT_ID=your-github-cliend-id
1818
GITHUB_CLIENT_SECRET=your-github-cliend-secret
19-
GITHUB_CALLBACK_URL=your-callback-url
19+
GITHUB_CALLBACK_URL=your-callback-url
20+
21+
LINKEDIN_CLIENT_ID=your-linkedin-cliend-id
22+
LINKEDIN_CLIENT_SECRET=your-linkedin-cliend-secret
23+
LINKEDIN_CALLBACK_URL=your-callback-url

auth-All/package-lock.json

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth-All/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"mongoose": "^5.9.24",
2727
"passport": "^0.4.1",
2828
"passport-facebook": "^3.0.0",
29-
"passport-github": "^1.1.0",
30-
"passport-google-oauth": "^2.0.0"
29+
"passport-github2": "^0.1.12",
30+
"passport-google-oauth": "^2.0.0",
31+
"passport-linkedin-oauth2": "^2.0.0"
3132
}
3233
}

auth-All/public/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.customContainer {
2-
margin: 2rem;
2+
margin: 3rem;
33
}
44

55
.logoDesign {

auth-All/public/img/favicon.ico

1.12 KB
Binary file not shown.

0 commit comments

Comments
 (0)