src/dropbox-base.js
/**
  * An authentication process that works with cordova applications.
  * @param {successCallback} successCallback
  * @param {errorCallback} errorCallback
  */
An authentication process that works with cordova applications.
@param {successCallback} successCallback
@param {errorCallback} errorCallback
An authentication process that works with cordova applications . @param { successCallback } successCallback @param { errorCallback } errorCallback
authenticateWithCordova(successCallback, errorCallback) {
    const redirectUrl = 'https://www.dropbox.com/1/oauth2/redirect_receiver';
    const url = this.getAuthenticationUrl(redirectUrl);
    let removed = false;
    const browser = window.open(url, '_blank');
    function onLoadError() {
      window.setTimeout(() => { browser.close(); }, 10);
      errorCallback();
    }
    function onLoadStop(event) {
      const errorLabel = '&error=';
      const errorIndex = event.url.indexOf(errorLabel);
      if (errorIndex > -1) {
        window.setTimeout(() => { browser.close(); }, 10);
        errorCallback();
      } else {
        const tokenLabel = '#access_token=';
        let tokenIndex = event.url.indexOf(tokenLabel);
        const tokenTypeIndex = event.url.indexOf('&token_type=');
        if (tokenIndex > -1) {
          tokenIndex += tokenLabel.length;
          window.setTimeout(() => { browser.close(); }, 10);
          const accessToken = event.url.substring(tokenIndex, tokenTypeIndex);
          successCallback(accessToken);
        }
      }
    }
    function onExit() {
      if (removed) {
        return;
      }
      browser.removeEventListener('loaderror', onLoadError);
      browser.removeEventListener('loadstop', onLoadStop);
      browser.removeEventListener('exit', onExit);
      removed = true;
    }
    browser.addEventListener('loaderror', onLoadError);
    browser.addEventListener('loadstop', onLoadStop);
    browser.addEventListener('exit', onExit);
  }
authenticateWithCordova ( successCallback , errorCallback ) { const redirectUrl = 'https://www.dropbox.com/1/oauth2/redirect_receiver' ; const url = this . getAuthenticationUrl ( redirectUrl ) ; let removed = false ; const browser = window . open ( url , '_blank' ) ; function onLoadError ( ) { window . setTimeout ( ( ) => { browser . close ( ) ; } , 10 ) ; errorCallback ( ) ; } function onLoadStop ( event ) { const errorLabel = '&error=' ; const errorIndex = event . url . indexOf ( errorLabel ) ; if ( errorIndex > - 1 ) { window . setTimeout ( ( ) => { browser . close ( ) ; } , 10 ) ; errorCallback ( ) ; } else { const tokenLabel = '#access_token=' ; let tokenIndex = event . url . indexOf ( tokenLabel ) ; const tokenTypeIndex = event . url . indexOf ( '&token_type=' ) ; if ( tokenIndex > - 1 ) { tokenIndex += tokenLabel . length ; window . setTimeout ( ( ) => { browser . close ( ) ; } , 10 ) ; const accessToken = event . url . substring ( tokenIndex , tokenTypeIndex ) ; successCallback ( accessToken ) ; } } } function onExit ( ) { if ( removed ) { return ; } browser . removeEventListener ( 'loaderror' , onLoadError ) ; browser . removeEventListener ( 'loadstop' , onLoadStop ) ; browser . removeEventListener ( 'exit' , onExit ) ; removed = true ; } browser . addEventListener ( 'loaderror' , onLoadError ) ; browser . addEventListener ( 'loadstop' , onLoadStop ) ; browser . addEventListener ( 'exit' , onExit ) ; }
An authentication process that works with cordova applications.
An authentication process that works with cordova applications .
// Try to avoid a browser crash on browser.close(). // Try to avoid a browser crash on browser.close(). // Try to avoid a browser crash on browser.close().