Using Prefers Ephemeral WebBrowser Session in Auth0 MAUI SDK

Problem statement

This article explains why it is no longer possible to create ASWebAuthenticationSessionBrowser in MAUI SDK and a potential alternative. This can be used for suppressing the iOS consent prompt by setting PrefersEphemeralWebBrowserSession = true.

Cause

The ASWebAuthenticationSessionBrowser class is not exposed by the current version of the MAUI SDK (1.0.0 at the time of writing).

Solution

In the current version of the MAUI SDK (1.0.0 at the time of writing), the ASWebAuthenticationSessionBrowser class is not exposed.

Instead, create a custom Browser implementation that is a copy of:

Then replace:

var result = await WebAuthenticator.Default.AuthenticateAsync(new Uri(options.StartUrl), new Uri(options.EndUrl));

with:

var result = await WebAuthenticator.Default.AuthenticateAsync(new WebAuthenticatorOptions { Url = new Uri(options.StartUrl), CallbackUrl = new Uri(options.EndUrl), PrefersEphemeralWebBrowserSession = true });

Then, when instantiating the client, pass the custom browser class that was created:

new Auth0Client() { Browser = new CustomBrowser() }