authenticate(endpoint) {
    let authPromise;

    // If we are application only, or are bypassing authentication
    // therefore we're using application only OAuth
    if (this._userConfig.useBrowserCookies) {
      if (endpoint.method === 'post') {
        authPromise = this._modhash.getModhash();
      } else {
        authPromise = when.resolve();
      }
    }
    else if (this.isApplicationOnly() || endpoint.contextOptions.bypassAuth) {
      authPromise = this._oauthAppOnly.applicationOnlyAuth();
    }
    else if (this._oauth.canRefreshAccessToken()) {
      // If we have been authenticated with a permanent refresh token use it
      if (this._oauth.hasRefreshToken()) {
        authPromise = this._oauth.refresh();
      }
      // If we are OAuth type script we can call `.auth` again
      else if (this._userConfig.isOAuthType('script')) {
        authPromise = this._oauth.auth();
      }
    }
    // No way to authenticate
    else {
      return when.reject(new Error('Unable to authenticate'));
    }

    return authPromise;
  }
/*
     Authenticate with the appropriate OAuth type for a given
     endpoint
   */
Authenticate with the appropriate OAuth type for a given
endpoint
Authenticate with the appropriate OAuth type for a given endpoint
authenticate(endpoint) {
    let authPromise;
    if (this._userConfig.useBrowserCookies) {
      if (endpoint.method === 'post') {
        authPromise = this._modhash.getModhash();
      } else {
        authPromise = when.resolve();
      }
    }
    else if (this.isApplicationOnly() || endpoint.contextOptions.bypassAuth) {
      authPromise = this._oauthAppOnly.applicationOnlyAuth();
    }
    else if (this._oauth.canRefreshAccessToken()) {
      if (this._oauth.hasRefreshToken()) {
        authPromise = this._oauth.refresh();
      }
      else if (this._userConfig.isOAuthType('script')) {
        authPromise = this._oauth.auth();
      }
    }
    else {
      return when.reject(new Error('Unable to authenticate'));
    }
    return authPromise;
  }
authenticate ( endpoint ) { let authPromise ; if ( this . _userConfig . useBrowserCookies ) { if ( endpoint . method === 'post' ) { authPromise = this . _modhash . getModhash ( ) ; } else { authPromise = when . resolve ( ) ; } } else if ( this . isApplicationOnly ( ) || endpoint . contextOptions . bypassAuth ) { authPromise = this . _oauthAppOnly . applicationOnlyAuth ( ) ; } else if ( this . _oauth . canRefreshAccessToken ( ) ) { if ( this . _oauth . hasRefreshToken ( ) ) { authPromise = this . _oauth . refresh ( ) ; } else if ( this . _userConfig . isOAuthType ( 'script' ) ) { authPromise = this . _oauth . auth ( ) ; } } else { return when . reject ( new Error ( 'Unable to authenticate' ) ) ; } return authPromise ; }
Authenticate with the appropriate OAuth type for a given
endpoint
Authenticate with the appropriate OAuth type for a given endpoint
// If we are application only, or are bypassing authentication // therefore we're using application only OAuth // If we have been authenticated with a permanent refresh token use it // If we are OAuth type script we can call `.auth` again // No way to authenticate