B2G/gecko/services/aitc/modules/manager.js
/* To start the AitcClient we need a token, for which we need a BrowserID
   * assertion. If login is true, makeClient will ask the user to login in
   * the context of win. cb is called with (err, client).
   */
To start the AitcClient we need a token, for which we need a BrowserID
assertion. If login is true, makeClient will ask the user to login in
the context of win. cb is called with (err, client).
To start the AitcClient we need a token for which we need a BrowserID assertion . If login is true makeClient will ask the user to login in the context of win . cb is called with ( err client ) .
function makeClient(cb, login, win) {
    if (!cb) {
      throw new Error("makeClient called without callback");
    }
    if (login && !win) {
      throw new Error("makeClient called with login as true but no win");
    }
    let self = this;
    let ctxWin = win;
    function processAssertion(val) {
      self._lastEmail = self._extractEmail(val);
      self._log.info("Got assertion from BrowserID, creating token");
      self._getToken(val, function(err, token) {
        if (err) {
          cb(err, null);
          return;
        }
        self._lastTokenTime = Date.now();
        cb(null, new AitcClient(
          token, new Preferences("services.aitc.client.")
        ));
      });
    }
    function gotSilentAssertion(err, val) {
      self._log.info("gotSilentAssertion called");
      if (err) {
        if (login) {
          self._log.info("Could not obtain silent assertion, retrying login");
          BrowserID.getAssertionWithLogin(function gotAssertion(err, val) {
            if (err) {
              self._log.error(err);
              cb(err, false);
              return;
            }
            processAssertion(val);
          }, ctxWin);
          return;
        }
        self._log.warn("Could not obtain assertion in _makeClient");
        cb(err, false);
      } else {
        processAssertion(val);
      }
    }
    self._log.info("Attempting to obtain assertion silently")
    BrowserID.getAssertion(gotSilentAssertion, {
      audience: DASHBOARD_URL,
      sameEmailAs: MARKETPLACE_URL
    });
  }
function makeClient ( cb , login , win ) { if ( ! cb ) { throw new Error ( "makeClient called without callback" ) ; } if ( login && ! win ) { throw new Error ( "makeClient called with login as true but no win" ) ; } let self = this ; let ctxWin = win ; function processAssertion ( val ) { self . _lastEmail = self . _extractEmail ( val ) ; self . _log . info ( "Got assertion from BrowserID, creating token" ) ; self . _getToken ( val , function ( err , token ) { if ( err ) { cb ( err , null ) ; return ; } self . _lastTokenTime = Date . now ( ) ; cb ( null , new AitcClient ( token , new Preferences ( "services.aitc.client." ) ) ) ; } ) ; } function gotSilentAssertion ( err , val ) { self . _log . info ( "gotSilentAssertion called" ) ; if ( err ) { if ( login ) { self . _log . info ( "Could not obtain silent assertion, retrying login" ) ; BrowserID . getAssertionWithLogin ( function gotAssertion ( err , val ) { if ( err ) { self . _log . error ( err ) ; cb ( err , false ) ; return ; } processAssertion ( val ) ; } , ctxWin ) ; return ; } self . _log . warn ( "Could not obtain assertion in _makeClient" ) ; cb ( err , false ) ; } else { processAssertion ( val ) ; } } self . _log . info ( "Attempting to obtain assertion silently" ) BrowserID . getAssertion ( gotSilentAssertion , { audience : DASHBOARD_URL , sameEmailAs : MARKETPLACE_URL } ) ; }
To start the AitcClient we need a token, for which we need a BrowserID
 assertion.
To start the AitcClient we need a token for which we need a BrowserID assertion .
// Store the email we got the token for so we can refresh. // Store when we got the token so we can refresh it as needed. // We only create one client instance, store values in a pref tree // If we were asked to let the user login, do the popup method. // Check if we can get assertion silently first