Created
November 9, 2017 21:46
-
-
Save crtr0/12d207bfb5d9c2d296b7ce751170c838 to your computer and use it in GitHub Desktop.
GH OAuth callback in StdLib
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
/** | |
* Function to handle a Github OAuth callback | |
* https://developer.github.com/apps/building-integrations/setting-up-and-registering-oauth-apps/about-scopes-for-oauth-apps/ | |
* @param {string} code Required. The code you received as a response to Step 1. | |
* @param {string} state The unguessable random string you provided in Step 1. | |
* @returns {string} | |
*/ | |
module.exports = (code, state, context, callback) => { | |
const axios = require('axios') | |
axios.post('https://github.com/login/oauth/access_token', { | |
client_id: 'foo', | |
client_secret: 'bar', | |
code: code | |
}) | |
.then(function (response) { | |
callback(null, response.data); | |
}) | |
.catch(function (error) { | |
callback(error); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
could just
.catch(callback)
:)