microsoft-authentication-library-for-objc icon indicating copy to clipboard operation
microsoft-authentication-library-for-objc copied to clipboard

MSALPublicClientApplication.acquireTokenSilent() completionBlock not called

Open noxo opened this issue 3 years ago • 1 comments

I've been observing random situations where MSALPublicClientApplication.acquireTokenSilent() completionBlock is not being called.

The code looks roughly following and is executed in main-thread.

        let semaphore = DispatchSemaphore(value: 0)
        let parameters = MSALSilentTokenParameters(scopes: ["\(clientId)/.default"], account: msalAccount)
        msalApplication.acquireTokenSilent(with: parameters, completionBlock: { result,error in
            // not getting called
            semaphore.signal()
        })
        semaphore.wait() // waits for ever

Could it be the the code itself - which is effectively blocking the main thread? I.e is MsalApplication.acquireTokenSilent() dispatching something syncronously to main queue (in some certain condition), which would be then blocked by above code, which would then lead in not getting the callback via completionBlock?

Issue has been with MSAL 1.19 and lower versions for quite a while. Environment has MFA and MDM enabled.

Code seems to work in 99% time. It seems that killing the app process doesn't help. Then it suddenly starts working after few hours. It's almost like some IPC thing is stuck on (i)OS level for longer time.

noxo avatar Aug 05 '22 14:08 noxo

Could you please provide us the MSAL logs such that i can take a deeper look? (If you haven't setup the logging yet, see here for details)

BTW, are you calling the silent call in main thread? Can you try to call the silent call in a background thread? Let me know what you find out.

jasoncoolmax avatar Aug 11 '22 22:08 jasoncoolmax

Thanks so much for the response.

We'll enable MSAL logging, to be able to gather more info.

And yeah, the silent call is done in main thread. Moving the silent call is into background thread is something to consider, but I would first try to get the logs.

noxo avatar Sep 07 '22 07:09 noxo

This issue has been automatically marked as stale because it has not had recent activity. Please provide additional information if requested. Thank you for your contributions.

stale[bot] avatar Oct 01 '22 11:10 stale[bot]

No update. Closing

antonioalwan avatar Oct 06 '22 19:10 antonioalwan

something was adjusted on corp Azure AAD to overcome this (didn't get further information what was done)

noxo avatar Dec 20 '22 14:12 noxo