Search code examples
androidibm-mobilefirstmobilefirst-servermobilefirst-cli

WLAuthorizationManager.obtainAccessToken() works fine in one environment but is broken in another


I am trying to call the WLAuthorizationManager.obtainAccessToken() but it is calling the error function on my Mac but succeeds just fine on my PC. The code sample I am using on both is below:

  waitingForMFP (renderer: Renderer) {
  this.tlpLogger.toLog('debug','-- Homepage waitingForMFP');
    renderer.listenGlobal ('document', 'mfpjsloaded', () => {
      this.tlpLogger.toLog('debug','-- Homepage waitingForMFP: The global event mfpjsloaded has been thrown');        
      WLAuthorizationManager.obtainAccessToken()
      .then(
          function(accessToken) {
            this.tlpLogger.toLog('debug','-- Homepage waitingForMFP: Access token has been granted');
          }.bind(this), 
          function(error) {
            this.tlpLogger.toLog('warn','-- Homepage waitingForMFP: Access token failed: ' + JSON.stringify(error));   
            this.ngZone.run();  
          }.bind(this)
      );
  })
  }

In both cases, I am trying to emulate this on an Android device. When I print out the "error" object, I get the following:

{"status":-1,"responseText":"","errorMsg":"This version of the MobileFirst client SDK requires a minimal server version greater than IFIX 8.0.0.0-IF20161122-19","errorCode":"MINIMUM_SERVER"}

This message makes no sense to me because they are both hitting the same server on Bluemix so if that was a problem, I should get the same message in both environments. When I check the version of the mfp cli on both environments, I get the same answer:

$ mfpdev -v
8.0.0-2016121916

I have tried calling the "mfpdev app register" on both environments and that does not seem to make a difference.

I am getting another error in the console logs (below) on BOTH environments but since it is coming after the obtainAccessToken() method and it happens on both environments, I think it is unrelated (although another problem I am trying to address). The message is:

Uncaught TypeError: Cannot read property 'apply' of undefined

PC:

02-07 16:08:32.568 7485-7485/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(60929)] "-- Homepage waitingForMFP", source: file:///android_asset/www/build/main.js (60929)
02-07 16:08:32.645 7485-7485/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(2505)] "Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.", source: file:///android_asset/www/build/main.js (2505)
02-07 16:08:32.690 7485-7485/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(111840)] "DEVICE READY FIRED AFTER", source: file:///android_asset/www/build/main.js (111840)
02-07 16:08:32.698 7485-7485/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(3)] "Running static_app_props.js...", source: file:///android_asset/www/plugins/cordova-plugin-mfp/worklight/static_app_props.js (3)
02-07 16:08:32.884 7485-7485/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(60929)] "-- Homepage waitingForMFP: The global event mfpjsloaded has been thrown", source: file:///android_asset/www/build/main.js (60929)
02-07 16:08:32.887 7485-7485/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(73)] "Calling WL.Client.init(wlInitOptions);", source: file:///android_asset/www/plugins/cordova-plugin-mfp/bootstrap.js (73)
02-07 16:08:32.902 7485-7485/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(0)] "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.", source:  (0)
02-07 16:08:33.521 7485-7485/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(60929)] "-- Homepage waitingForMFP: Access token has been granted", source: file:///android_asset/www/build/main.js (60929)
02-07 16:08:33.547 7485-7485/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(312)] "Error in Success callbackId: WLAuthorizationManagerPlugin756181927 : TypeError: Cannot read property 'apply' of undefined", source: file:///android_asset/www/cordova.js (312)
02-07 16:08:33.554 7485-7485/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(314)] "Uncaught TypeError: Cannot read property 'apply' of undefined", source: file:///android_asset/www/cordova.js (314)

Mac:

02-07 16:07:12.240 4122-4122/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(60929)] "-- Homepage waitingForMFP", source: file:///android_asset/www/build/main.js (60929)
02-07 16:07:12.352 4122-4122/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(2505)] "Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.", source: file:///android_asset/www/build/main.js (2505)
02-07 16:07:12.418 4122-4122/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(111846)] "Native: deviceready did not fire within 2000ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.", source: file:///android_asset/www/build/main.js (111846)
02-07 16:07:12.422 4122-4122/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(111841)] "DEVICE READY FIRED AFTER", source: file:///android_asset/www/build/main.js (111841)
02-07 16:07:12.433 4122-4122/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(3)] "Running static_app_props.js...", source: file:///android_asset/www/plugins/cordova-plugin-mfp/worklight/static_app_props.js (3)
02-07 16:07:12.779 4122-4122/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(60929)] "-- Homepage waitingForMFP: The global event mfpjsloaded has been thrown", source: file:///android_asset/www/build/main.js (60929)
02-07 16:07:12.790 4122-4122/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(73)] "Calling WL.Client.init(wlInitOptions);", source: file:///android_asset/www/plugins/cordova-plugin-mfp/bootstrap.js (73)
02-07 16:07:12.813 4122-4122/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(0)] "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.", source:  (0)
02-07 16:07:13.294 4122-4122/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(60917)] "-- Homepage waitingForMFP: Access token failed: {"status":-1,"responseText":"","errorMsg":"This version of the MobileFirst client SDK requires a minimal server version greater than IFIX 8.0.0.0-IF20161122-19","errorCode":"MINIMUM_SERVER"}", source: file:///android_asset/www/build/main.js (60917)
02-07 16:07:13.315 4122-4122/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(312)] "Error in Error callbackId: WLAuthorizationManagerPlugin1973171517 : TypeError: Cannot read property 'apply' of undefined", source: file:///android_asset/www/cordova.js (312)
02-07 16:07:13.326 4122-4122/com.ionicframework.tlpapp360156 I/chromium: [INFO:CONSOLE(314)] "Uncaught TypeError: Cannot read property 'apply' of undefined", source: file:///android_asset/www/cordova.js (314)

Any help here would be greatly appreciated!


Solution

  • First, checking for the CLI version to check for compatibility doesn't really matter... the CLI does not instantiate a server instance or add SDKs to applications like in previous releases... so its version is less important.

    There was a recent update to the Cordova plug-ins that introduced a client-server incompatibility bug.

    I suggest that you will either:

    1. Update the server (the Mobile Foundation service was updated yesterday), remove the plug-in and re-add it, and try again
    2. Remove the plug-in and re-add it, and try again, although updating the server as well is always recommended