B2G/gecko/services/aitc/modules/manager.js
/* Obtain a (new) token from the Sagrada token server. If win is is specified,
   * the user will be asked to login via UI, if required. The callback's
   * signature is cb(err, done). If a token is obtained successfully, done will
   * be true and err will be null.
   */
Obtain a (new) token from the Sagrada token server. If win is is specified,
the user will be asked to login via UI, if required. The callback's
signature is cb(err, done). If a token is obtained successfully, done will
be true and err will be null.
Obtain a ( new ) token from the Sagrada token server . If win is is specified the user will be asked to login via UI if required . The callback ' s signature is cb ( err done ) . If a token is obtained successfully done will be true and err will be null .
function _refreshToken(cb, win) {
    if (!this._client) {
      throw new Error("_refreshToken called without an active client");
    }
    this._log.info("Token refresh requested");
    let self = this;
    function refreshedAssertion(err, assertion) {
      if (!err) {
        self._getToken(assertion, function(err, token) {
          if (err) {
            cb(err, null);
            return;
          }
          self._lastTokenTime = Date.now();
          self._client.updateToken(token);
          self._invalidTokenFlag = false;
          cb(null, true);
        });
        return;
      }
      if (!win) {
        cb(err, null);
        return;
      }
      self._makeClient(function(err, client) {
        if (err) {
          cb(err, null);
          return;
        }
        self._client = client;
        self._invalidTokenFlag = false;
        cb(null, true);
      }, win);
    }
    let options = { audience: DASHBOARD_URL };
    if (this._lastEmail) {
      options.requiredEmail = this._lastEmail;
    } else {
      options.sameEmailAs = MARKETPLACE_URL;
    }
    if (this._premadeToken) {
      this._client.updateToken(this._premadeToken);
      this._tokenDuration = parseInt(this._premadeToken.duration, 10);
      this._lastTokenTime = Date.now();
      this._invalidTokenFlag = false;
      cb(null, true);
    } else {
      BrowserID.getAssertion(refreshedAssertion, options);
    }
  }
function _refreshToken ( cb , win ) { if ( ! this . _client ) { throw new Error ( "_refreshToken called without an active client" ) ; } this . _log . info ( "Token refresh requested" ) ; let self = this ; function refreshedAssertion ( err , assertion ) { if ( ! err ) { self . _getToken ( assertion , function ( err , token ) { if ( err ) { cb ( err , null ) ; return ; } self . _lastTokenTime = Date . now ( ) ; self . _client . updateToken ( token ) ; self . _invalidTokenFlag = false ; cb ( null , true ) ; } ) ; return ; } if ( ! win ) { cb ( err , null ) ; return ; } self . _makeClient ( function ( err , client ) { if ( err ) { cb ( err , null ) ; return ; } self . _client = client ; self . _invalidTokenFlag = false ; cb ( null , true ) ; } , win ) ; } let options = { audience : DASHBOARD_URL } ; if ( this . _lastEmail ) { options . requiredEmail = this . _lastEmail ; } else { options . sameEmailAs = MARKETPLACE_URL ; } if ( this . _premadeToken ) { this . _client . updateToken ( this . _premadeToken ) ; this . _tokenDuration = parseInt ( this . _premadeToken . duration , 10 ) ; this . _lastTokenTime = Date . now ( ) ; this . _invalidTokenFlag = false ; cb ( null , true ) ; } else { BrowserID . getAssertion ( refreshedAssertion , options ) ; } }
Obtain a (new) token from the Sagrada token server.
Obtain a ( new ) token from the Sagrada token server .
// Silent refresh was asked for. // Prompt user to login. // makeClient sets an updated token.