{"action":"created","issue":{"url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-cordova/issues/14","labels_url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-cordova/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-cordova/issues/14/comments","events_url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-cordova/issues/14/events","html_url":"https://github.com/AzureAD/azure-activedirectory-library-for-cordova/issues/14","id":97804640,"number":14,"title":"Exception when using ADAL cordova on a encrypted android phone","user":{"login":"fw224","id":9651154,"avatar_url":"https://avatars.githubusercontent.com/u/9651154?v=3","gravatar_id":"","url":"https://api.github.com/users/fw224","html_url":"https://github.com/fw224","followers_url":"https://api.github.com/users/fw224/followers","following_url":"https://api.github.com/users/fw224/following{/other_user}","gists_url":"https://api.github.com/users/fw224/gists{/gist_id}","starred_url":"https://api.github.com/users/fw224/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fw224/subscriptions","organizations_url":"https://api.github.com/users/fw224/orgs","repos_url":"https://api.github.com/users/fw224/repos","events_url":"https://api.github.com/users/fw224/events{/privacy}","received_events_url":"https://api.github.com/users/fw224/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-cordova/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":{"login":"weijjia","id":1166233,"avatar_url":"https://avatars.githubusercontent.com/u/1166233?v=3","gravatar_id":"","url":"https://api.github.com/users/weijjia","html_url":"https://github.com/weijjia","followers_url":"https://api.github.com/users/weijjia/followers","following_url":"https://api.github.com/users/weijjia/following{/other_user}","gists_url":"https://api.github.com/users/weijjia/gists{/gist_id}","starred_url":"https://api.github.com/users/weijjia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weijjia/subscriptions","organizations_url":"https://api.github.com/users/weijjia/orgs","repos_url":"https://api.github.com/users/weijjia/repos","events_url":"https://api.github.com/users/weijjia/events{/privacy}","received_events_url":"https://api.github.com/users/weijjia/received_events","type":"User","site_admin":false},"milestone":null,"comments":5,"created_at":"2015-07-28T21:21:12Z","updated_at":"2015-11-04T07:22:47Z","closed_at":null,"body":"I am developing a cordova app that uses ADAL cordova and requires a service from a corp network (MSFT corp network). ADAL cordova works using an emulator, but on a real device (which requires encryption to access the corp network) ADAL cordova is giving me an exception. The following is the exact error:\r\n\r\nE/PluginManager(18227): Uncaught exception from plugin\r\nE/PluginManager(18227): java.lang.ClassCastException: com.microsoft.aad.adal.AuthenticationContext$1 cannot be cast to com.microsoft.aad.adal.DefaultTokenCacheStore\r\nE/PluginManager(18227):    at com.microsoft.aad.adal.CordovaAdalPlugin.readTokenCacheItems(CordovaAdalPlugin.java:165)\r\nE/PluginManager(18227):    at com.microsoft.aad.adal.CordovaAdalPlugin.execute(CordovaAdalPlugin.java:83)\r\nE/PluginManager(18227):    at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:84)\r\nE/PluginManager(18227):    at org.apache.cordova.PluginManager.exec(PluginManager.java:147)\r\nE/PluginManager(18227):    at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)\r\nE/PluginManager(18227):    at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:40)\r\nE/PluginManager(18227):    at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)\r\nE/PluginManager(18227):    at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)\r\nE/PluginManager(18227):    at android.os.Handler.dispatchMessage(Handler.java:102)\r\nE/PluginManager(18227):    at android.os.Looper.loop(Looper.java:145)\r\nE/PluginManager(18227):    at android.os.HandlerThread.run(HandlerThread.java:61)\r\n\r\nAnd the following is my code:\r\n$scope.context = new Microsoft.ADAL.AuthenticationContext(authority);\r\n\r\n    $scope.context.tokenCache.readItems().then(function (items) {\r\n      if (items.length > 0) {\r\n        authority = items[0].authority;\r\n        $scope.context = new Microsoft.ADAL.AuthenticationContext(authority);\r\n      }\r\n\r\n      // Attempt to authorize user silently\r\n      $scope.context.acquireTokenSilentAsync(resourceUrl, appId)\r\n      .then(onAADSuccess, function () {\r\n      // We require user cridentials so triggers authentication dialog\r\n      $scope.context.acquireTokenAsync(resourceUrl, appId, redirectUrl)\r\n     .then(onAADSuccess, function (err) {\r\n        });\r\n      });\r\n    });\r\n\r\nAny help would be appreciated!"},"comment":{"url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-cordova/issues/comments/153613618","html_url":"https://github.com/AzureAD/azure-activedirectory-library-for-cordova/issues/14#issuecomment-153613618","issue_url":"https://api.github.com/repos/AzureAD/azure-activedirectory-library-for-cordova/issues/14","id":153613618,"user":{"login":"weijjia","id":1166233,"avatar_url":"https://avatars.githubusercontent.com/u/1166233?v=3","gravatar_id":"","url":"https://api.github.com/users/weijjia","html_url":"https://github.com/weijjia","followers_url":"https://api.github.com/users/weijjia/followers","following_url":"https://api.github.com/users/weijjia/following{/other_user}","gists_url":"https://api.github.com/users/weijjia/gists{/gist_id}","starred_url":"https://api.github.com/users/weijjia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weijjia/subscriptions","organizations_url":"https://api.github.com/users/weijjia/orgs","repos_url":"https://api.github.com/users/weijjia/repos","events_url":"https://api.github.com/users/weijjia/events{/privacy}","received_events_url":"https://api.github.com/users/weijjia/received_events","type":"User","site_admin":false},"created_at":"2015-11-04T07:22:47Z","updated_at":"2015-11-04T07:22:47Z","body":"@RandalliLama Sorry I just saw the issue. For the crash stack trace, I don't think it even starts to talk to company portal. It looks like the crash happens inside the readTokenCacheItems, which contains the authContext.getCache. In android version of ADAL, the getCache method will check if we can switch to broker, it seems in this particular case, the existence of Company Portal makes adal-android switch to broker, and we're retuning a new anonymous inner class implementing the interface ITokenCacheStore. When authContext.getCache returns, the cordova plugin is trying to cast it to the DefaultTokenCacheStore...oops, exception is thrown here. The returned anonymous inner class implementing the interface ITokenCacheStore cannot be casted to DefaultTokenCacheStore. "}}