ASWebAuthenticationSession won't open the Safari login window on Monterey

My macOS app uses ASWebAuthenticationSession for users to login to a third party service. It's worked fine until Monterey.

When I call start on ASWebAuthenticationSession it shows me the permission window as expected:

However when I click Continue nothing else happens. It does not show the Safari window and load the login page.

I've noticed these errors appear in the Console every time, so it seems it's having trouble opening Safari (even though I have Safari already open).

Any suggestions on how to fix this? Surely ASWebAuthenticationSession isn't broken for everyone?

error	10:40:50.598301+0000	kernel	43 duplicate reports for Sandbox: com.apple.WebKit(13346) deny(1) mach-lookup com.apple.diagnosticd
error	10:40:50.598309+0000	kernel	Sandbox: SafariLaunchAgen(5469) deny(1) system-fsctl _IO('h', 47)
error	10:40:52.349729+0000	kernel	Sandbox: com.apple.WebKit(6675) deny(1) mach-lookup com.apple.diagnosticd
error	10:40:53.011948+0000	CoreServicesUIAgent	LAUNCH: Launch failure with -10652/ <FSNode 0x60000068b6e0> { isDir = y, path = '/Applications/Safari.app' }
error	10:40:53.019505+0000	CoreServicesUIAgent	Unable to forward entitlements from overridden keySenderAuditTokenAttr [sess=100005 pid=5469 uid:501,501,501 g:20,20 pV:257536] to target port ( port:85539/0x14e23 rcv:0,send:2,d:0 limit:0), which will likely cause them to reject this AppleEvent, errorRef=[ NULL ]
Answered by Systems Engineer in 716453022

This issue was fixed in macOS 12.4. If you see further issues, please file additional feedbacks 🙂.

Ok, I guess I fixed it, for now.

Even though i'd tried rebooting the Mac, closing Safari then trying this login did in fact open Safari correctly. It even presented me with the 30+ login windows that had previously not opened.

So it's working again now, but I don't know why it got stuck.

This happens to my app too. I'm now using a WebKit view instead, for a more predictable sign in flow.

This is absolutely not fixed. We use the Auth0 SDK for Oauth2 authentication across various Apple devices, which on macOS wraps ASWebAuthenticationSession, and encounter this behavior relatively frequently. We see it on Monterey, across Safari, Chrome and Brave browsers.

I am surprised this isn't getting more attention. The problem is pretty nasty once it triggers -- the user has no idea what is happening or why the login dialog doesn't pop up, and the calling application has no way to detect the condition.

We reported it to Auth0 and they closed our bug pretty quickly -- everyone seems to understand this is Apple's problem.

I can confirm this issue. It is sporadic and hard to pin down, making it difficult to debug. But when it does happen, the experience is very bad for the user: there is no login possible. And when they close and re-open their browser at a later time, they are surprised with the login window; which is very jarring.

Has anyone found a fix to this? I just posted a question on a couple of ASWebAuthenticationSession issues I'm seeing and just realised that one of them looks a lot like this one (apologies for the duplicate if so).

Same problem here - since months. Also very surprised Apple isn't interested in fixing this.

Could someone from Apple please comment on this?

I am also experiencing this issue when trying to use Auth0 on macOS Monterrey. Anyone been able to figure out a workaround?

We are having this issue as well. Did anyone come up with a workaround? Could anyone from Apple please advise?

Hi guys,

We also have similar problem with ASWebAuthenticationSession on 10.15.

The issue occurs when Safari is selected as default browser and it is been used for a while before the session starts.

When it happens login window does not show up and CompletionHandler is never called.

Closing Safari process helps to overcome the issue and the session window appears immediately after the current process is closed.

It seems to be something wrong between OS and Safari, which prevents it to behave normally.

Any help with the issue would be highly appreciated.

The same issue happening for me on Monterrey, please fix that.

Same here on Monterey 12.2 - I had Safari running for a long time (with lots of open windows and tons of tabs). The UI for ASWebAuthenticationSession never showed up, even when trying multiple times. After quitting and relaunching Safari, all the queued requests for ASWebAuthenticationSession were handled in a serial fashion. This is clearly broken. Please fix in macOS 13.

I hope everyone is filing bug reports for this.

Also posted a bug report FB10031739

This issue was fixed in macOS 12.4. If you see further issues, please file additional feedbacks 🙂.

ASWebAuthenticationSession won't open the Safari login window on Monterey
 
 
Q