-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad49bf5
commit 33c302d
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const router = require('express').Router(); | ||
const axios = require('axios'); | ||
|
||
const CLIENT_ID = process.env.GITHUB_ID; | ||
const CLIENT_SECRET = process.env.GITHUB_SECRET; | ||
|
||
router.get('/github', async (req, res) => { | ||
const code = req.query.code; | ||
await axios({ | ||
method: 'post', | ||
url: `https://github.com/login/oauth/access_token?client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&code=${code}`, | ||
headers: { accept: 'application/json' } | ||
}) | ||
.then(async result => { | ||
const token = result.data.access_token; | ||
if(token){ | ||
await axios({ | ||
method: 'get', | ||
url: `https://api.github.com/user`, | ||
headers: { | ||
Authorization: 'token ' + token | ||
} | ||
}) | ||
.then(user => { res.json(user.data) }) | ||
.catch(err => console.log(err)) | ||
}else res.json('Error in Registering via GitHub'); | ||
}) | ||
.catch(err => console.log(err)) | ||
}) | ||
|
||
module.exports = router; |