lib/githubAuthentication.js
function authorizeApp(user, tokenName, scope) {
  return new Promise((resolve, reject) => {
    request.post('https://api.github.com/authorizations', {
      auth: {
        user: user.username,
        pass: user.password,
        sendImmediately: true
      },
      headers: {
        'content-type': 'application/x-www-form-urlencoded',
        'User-Agent': tokenName
      },
      body: JSON.stringify({
        scopes: scope,
        note: tokenName
      })
    }, (err, response, body) => {
      if (err) {
        reject(err);
      }
      const returnBody = JSON.parse(body);
      if (returnBody.token) {
        resolve(returnBody.token);
      }
      else if (returnBody.errors) {
        console.log(returnBody.errors);
        reject(returnBody.errors);
      }
    });
  });
}
function authorizeApp(user, tokenName, scope) {
  return new Promise((resolve, reject) => {
    request.post('https://api.github.com/authorizations', {
      auth: {
        user: user.username,
        pass: user.password,
        sendImmediately: true
      },
      headers: {
        'content-type': 'application/x-www-form-urlencoded',
        'User-Agent': tokenName
      },
      body: JSON.stringify({
        scopes: scope,
        note: tokenName
      })
    }, (err, response, body) => {
      if (err) {
        reject(err);
      }
      const returnBody = JSON.parse(body);
      if (returnBody.token) {
        resolve(returnBody.token);
      }
      else if (returnBody.errors) {
        console.log(returnBody.errors);
        reject(returnBody.errors);
      }
    });
  });
}
function authorizeApp ( user , tokenName , scope ) { return new Promise ( ( resolve , reject ) => { request . post ( 'https://api.github.com/authorizations' , { auth : { user : user . username , pass : user . password , sendImmediately : true } , headers : { 'content-type' : 'application/x-www-form-urlencoded' , 'User-Agent' : tokenName } , body : JSON . stringify ( { scopes : scope , note : tokenName } ) } , ( err , response , body ) => { if ( err ) { reject ( err ) ; } const returnBody = JSON . parse ( body ) ; if ( returnBody . token ) { resolve ( returnBody . token ) ; } else if ( returnBody . errors ) { console . log ( returnBody . errors ) ; reject ( returnBody . errors ) ; } } ) ; } ) ; }
Attempt to create a new Personal Access Token with the Github API.
@param  {Object} user      Object containing the username and password
@param  {String} tokenName Name of the token to be created_at
@param  {Array} scope      List of priviledges to allow the token (See
https://developer.github.com/v3/oauth/#scopes)
@return {Promise}          Resolves to a 40-char token string
Attempt to create a new Personal Access Token with the Github API .