Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
manjufy committed Sep 27, 2018
2 parents 4639d0b + 0fab196 commit 175c61a
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 4 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,24 @@ Make sure to install nodemon locally in global mode

and

`npm run dev` to start
`npm run dev` to start


### Github OAuth flow explained

https://github.com/octokit/octokit.net/blob/master/docs/oauth-flow.md

### TODO

Implement a package to consume Github auth code and return access token

### Errors

```
{
"message": "Bad credentials",
"documentation_url": "https://developer.github.com/v3"
}
```

Make sure to include `Authorization: Bearer <accessToken>` In your header
124 changes: 124 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"homepage": "https://github.com/manjufy/nodejs-github-auth#readme",
"dependencies": {
"@octokit/rest": "^15.10.0",
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
Expand Down
17 changes: 14 additions & 3 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const cors = require('cors')
const bodyParser = require('body-parser')
const express = require('express')
const axios = require('axios')
const app = express()
const axios = require('axios')
const bodyParser = require('body-parser')
const cors = require('cors')
const jwt = require('express-jwt')
const jwks = require('jwks-rsa')
const queryStr = require('querystring')
const util = require('util')

const octokit = require('@octokit/rest')
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors());
Expand All @@ -16,6 +21,7 @@ app.get('/', (req, res) => {

app.get('/auth', async (req, res) => {
const code = req.query.code

// Make a post request to Github
const response = await axios.post('https://github.com/login/oauth/access_token', {
client_id: '13713e448956673736bb',
Expand All @@ -28,9 +34,14 @@ app.get('/auth', async (req, res) => {
'crossDomain': true
}
})


// Response is in the form of access_token=50d935da34d5bf48d0560e30d1f052ee56d030bc&scope=user%3Aemail&token_type=bearer
const token = response.data

res.send(token)
res.json(
queryStr.parse(token)
)
})

app.listen(3333)
Expand Down

0 comments on commit 175c61a

Please sign in to comment.