ASWebAuthenticationSession MacOS implementation

Hi all; I'm trying to implement ASWebAuthenticationSession on MacOS. The application must be able to open the default browser to interact with the IdP. The implemented code is basic, since what I am trying to understand is how to configure the framework to be able to open the system browser. Based on the documentation I observe this:

A browser loads and displays the page, from which the user can authenticate. In iOS, the browser is a secure, embedded web view. In macOS, the system opens the user’s default browser if it supports web authentication sessions, or Safari otherwise.

That is, it implies that this would be valid only for iOS, since a view is required where the content can be anchored. With which my understanding is that for MacOS that is not necessary, since the system browser is used.

However, when I try to compile the base example, Xcode throws the following message:

_Domain=com.apple.AuthenticationServices.WebAuthenticationSession Code=2 "Cannot start ASWebAuthenticationSession without providing presentation context.

The base code I'm using is very simple:

ASWebAuthenticationSession* webAuth = [[ASWebAuthenticationSession alloc] initWithURL:requestURL
                callbackURLScheme:redirectScheme
                completionHandler:^(NSURL * _Nullable callbackURL,NSError * _Nullable error)
  {}];

webAuth.start;

All of this is required in Objective-C. All the examples that have been and will be are for iOS and all based on Swift.

Any reference about it to be able to implement this in MacOs?

Thanks and regards. Cristian.

You still need to set the presentationContextProvider and provide a valid window on Mac. The anchor window that you provide is used to hint to the system where to show the browser window.

Thanks for the reply. In case I need to interact directly with the browser of the operating system (Safari, Chrome); According to the documentation, the presentationContextProvider applies for iOS in order to implement it in a webview, but in MacOs the system should open the browser. How is interaction with the OS browser achieved on Mac? I mean how should the context provider be configured on MacOs to depend on the external browser? Thanks again.

ASWebAuthenticationSession MacOS implementation
 
 
Q