Skip to content

Issue with Essentials.WebAuthenticator and multiple activities #22017

@koviant

Description

@koviant

Description

Hello,

I'd like to report an issue that I've encountered while using WebAuthenticator from the MAUI Essentials.

In order to open the link in the CustomTabs on Android, WebAuthenticator uses the CustomTabsActivityManager from the Xamarin.AndroidX.Browser nuget. Method CustomTabsActivityManager.From contains the following code:

static CustomTabsActivityManager instance;

public static CustomTabsActivityManager From(Activity parentActivity, string servicePackageName = null)
{
    if (instance == null) {
        instance = new CustomTabsActivityManager(parentActivity);
    }

    return instance;
}

Due to the static instance field of the manager, it forever holds the reference to the activity that was passed with the first call to that method. The problem happens when this activity was destroyed, and then the app tries to call WebAuthenticator again. CustomTabsActivityManager still holds the reference to the Activity that is no longer in use, and then WebAuthenticator fails to use CustomTabs and fallbacks to the default browser.

I've created a repo where you can reproduce the issue.

Also this issue was discussed in this issue in the Xamarin/AndroidX repository, and as the result of that, the From method was marked as obsolete.

Steps to Reproduce

  1. Download the repo
  2. Run the android app on the device that have browser, which supports CustomTabs (Chrome)
  3. Tap "Navigate to second activity" button
  4. Tap "Open Web Auth" button
  5. Verify that the CustomTab is open, user is not redirected to a browser app
  6. Go back to the repro app
  7. Tap "Go back", which would finish the second activity
  8. Tap "Navigate to second activity" button
  9. Tap "Open Web Auth" button

Expected result: link is still opened in the CustomTabs
Actual result: user is redirected to the browser app, CustomTabs are not open

Link to public reproduction project repository

https://github.com/koviant/DroidWebAuthRepro

Version with bug

8.0.20 SR4

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions