Github.getAccessToken()

Generate a new access token for acting on behalf of a particular GitHub user account.

Note that you must first have a valid `code` from the user proving that they're OK with this. You can get a code by redirecting the user to the url generated by calling the `getLoginUrl(...)` machine.

Usage

Hover over inputs/exits for more info.

var Github = require('machinepack-github');


// Generate a new access token for acting on behalf of a particular GitHub user account.

Github.getAccessToken({

clientId: '215798311808508',

clientSecret: 'dsg4901g0123456',

code: 'AQDvCav5zRSafS795TckAerUV53xzgqRyrcfYX2i_PJFObCvACVRP-V7sfemiMPBh3TWypvagfZ6aoqfwKCNcBxg8XR_skdYUe5tsY9UzX9Z_8q4mRrqaLhwSh5OHj9ORmE4ocyd-neZtdceTZjlmEVeO38UH9QOe_md7h5hy2gMhOS6TL9IBk5Guxg3O6I0WmjpFNPoj6JzWIvG9cgj7RQqxMA2q_8EJxGPTqEbmTqOBqqCIOlvPEPCeIiy21VD9__tuzB0JvgqbVh-U_WW8mjwGBqsfxlNvjYwIxk4zBNAxuRJijkkn0TwyogFpZqIlkY',

callbackUrl: 'http://localhost:1337/user/github/login',

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// Triggered when the callbackUrl doesn't match the settings supplied in the configured app settings on GitHub.

redirectUriMismatch: function () {

 

},

// Triggered when the code sent with the request is invalid.

badVerificationCode: function () {

 

},

// Triggered when either the client id or client secret is incorrect.

incorrectClientCredentials: function () {

 

},

// OK.

success: function (result) {

 

},

});

Inputs

clientId required

The unique identifier for your GitHub app (i.e. this is the "Client ID" listed on your app's settings page)

'215798311808508'
clientSecret required

The developer "secret" for your GitHub app (i.e. this is the "Client ID" listed on your app's settings page)

'dsg4901g0123456'
code required

The OAuth `code` generated by GitHub and sent to the `callbackUrl` if the user chooses to grant your app the requested permissions

'AQDvCav5zRSafS795TckAerUV53xzgqRyrcfYX2i_PJFObCvACVRP-V7sfemiMPBh3TWypvagfZ6aoqfwKCNcBxg8XR_skdYUe5tsY9UzX9Z_8q4mRrqaLhwSh5OHj9ORmE4ocyd-neZtdceTZjlmEVeO38UH9QOe_md7h5hy2gMhOS6TL9IBk5Guxg3O6I0WmjpFNPoj6JzWIvG9cgj7RQqxMA2q_8EJxGPTqEbmTqOBqqCIOlvPEPCeIiy21VD9__tuzB0JvgqbVh-U_WW8mjwGBqsfxlNvjYwIxk4zBNAxuRJijkkn0TwyogFpZqIlkY'
callbackUrl required

The redirect URL that was used when generating the provided `code`

'http://localhost:1337/user/github/login'

Exits

error

An unexpected error occurred.

redirectUriMismatch

Triggered when the callbackUrl doesn't match the settings supplied in the configured app settings on GitHub.

badVerificationCode

Triggered when the code sent with the request is invalid.

incorrectClientCredentials

Triggered when either the client id or client secret is incorrect.

success

OK.

{ token: 'CA2Emk9XsJUIBAHB9sTF5rOdNmAXTDjiHxZaZC1GYtFZCcdYGVnLYZB7jZCvensIpGc22yEzN6CL6wtQ9LPVXTNkuP6eQoUQ0toEVPrmTTqDpj0POijBpsuZBnx7jrZCHaTw8leiZBn0R8u6gZAYZAuD77cA3tnDMYvHhrl42CnljROeC9maWoa5zbsT2TZBXdL9wEuGQDSxKqRPyajRw3P3HEK' }