Skip to content

Commit

Permalink
Added express example.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreareginato committed May 16, 2013
1 parent d8876bd commit 3744491
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,59 @@ Install the client library using git:

## Getting started

### Express and Github example

```javascript
var express = require('express'),
app = express();

var OAuth2 = require('simple-oauth2')({
clientID: CLIENT_ID,
clientSecret: CLIENT_SECRET,
site: 'https://github.com/login',
tokenPath: '/oauth/access_token'
});


// Authorization uri definition
var authorization_uri = OAuth2.AuthCode.authorizeURL({
redirect_uri: 'http://localhost:3000/callback',
scope: 'notifications',
state: '3(#0/!~'
});

// Initial page redirecting to Github
app.get('/auth', function (req, res) {
res.redirect(authorization_uri);
});

// Callback service parsing the authorization token and asking for the access token
app.get('/callback', function (req, res) {
var code = req.query.code;
console.log('/callback');
OAuth2.AuthCode.getToken({
code: code,
redirect_uri: 'http://localhost:3000/callback'
}, saveToken);

function saveToken(error, result) {
if (error) { console.log('Access Token Error', error.message); }
token = OAuth2.AccessToken.create(result);
}
});


app.get('/', function (req, res) {
res.send('Hello World');
});

app.listen(3000);

console.log('Express server started on port 3000');
```

Credits to [@lazybean](https://github.com/lazybean)

### Authorization Code flow

The Authorization Code flow is made up from two parts. At first your application asks to
Expand Down

0 comments on commit 3744491

Please sign in to comment.