Created
May 16, 2017 21:33
-
-
Save orels1/3495352b88bd60299181e3252db15f76 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
router.get('/callback', catchAsync(async (req, res) => { | |
if (!req.query.code) throw new Error('NoCodeProvided'); | |
const code = req.query.code; | |
const creds = btoa(`${CLIENT_ID}:${CLIENT_SECRET}`); | |
const response = await fetch(`https://discordapp.com/api/oauth2/token?grant_type=authorization_code&code=${code}&redirect_uri=${redirect}`, | |
{ | |
method: 'POST', | |
headers: { | |
Authorization: `Basic ${creds}`, | |
}, | |
}); | |
const json = await response.json(); | |
res.redirect(`/?token=${json.access_token}`); | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment