Skip to content
Open
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
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ A simple [Passport](http://passportjs.org/) strategy for LinkedIn OAuth2.

## Install

npm install passport-linkedin-oauth2
```sh
npm install passport-linkedin-oauth2
```

## Usage

Register the strategy

~~~javascript
```javascript
var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;

passport.use(new LinkedInStrategy({
Expand All @@ -26,35 +28,35 @@ passport.use(new LinkedInStrategy({
return done(null, profile);
});
}));
~~~
```

and then authenticate as:

~~~javascript
```javascript
app.get('/auth/linkedin',
passport.authenticate('linkedin', { state: 'SOME STATE' }),
function(req, res){
// The request will be redirected to LinkedIn for authentication, so this
// function will not be called.
});
~~~
```

the login callback:

~~~javascript
```javascript
app.get('/auth/linkedin/callback', passport.authenticate('linkedin', {
successRedirect: '/',
failureRedirect: '/login'
}));
~~~
```

See [this](http://developer.linkedin.com/) for details on LinkedIn API.

## Auto-handle `state` param

The `state` param is used to prevent CSRF attacks, and is [required by the LinkedIn API](https://developer.linkedin.com/documents/authentication). You can ask Passport to handle the sending and validating of the `state` parameter by passing `state: true` as an option to the strategy:

~~~javascript
```javascript
var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;

passport.use(new LinkedInStrategy({
Expand All @@ -73,7 +75,7 @@ passport.use(new LinkedInStrategy({
return done(null, profile);
});
}));
~~~
```

and then authenticate as:

Expand Down