diff --git a/README.md b/README.md index 38fd158e..550442c7 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,9 @@ npm install passport-linkedin-oauth2 ## Usage -Register the strategy +### Register the strategy +### 1. Example for "Share on LinkedIn" ```javascript var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy; @@ -33,6 +34,32 @@ passport.use( ); ``` +### 2. Exmample for "Community Management API" +```javascript +var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy; + +passport.use( + new LinkedInStrategy( + { + clientID: LINKEDIN_KEY, + clientSecret: LINKEDIN_SECRET, + callbackURL: 'http://127.0.0.1:3000/auth/linkedin/callback', + scope: ['r_basicprofile'], // 'profile', 'openid' scope will not work for "Community Management API" + }, + function (accessToken, refreshToken, profile, done) { + // asynchronous verification, for effect... + process.nextTick(function () { + // To keep the example simple, the user's LinkedIn profile is returned to + // represent the logged-in user. In a typical application, you would want + // to associate the LinkedIn account with a user record in your database, + // and return that user instead. + return done(null, profile); + }); + } + ) +); +``` + and then authenticate as: ```javascript diff --git a/lib/oauth2.js b/lib/oauth2.js index e34f1250..33f7e420 100644 --- a/lib/oauth2.js +++ b/lib/oauth2.js @@ -13,6 +13,10 @@ function Strategy(options, verify) { options.tokenURL || 'https://www.linkedin.com/oauth/v2/accessToken'; options.scope = options.scope || ['profile', 'email', 'openid']; + if (options.scope.includes('r_basicprofile')) { + profileUrl = 'https://api.linkedin.com/v2/me'; + } + //By default we want data in JSON options.customHeaders = options.customHeaders || { 'x-li-format': 'json' };