xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.52k stars 505 forks source link

AppDelegate.OpenUrl does not bring app to front #2003

Open jonasrembratt opened 2 years ago

jonasrembratt commented 2 years ago

Description

Writing a OIDC implementation that sets up a (Kestrel) listener to fetch the callback from the token issuer. All works fine but now I want the app to reactivate so I have registered a custom URI scheme (iOS) and also added that scheme to the info.plist LSApplicationQueriesSchemes array.

Here's my code that gets called as a result of the OIDC callback coming back, to bring my app to the front again:

if (!await Launcher.CanOpenAsync(identifier)) // <-- returns true
    return Outcome.Fail($"Cannot open application with identifier '{identifier}'");

var outcome = await Launcher.TryOpenAsync(identifier) // <-- returns true
    ? Outcome.Success() 
    : Outcome.Fail($"Cannot open application with identifier '{identifier}'");
return outcome;

NOTE: I understand that rolling one's own OIDC can be considered sketchy, with the WebAuthenticator available, but from how I understand the WebAuthenticator it only returns an access token. The flow I'm supporting also returns a refresh token and an id token.

Steps to Reproduce

  1. Write app that performs OIDC using Browser.OpenAsync with LaunchMode = BrowserLaunchMode.SystemPreferred (I have also tested LaunchMode = BrowserLaunchMode.External) and that listens to the auth code callback
  2. When callback comes invoke code as per above example
  3. Ensure breakpoint is set in AppDelegate's OpenUrl method and that the method returns true

Expected Behavior

App should be brought to the front

Actual Behavior

Breakpoint in OpenUrl gets hit but nothing happens after it returns true. Browser is still at the front and the app remains in the background

Basic Information