scripts/authorize.js
/**
   * Finish
   *
   * @param token The OAuth2 token given to the application from the provider.
   */
Finish
@param token The OAuth2 token given to the application from the provider.
Finish @param token The OAuth2 token given to the application from the provider .
finish(token) {
    const AUTHENTICATION_URL = 'https://api.github.com/user';
    const xhr = new XMLHttpRequest();
    xhr.addEventListener('readystatechange', function () {
      if (xhr.readyState === 4) {
        if (xhr.status === 200) {
          const username = JSON.parse(xhr.responseText).login;
          chrome.runtime.sendMessage({
            closeWebPage: true,
            isSuccess: true,
            token,
            username,
            KEY: this.KEY,
          });
        }
      }
    });
    xhr.open('GET', AUTHENTICATION_URL, true);
    xhr.setRequestHeader('Authorization', `token ${token}`);
    xhr.send();
  }
finish ( token ) { const AUTHENTICATION_URL = 'https://api.github.com/user' ; const xhr = new XMLHttpRequest ( ) ; xhr . addEventListener ( 'readystatechange' , function ( ) { if ( xhr . readyState === 4 ) { if ( xhr . status === 200 ) { const username = JSON . parse ( xhr . responseText ) . login ; chrome . runtime . sendMessage ( { closeWebPage : true , isSuccess : true , token , username , KEY : this . KEY , } ) ; } } } ) ; xhr . open ( 'GET' , AUTHENTICATION_URL , true ) ; xhr . setRequestHeader ( 'Authorization' , ` ${ token } ` ) ; xhr . send ( ) ; }
Finish
 @param token The OAuth2 token given to the application from the provider.
Finish @param token The OAuth2 token given to the application from the provider .
/* Get username */ // To validate user, load user object from GitHub.