App crash only on iOS after successful WebAuthenticator callback via Universal App Link

I’m migrating a .NET MAUI iOS authorization flow from one that handles redirect using the now-deprecated custom URL scheme to one that employs an Universal App Link verified via a apple-app-site-association file hosted on Firebase.

The callback works. The code is received successfully. The issue is that the app crashes upon returning from the WebAuthenticator authorization flow. This is a problem with iOS only, not Android which works perfectly using an Android App Link served by a assetlinks.json file on the same server.

Short question

Have you gotten this to work? In that case skip all the laborious details and walk me through it! Otherwise, here is…


What I’ve tried

  1. Verify the Universal App Link using the Developer settings on iPhone.

  1. With the app debugger attached, inject the URL in Safari from a special “redirect test” page on our server. Verify that a breakpoint in ContinueUserActivity is hit. Verify that the app does not crash when the Universal App Link is exercised in this manner.

  1. Setting a breakpoint to inspect the returned authorization code. Then returning immediately to avoid any possibility of other exceptions.
buttonLogin.Clicked += async (sender, e) =>
{
    var clientId = "123456789012-1ok9rauo969og7aljrnri1gesrr7l1b3.apps.googleusercontent.com";
    var redirectUrl = "https://myfirebasedomain.com/auth";
    var scopes = "profile%20openid%20email";
    var authUrl = $"https://accounts.google.com/o/oauth2/auth?client_id={clientId}&redirect_uri={redirectUrl}&prompt=consent&response_type=code&scope={scopes}&access_type=offline";

    Uri authUri = new Uri(authUrl);
    Uri callbackUri = new Uri(redirectUrl);

    WebAuthenticatorResult result;
    try
    {
        result = await WebAuthenticator.AuthenticateAsync(new WebAuthenticatorOptions
        {
            Url = authUri,
            CallbackUrl = callbackUri,
            PrefersEphemeralWebBrowserSession = true
        });
    }
    catch (TaskCanceledException)
    {
        // 'Not' an error. The user simply cancelled this op.
        return;
    }
    catch (Exception ex)
    {
        Debug.Fail(ex.Message);
        return;
    }

    // Exchange the authorization code for an access token

    var payload = new
    {
        code = result.Properties["code"],
        redirectUri = redirectUrl,
        clientId = clientId,
        key = "web",
    };
    var jsonPayload = JsonConvert.SerializeObject(payload, Formatting.Indented);
    var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
    using var httpClient = new HttpClient();
    HttpResponseMessage? response = null;
    string? error = null;

    try
    {
        // Exchange token using secret stored on server.

        // We are unable to attempt this. The async post causes this 
        // method to return, and when it does, the app crashes.
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message);
        if (response != null)
        {
            error = await response.Content.ReadAsStringAsync();
        }
        Debug.Fail(error ?? "null");
    }
};

Value of jsonPayload indicates success

{
  "code": "4/0AanRRrte8fELNx0CyzgsPzrGCo46TLvkp_JhQaG0ao8DMmVLySwN4_8KIfAXNiouGAqkrQ",
  "redirectUri": "https://myfirebasedomain.com/auth",
  "clientId": "123456789012-1ok9rauo969og7aljrnri1gesrr7l1b3.apps.googleusercontent.com",
  "key": "web"
}

  1. Going up a level to wrap the ContinueUserActivity for exceptions. I can set a breakpoint on return result. The crash occurs if this method is allowed to run from that point.
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
    protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
    public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
    {
        bool result = false;
        try
        {
            // Calling the BC is what causes the AuthenticateAsync task to complete.
            result = base.ContinueUserActivity(application, userActivity, completionHandler);
        }
        catch (Exception)
        {
            // NO exception being caught here.
        }
        return result;
    }
}

My question:

AFAIK I’m doing everything right, but can anyone spot any reason for the crash? I’m inclined to log it as a bug against WebAuthenticator for iOS, but before I do anything dumb please “check my work!”


Crash Log (iPhone 11 physical device)


Loaded assembly: Anonymously Hosted DynamicMethods Assembly [External]
INFO:   0x1a3be2db0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a390977c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__

INFO:   0x1a3c6677c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO: 014e7888 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : xamarin_get_original_working_directory_path
    0x101842cdc - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x1c72e0de8 - /usr/lib/dyld : <redacted>

=================================================================
    Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x19e5d634c):0x19e5d633c  21 20 37 91 30 06 00 14 00 00 00 ea 6d ff ff 54  ! 7.0.......m..T
0x19e5d634c  10 00 
INFO: 0x19e5d635c  30 04 00 36 11 
INFO:   0x1a3abee00 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a3c02410 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a3908434 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a3886350 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO: Disposing input and output streams...
INFO:   0x1a10d5bbc - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
    0x1a10d21b0 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
    0x1a1124274 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : CFRunLoopRunSpecific

