linkedin api nodejs tutorial

Solutions on MaxInterview for linkedin api nodejs tutorial by the best coders in the world

showing results for - "linkedin api nodejs tutorial"
Athénaïs
01 May 2017
1// paspport dependencies
2
3var passport = require('passport');
4var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;
5
6// linkedin app settings
7var LINKEDIN_CLIENT_ID = "CLIENT_ID_HERE";
8var LINKEDIN_CLIENT_SECRET = "CLIENT_SECRET_HERE";
9var Linkedin = require('node-linkedin')(LINKEDIN_CLIENT_ID, LINKEDIN_CLIENT_SECRET);
10
11passport.serializeUser(function (user, done) {
12    done(null, user);
13});
14
15passport.deserializeUser(function (obj, done) {
16    done(null, obj);
17});
18
19passport.use(new LinkedInStrategy({
20    clientID: LINKEDIN_CLIENT_ID,
21    clientSecret: LINKEDIN_CLIENT_SECRET,
22    callbackURL: "http://127.0.0.1:3000/auth/linkedin/callback",
23    scope: ['r_emailaddress', 'r_basicprofile', 'rw_company_admin'],
24    passReqToCallback: true
25},
26function (req, accessToken, refreshToken, profile, done) {
27	req.session.accessToken = accessToken;
28    process.nextTick(function () {
29        return done(null, profile);
30	});
31}));
32
33// for auth
34
35app.get('/auth/linkedin',
36  passport.authenticate('linkedin', { state: 'SOME STATE'  }),
37  function(req, res){
38    // The request will be redirected to LinkedIn for authentication, so this
39    // function will not be called.
40});
41
42// for callback
43
44app.get('/auth/linkedin/callback', passport.authenticate('linkedin', { failureRedirect: '/' }),
45function (req, res) {
46    res.redirect('/');
47});
48