wrobins / cordova-plugin-msal

Use the newest Microsoft MSAL library in your Cordova-based project!
Apache License 2.0
23 stars 66 forks source link

NullPointerException is thrown if response doesn't contain claims #112

Open dominic-simplan opened 11 months ago

dominic-simplan commented 11 months ago

I am getting a NullPointerException error when calling

cordova.plugins.msalPlugin.signInInteractive(resolve, reject, {
                webViewType: "WK_WEB_VIEW",
                prompt: "LOGIN",
            });

for a Azure AAD instance.

The error stack trace:

java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Set java.util.Map.entrySet()' on a null object reference
    at com.wrobins.cordova.plugin.MsalPlugin.processClaims(MsalPlugin.java:563)
    at com.wrobins.cordova.plugin.MsalPlugin.getAccountObject(MsalPlugin.java:554)
    at com.wrobins.cordova.plugin.MsalPlugin.getAuthResult(MsalPlugin.java:542)
    at com.wrobins.cordova.plugin.MsalPlugin.access$1500(MsalPlugin.java:42)
    at com.wrobins.cordova.plugin.MsalPlugin$6$1.onSuccess(MsalPlugin.java:390)
    at com.microsoft.identity.client.PublicClientApplication.postAuthResult(PublicClientApplication.java:2023)
    at com.microsoft.identity.client.SingleAccountPublicClientApplication$3.onTaskCompleted(SingleAccountPublicClientApplication.java:438)
    at com.microsoft.identity.client.SingleAccountPublicClientApplication$3.onTaskCompleted(SingleAccountPublicClientApplication.java:429)
    at com.microsoft.identity.common.java.controllers.CommandDispatcher.commandCallbackOnTaskCompleted(CommandDispatcher.java:562)
    at com.microsoft.identity.common.java.controllers.CommandDispatcher.access$1000(CommandDispatcher.java:86)
    at com.microsoft.identity.common.java.controllers.CommandDispatcher$4.run(CommandDispatcher.java:538)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7918)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Issue seems to be that the account object doesn't contain any claims and therefore the account.getClaims() returns null instead of a map.

dominic-simplan commented 5 months ago

Hello @wrobins , I can see that you fixed the above mentioned line but you also introduced a NonNull annotation here: https://github.com/wrobins/cordova-plugin-msal/commit/d909884c6638ee00c132101fc11898083bc4d564#diff-e5923747b7842092fa19ae5c75aca5d73f0465b348be327edf209c96e59fa444R580

Now it fails for me with v4.1.1 at the NonNull check. Is there any specific reason for the check?

As far as I can see, the claims are allowed to be null by the msal android library: https://github.com/AzureAD/microsoft-authentication-library-for-android/blob/f0487a4cbcba7b778185bfe4278704d580b35bd2/msal/src/main/java/com/microsoft/identity/client/Account.java#L137