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

Issue with Essentials.WebAuthenticator and multiple activities #22017

Open
koviant opened this issue Apr 23, 2024 · 2 comments · May be fixed by #22018
Open

Issue with Essentials.WebAuthenticator and multiple activities #22017

koviant opened this issue Apr 23, 2024 · 2 comments · May be fixed by #22018
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/android 🤖 t/bug Something isn't working

Comments

@koviant
Copy link

koviant commented Apr 23, 2024

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

@koviant koviant added the t/bug Something isn't working label Apr 23, 2024
@koviant koviant linked a pull request Apr 23, 2024 that will close this issue
@Eilon Eilon added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label Apr 30, 2024
@PureWeen
Copy link
Member

PureWeen commented May 2, 2024

/similarissues

Copy link
Contributor

github-actions bot commented May 2, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

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 platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants