Skip to content

Commit

Permalink
Merge pull request #69 from sebadoom/ulp-502-linkedin-api-v2
Browse files Browse the repository at this point in the history
ULP-502: LinkedIn API v2 (based on #63)
  • Loading branch information
sebadoom committed May 29, 2019
2 parents 3e11237 + ab8b05e commit e311f79
Show file tree
Hide file tree
Showing 9 changed files with 1,795 additions and 519 deletions.
8 changes: 4 additions & 4 deletions README.md
@@ -1,4 +1,4 @@
A simple [Passport](http://passportjs.org/) strategy for LinkedIn OAuth2.
A simple [Passport](http://passportjs.org/) strategy for LinkedIn OAuth2 that works with lite profile.

## Install

Expand All @@ -15,7 +15,7 @@ passport.use(new LinkedInStrategy({
clientID: LINKEDIN_KEY,
clientSecret: LINKEDIN_SECRET,
callbackURL: "http://127.0.0.1:3000/auth/linkedin/callback",
scope: ['r_emailaddress', 'r_basicprofile'],
scope: ['r_emailaddress', 'r_liteprofile'],
}, function(accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
Expand Down Expand Up @@ -48,7 +48,7 @@ app.get('/auth/linkedin/callback', passport.authenticate('linkedin', {
}));
~~~

See [this](http://developer.linkedin.com/) for details on LinkedIn API.
See [this](https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin?context=linkedin/consumer/context?trk=eml_mktg_gco_dev_api_comms) for details on LinkedIn API.

## Auto-handle `state` param

Expand All @@ -61,7 +61,7 @@ passport.use(new LinkedInStrategy({
clientID: LINKEDIN_KEY,
clientSecret: LINKEDIN_SECRET,
callbackURL: "http://127.0.0.1:3000/auth/linkedin/callback",
scope: ['r_emailaddress', 'r_basicprofile'],
scope: ['r_emailaddress', 'r_liteprofile'],
state: true
}, function(accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
Expand Down
39 changes: 19 additions & 20 deletions example/server.js
Expand Up @@ -4,8 +4,9 @@ var express = require('express')

// API Access link for creating client ID and secret:
// https://www.linkedin.com/secure/developer
var LINKEDIN_CLIENT_ID = "50p3e3wo29te";
var LINKEDIN_CLIENT_SECRET = "CUFBLLzfpU24oQ3B";
var LINKEDIN_CLIENT_ID = process.env.LINKEDIN_CLIENT_ID;
var LINKEDIN_CLIENT_SECRET = process.env.LINKEDIN_CLIENT_SECRET;
var CALLBACK_URL = process.env.CALLBACK_URL || 'http://localhost:3000/auth/linkedin/callback';


// Passport session setup.
Expand All @@ -31,8 +32,8 @@ passport.deserializeUser(function(obj, done) {
passport.use(new LinkedinStrategy({
clientID: LINKEDIN_CLIENT_ID,
clientSecret: LINKEDIN_CLIENT_SECRET,
callbackURL: "http://localhost:3000/auth/linkedin/callback",
scope: [ 'r_basicprofile', 'r_emailaddress'],
callbackURL: CALLBACK_URL,
scope: ['r_liteprofile', 'r_emailaddress'],
passReqToCallback: true
},
function(req, accessToken, refreshToken, profile, done) {
Expand All @@ -54,21 +55,19 @@ passport.use(new LinkedinStrategy({
var app = express();

// configure Express
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.logger());
app.use(express.cookieParser());
app.use(express.urlencoded());
app.use(express.json());
app.use(express.session({ secret: 'keyboard cat' }));
// Initialize Passport! Also use passport.session() middleware, to support
// persistent login sessions (recommended).
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.logger());
app.use(express.cookieParser());
app.use(express.urlencoded());
app.use(express.json());
app.use(express.session({ secret: 'keyboard cat' }));
// Initialize Passport! Also use passport.session() middleware, to support
// persistent login sessions (recommended).
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(express.static(__dirname + '/public'));


app.get('/', function(req, res){
Expand Down Expand Up @@ -120,4 +119,4 @@ http.createServer(app).listen(3000);
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) { return next(); }
res.redirect('/login');
}
}

0 comments on commit e311f79

Please sign in to comment.