ASWebAuthenticationSession doesn't work as expected

ASWebAuthenticationSession works wrong when called second time in a row.

So our web authentication code is organised like this:

if let existingSession = ssoAuthSession {
   // closes the auth window but then request queue gets stuck:
    existingSession.cancel() 
}

let session = ASWebAuthenticationSession(url: signinURL, callbackURLScheme: callbackScheme) { (receivedURL, error) in 

    /// handle the result, 

    DispatchQueue.main.async {
        // report the result
        self.ssoAuthSession = nil
    }
}

session.prefersEphemeralWebBrowserSession = true
session.presentationContextProvider = delegate //delegate provides a valid app window
if !session.canStart() {
     // report error, (doesn't happen)
     return
}
self.ssoAuthSession = session
self.ssoAuthSession.start()

The problem is, if the user initiates the SSO Authentication second time without closing the previous browser authentication window, that old window closes (as we cancelled the old session), but the new window never opens.

This reproduces 100% on every default browser except Safari. What helps is to re - start the default browser, then it shows the queue of previously called (but not shown) authentication windows.

The fact that it happens everywhere except Safari and that the web authentication request queue survives browser life time points me to possible bug in macOS.

The documentation says it should work with any default browser that supports ASWebAuthenticationSession, however, it doesn't.

Please point me to how I can solve this problem, if I am mistaken regarding macOS bug.

Can you please file this through Feedback Assistant? A screen recording and sysdiagnose would be super helpful. Thanks!

ASWebAuthenticationSession doesn't work as expected
 
 
Q