0

I'm using ASWebAuthenticationSession authorization for my application. It works fine before macOS12.4, but occur unresponse's issue. After "session.start success", Click Cancel or Continue and there is no response.

The window that can't be closed

        var session = ASWebAuthenticationSession.init(url: url, callbackURLScheme: "http", completionHandler: completionHandler)

        guard let provider = NSApplication.shared.keyWindow!.contentViewController as? FlutterViewController else {
            result(FlutterError(code: "FAILED", message: "Failed to aquire root FlutterViewController" , details: nil))
            return
        }

        session.presentationContextProvider = provider

        if(!session.start()) {
            NSLog("session.start  fail");
        } else {
            NSLog("session.start success");
        }
Mars Cai
  • 21
  • 3

1 Answers1

0

Edit: I just noticed I did not read correctly and missed the fact that this question was for macOS, not iOS. I still hope one of those answers might lead to a solution.

I have noticed 2 things that seem incorrect to me.


The first one is that you need a strong reference for your session. This limitation is only valid for iOS version < 13.0.

This means, the session variable must "outlive" the invoked method it was started in, e.g. setting a session attribute for the whole class. I cannot see something similar in the code snippet you provided, it looks like a scoped variable to me.

From Apples documentation for this feature:

For iOS apps with a deployment target earlier than iOS 13, your app must keep a strong reference to the session to prevent the system from deallocating the session while waiting for authentication to complete.


The second thing is your callback URL scheme seems to be set to https. The scheme should match your apps bundle ID. It must be configured in your Info.plist file. Here's an example how to achieve this. It should actually be something like com.company.myappname instead of http. Your authentication provider would also need to redirect to com.company.myappname://someurl to make this work. Please note the :// must not be part of the callback URL scheme, only the part before that.