INFO:   0x1a38863c0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a2c47008 - /System/Library/Frameworks/QuartzCore.framework/QuartzCore : <redacted>

INFO:   0x1a3908434 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a3c02410 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a3c02790 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a3886350 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a3909718 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a3ac1944 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1c4e37488 - /System/Library/Frameworks/SafariServices.framework/SafariServices : <redacted>

INFO:   0x1a3abee00 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1017efa50 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x1017d1d0c - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x22bba8ca8 - /usr/lib/system/libsystem_platform.dylib : <redacted>

INFO: 
=================================================================
    Native Crash Reporting
=================================================================

INFO: Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
    Native stacktrace:
=================================================================

INFO:   0x101804b64 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection

INFO:   0x1a8e0bfa8 - /usr/lib/system/libdispatch.dylib : <redacted>
    0x1a8e1aa34 - /usr/lib/system/libdispatch.dylib : <redacted>

INFO:   0x1a8e1a64c - /usr/lib/system/libdispatch.dylib : _dispatch_main_queue_callback_4CF

INFO:   0x1014e7888 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : xamarin_get_original_working_directory_path
    0x101842cdc - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x1c72e0de8 - /usr/lib/dyld : <redacted>

Exiting early due to double fault.

INFO:   0x1a1124274 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : CFRunLoopRunSpecific
    0x1ee26d4c0 - /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices : GSEventRunModal
    0x1a3c6677c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a388ce64 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : UIApplicationMain
    0x1014bc5f4 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : xamarin_UIApplicationMain
    0x101815404 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x101813d04 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x101808714 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x1018062ac - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncP
INFO:   0x1a2c47008 - /System/Library/Frameworks/QuartzCore.framework/QuartzCore : <redacted>
    0x1a8e0bfa8 - /usr/lib/system/libdispatch.dylib : <redacted>
    0x1a8e1aa34 - /usr/lib/system/libdispatch.dylib : <redacted>
    0x1a8e1a64c - /usr/lib/system/libdispatch.dylib : _dispatch_main_queue_callback_4CF
    0x1a10d5bbc - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
    0x1a10d21b0 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>

INFO:   0x1a38863c0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a390977c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__

INFO:   0x1a3909718 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO: roxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x1017d4e84 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x10177c548 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x101782844 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x1017da4a0 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection

INFO:   0x1a3c02790 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a3ac1944 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:   0x1a3be2db0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>

INFO:     at UIKit.UIApplication:Main <0x00152>
      at GoogleDriveLocalSyncProxy.Maui.TestProject.Program:Main <0x0002c>
      at <Module>:runtime_invoke_direct_void_string[] <0x0007e>
      at <unknown> <0x00000>
=================================================================

=================================================================
    Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

An error has occurred in the native fault reporting. Some diagnostic information will be unavailable.

INFO: 
=================================================================
    Native stacktrace:
=================================================================
    0x101804b64 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x1017efa50 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x1017d1d0c - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection

INFO: ...

=================================================================
    Managed Stacktrace:
=================================================================
      at <unknown> <0xffffffff>
      at UIKit.UIApplication:xamarin_UIApplicationMain <0x000b8>
      at UIKit.UIApplication:UIApplicationMain <0x0006e>

INFO:   0x22bba8ca8 - /usr/lib/system/libsystem_platform.dylib : <redacted>
    0x1c4e37488 - /System/Library/Frameworks/SafariServices.framework/SafariServices : <redacted>

INFO:  `..T. .......
INFO: fe 77 d3 91 fe ff b4 3f 06 00 f1  0..6..w.....?...
INFO:  ..@...}[email protected]

INFO: 40 f9 02 82 7d 92 51 10 40 f9 31 03 10 36 
INFO:   0x1018062ac - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x1017d4e84 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x10177c548 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x101782844 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x1017da4a0 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x1
INFO:   0x1a388ce64 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : UIApplicationMain
    0x1014bc5f4 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : xamarin_UIApplicationMain
    0x101815404 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x101813d04 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection
    0x101808714 - /private/var/containers/Bundle/Application/0D3ED65C-DDCD-40D0-A24A-BE6EDA007591/IVSoftware.Maui.EchoesSyncProxy.app/IVSoftware.Maui.EchoesSyncProxy : AppleCryptoNative_X509ImportCollection

INFO:   0x1ee26d4c0 - /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices : GSEventRunModal

INFO: 
0x19e5d636c  60 02 00 54 11 20 e0 d2 11 02 11 cb e1 03 10 aa 
INFO: Closing debug connection from remote debugger (TCP)
INFO: Closing debug connection from device (USB)
The app has been terminated.
INFO: Disposing input and output streams...
INFO: Disposing console and debugger streams...
ERROR: An error occurred while writing to the debug stream. Details: ObjectDisposed_Generic
ObjectDisposed_ObjectName_Name, UsbStream

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật