0

I am using Ionic and Oauth.io to perform authentication. If I run ionic serve and include the outh.js file in my index everything works good from the browser.

But when I run ionic run ios or install the app in android, I get the following error when I press the auth button (the one that suppose to execute OAuth.popup

The unexpected error

I do not know what to do, until now I have checked the following:

  1. In config.xml I have access, allow-intent and allow-navigation full permisive
  2. I have installed and re-installed the plugin ionic plugin add https://github.com/oauth-io/oauth-phonegap.git
  3. I tried to run the native app without the inclusion of the oauth.js file and everything breaks.
  4. Using current versions up to date.
  5. I am new to Ionic, so I don't know how to debug the device-running app or simulator.
  6. Could be similar to this post but not exactly .

Your advices will be appreciated.

Community
  • 1
  • 1
po5i
  • 548
  • 5
  • 19

1 Answers1

1

I figure it out reading some posts. The OAuth initialization and references should be done after the device is ready, so it is best to put the initialize in this block:

$ionicPlatform.ready(function() {
  // ...
  if(typeof window.OAuth !== 'undefined'){
    $rootScope.OAuth = window.OAuth;
    $rootScope.OAuth.initialize('XXX');
  }
  else{
    console.log("plugin not loaded, this is running in a browser");
    $.getScript( "lib/oauth.js", function() {
      $rootScope.OAuth = OAuth;
      $rootScope.OAuth.initialize('XXX');
    });

  }
});

Now, if the plugin is loaded it initializes the window.OAuth object, else the app is running in browser, so I have to include the oauth.js file. Also I assigned the OAuth to the $rootScope for quick access.

Hope this helps anyone.

po5i
  • 548
  • 5
  • 19