Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
IVSoftware opened this issue Dec 25, 2024 · 2 comments
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info t/bug Something isn't working

Comments

@IVSoftware
Copy link

Description

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.

Steps to Reproduce

  1. Set a breakpoint such that the jsonPayload can be inspected, to confirm that the code has been successfully returned using the Universal App Link as the redirect URL.
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. Go 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;
    }
}

Other details on verifying the integrity of the Universal App Link are (at least for now) available here: https://stackoverflow.com/q/79306670/5438626.


Workload list

> dotnet workload list

Installed Workload Id      Manifest Version       Installation Source
---------------------------------------------------------------------
android                    35.0.7/9.0.100         VS 17.12.35527.113
ios                        18.1.9163/9.0.100      VS 17.12.35527.113
maccatalyst                18.1.9163/9.0.100      VS 17.12.35527.113
maui-windows               9.0.0/9.0.100          VS 17.12.35527.113

Link to public reproduction project repository

No response

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

No response

Affected platforms

iOS

Affected platform versions

iPhone11 iOS 18.2

Did you find any workaround?

By reverting to a custom URI scheme, using an 'installed' credential for iOS, I can successfully connect to Google Drive.

Relevant log output

**Crash Log**

~~~plaintext
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
~~~
@IVSoftware IVSoftware added the t/bug Something isn't working label Dec 25, 2024
Copy link

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

@IVSoftware
Copy link
Author

IVSoftware commented Dec 25, 2024

I'm requesting guidance on site protocols please. Indeed, this appears to duplicate #21183 (sorry - I did search before posting). However that issue is closed.

It seems unlikely that a closed issue is going to be monitored closely, so I'm reoopening this thread to put it in the queue as something that is still going on. Again, I couldn't quite ascertain what the appropriate action is in this case, but feel free to point me in that direction.

@IVSoftware IVSoftware reopened this Dec 26, 2024
@PureWeen PureWeen added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants