Skip to content

Commit

Permalink
Remove state mentions from README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Slotos committed Jul 17, 2022
1 parent 63468d9 commit eca2173
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,24 @@ application:

```javascript
app.get('/auth/reddit', function(req, res, next){
req.session.state = crypto.randomBytes(32).toString('hex');
passport.authenticate('reddit', {
state: req.session.state,
duration: 'permanent',
})(req, res, next);
});

app.get('/auth/reddit/callback', function(req, res, next){
// Check for origin via state token
if (req.query.state == req.session.state){
passport.authenticate('reddit', {
successRedirect: '/',
failureRedirect: '/login'
})(req, res, next);
}
else {
next( new Error(403) );
}
passport.authenticate('reddit', {
successRedirect: '/',
failureRedirect: '/login'
})(req, res, next);
});
```

##### `state` option use
Reddit requires state, otherwise erring out.
I've decided to opt out of providing default state, since it kills the whole purpose of the flag.
If you don't want to use it, provide any string and don't check for it on user return.
##### `duration` option on authenticate call

This strategy supports`duration` option on authenticate call, to request an indefinite authorization as opposed to 1 hour default.
Possible values: `permanent` and `temporary` (1 hour).

Also included is the optional `duration` parameter, to request a slightly longer authorization.
Defaults to `temporary` (1 hour).
Defined in the official [Reddit OAuth spec](https://github.com/reddit/reddit/wiki/OAuth2#authorization-parameters)

## Examples
Expand Down

0 comments on commit eca2173

Please sign in to comment.