Skip to content

Instantly share code, notes, and snippets.

@crtr0
Created November 9, 2017 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crtr0/12d207bfb5d9c2d296b7ce751170c838 to your computer and use it in GitHub Desktop.
Save crtr0/12d207bfb5d9c2d296b7ce751170c838 to your computer and use it in GitHub Desktop.
GH OAuth callback in StdLib
/**
* 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);
});
};
@mikeal
Copy link

mikeal commented Nov 9, 2017

could just .catch(callback) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment