wrobins / cordova-plugin-msal

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

signInSilent method randomly returns an array instead of an object #76

Open DanielTokyo opened 3 years ago

DanielTokyo commented 3 years ago

Hi, I've created an Android Cordova app based on an Angular 11 SPA. I am calling the signInSilent method from my SPA's HttpInterceptor to get a token to pass to my API. This usually works normally the first time, but then it starts randomly giving me an array as a response when invoked.

This is my configuration (I removed the API ID):

{
    authorities: [
      {
          type: 'AAD',
          audience: 'AzureADMyOrg',
          authorityUrl: '',
          cloudInstance: 'MSALAzurePublicCloudInstance',
          default: true
      }
    ],
    authorizationUserAgent: 'DEFAULT',
    multipleCloudsSupported: false,
    brokerRedirectUri: false,
    accountMode: 'SINGLE',
    scopes: ['api://00000000-0000-0000-0000-000000000000/access_api'],
    otherScopesToAuthorize: [
      'User.Read'
    ]
  }

Normally I get this kind of result:

{
    "token":"eyJ0eX000000...",
    "account":{
        "id":"00000000-0000-0000-0000-000000000000",
        "username":"Missing from the token response",
        "claims":[]
    }
}

But then I randomly also receive this result:

[
    {
        "id":"00000000-0000-0000-0000-000000000000",
        "username":"Missing from the token response",
        "claims":[]
    }
]

As you can see, first, it doesn't have a token; second, it is an array.

I keep my own cache of the token, so this is not a problem during the time that the token is valid, but as soon as it expires, if the next API call receives the array result, I end up passing the cached expired token to the API, and of course get a 401 Unauthorized error.

The most bizarre thing about this error is that when debugging the Java code using Android Studio, I noticed that the array result is being passed to my app's JavaScript callback, before the native code is invoked. So the native code produces the right authorization object, but it never gets to the app because the callback has already been triggered.

Has anyone experienced this error, and/or knows how I can solve it? Any ideas are welcome.

Thank you for your attention, and for this great library!