Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' };

Expand Down