Skip to content

Commit d9de2de

Browse files
committed
Scale to linkedin
1 parent 491c4ed commit d9de2de

File tree

7 files changed

+40
-0
lines changed

7 files changed

+40
-0
lines changed

configs/project/server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if (process.env.TRAVIS) {
1616
firebase: require('./firebase/credential.json'),
1717
passportStrategy: {
1818
facebook: require('./passportStrategy/facebook/credential'),
19+
linkedin: require('./passportStrategy/linkedin/credential'),
1920
},
2021
};
2122
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"passport": "^0.3.2",
110110
"passport-facebook": "^2.1.1",
111111
"passport-jwt": "^2.0.0",
112+
"passport-linkedin-oauth2": "^1.4.1",
112113
"pm2": "^2.0.18",
113114
"react": "^15.3.2",
114115
"react-bootstrap": "^0.30.5",

src/common/components/pages/user/LoginPage.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const LoginPage = (props) => (
2727
>
2828
<span className="fa fa-facebook"></span>Login with Facebook
2929
</a>
30+
<a
31+
href="/auth/linkedin"
32+
className="btn btn-block btn-social btn-linkedin"
33+
>
34+
<span className="fa fa-linkedin"></span>Login with LinkedIn
35+
</a>
3036
</Col>
3137
</Row>
3238
</Grid>

src/server/controllers/socialAuth.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ export default {
44
initFacebook: passport.authenticate('facebook', {
55
scope: ['public_profile', 'email'],
66
}),
7+
initLinkedin: passport.authenticate('linkedin', {
8+
state: Math.random(),
9+
}),
710
};

src/server/middlewares/passportInit.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import passport from 'passport';
22
import { Strategy as JwtStrategy } from 'passport-jwt';
33
import { Strategy as FacebookStrategy } from 'passport-facebook';
4+
import { Strategy as OAuthLinkedinStrategy } from 'passport-linkedin-oauth2';
45
import configs from '../../../configs/project/server';
56
import User from '../models/User';
67

@@ -61,5 +62,24 @@ if (configs.passportStrategy.facebook) {
6162
}));
6263
}
6364

65+
if (configs.passportStrategy.linkedin) {
66+
passport.use(new OAuthLinkedinStrategy({
67+
...configs.passportStrategy.linkedin.default,
68+
...configs.passportStrategy.linkedin[process.env.NODE_ENV],
69+
}, (req, accessToken, refreshToken, profile, done) => {
70+
findOrCreateUser('linkedin', profile._json.emailAddress, (err, user) => {
71+
if (err) {
72+
return done(err);
73+
}
74+
// map `linkedin-specific` profile fields to our custom profile fields
75+
user.social.profile.linkedin = profile._json;
76+
user.email.value = user.email.value || profile._json.emailAddress;
77+
user.name = user.name || profile._json.formattedName;
78+
user.avatarURL = user.avatarURL || profile._json.pictureUrl;
79+
done(null, user);
80+
});
81+
}));
82+
}
83+
6484
const passportInitMiddleware = passport.initialize();
6585
export default passportInitMiddleware;

src/server/models/User.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ let UserSchema = new mongoose.Schema({
4444
social: {
4545
profile: {
4646
facebook: Object,
47+
linkedin: Object,
4748
},
4849
},
4950
}, {

src/server/routes/socialAuth.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ export default ({ app }) => {
1212
userController.socialLogin
1313
);
1414
}
15+
// linkedin
16+
if (configs.passportStrategy.linkedin) {
17+
app.get('/auth/linkedin', socialAuthController.initLinkedin);
18+
app.get('/auth/linkedin/callback',
19+
passportAuth('linkedin'),
20+
userController.socialLogin
21+
);
22+
}
1523
};

0 commit comments

Comments
 (0)