auth0 / auth0-oidc-client-net

OIDC Client for .NET Desktop and Mobile applications
https://auth0.github.io/auth0-oidc-client-net/
Apache License 2.0
84 stars 49 forks source link

Login browser appears again after successfully login on Xamarin Forms (Android) #242

Closed juniorsaraviao closed 1 year ago

juniorsaraviao commented 1 year ago

Issue Report

Description

I found an issue and posted it on the Auth0 community. Also, I created a bug report in Auth0 Xamarin Sample

When the login is successful and the app is closed using the Phone back button, the login browser appears again (Auth0.OidcClient.AndroidX v3.2.6).

Expected behaviour

Close the login browser so that when pressing the Phone back button, the browser doesn't appear again.

Actual behaviour

The login browser appears again after pressing the Phone back button.

Steps to reproduce the problem

  1. Use the Auth0 Xamarin sample here or create a project following these steps.
  2. Log in with valid credentials.
  3. Press the phone back button on the bottom.
  4. The login browser appears again.

Language / Framework Versions

  1. Language used: C#
  2. Framework used: Xamarin forms (v5.0.0.2515)

Testing environment

  1. Operating system: Windows 10
  2. Browser version: Samsung A11 (Android 11) - Genymotion Custom Phone (Android 8)
frederikprijck commented 1 year ago

Thanks for reporting, sorry for missing the report on the Sample repository. I will look into this and see what could be causing it and how we can solve it.

frederikprijck commented 1 year ago

I opened a PR which I believe should address it. I have been able to, partly, reproduce it, and resolve it using that change.

Before being able to merge it, I will need to verify if it works in Xamarin Forms. But currently having some issues with my Windows machine.

Any chance you could also give that PR a try? Not sure u can build the project locally, and reference it in your project locally to verify it works for you as well?

In the meanwhile, I am looking into fixing my windows environment, which doesnt appear to be running the Xamarin Forms application.

juniorsaraviao commented 1 year ago

Hi @frederikprijck, just a question when could we have a new version that includes this change?

frederikprijck commented 1 year ago

I am currently working on another fix for this SDK, then I plan to cut a release. I would say somewhere this week.

frederikprijck commented 1 year ago

The release is out. Let me know if it would still not work!

juniorsaraviao commented 1 year ago

I just checked the new release version and the browser doesn't appear after pressing the back button. However, I saw the browser was still in the background if I pressed the overview button. Let me know if I should open a new issue for that

image

frederikprijck commented 1 year ago

Thanks, I will take another look to see how we can fix that.

frederikprijck commented 1 year ago

Any chance you can try out using your own browser as below? I am still having difficulties running Xamarin Forms and can not reproduce the behavior outside of Xamarin Forms.

    public class MyChromeCustomTabsBrowser : AndroidBrowserBase
    {
        /// <summary>
        /// Create a new instance of <see cref="MyChromeCustomTabsBrowser"/> for a given <see cref="Context"/>.
        /// </summary>
        /// <param name="context"><see cref="Context"/> provided to any subsequent callback.</param>
        public MyChromeCustomTabsBrowser(Context context = null)
            : base(context)
        {
        }

        /// <inheritdoc/>
        protected override void OpenBrowser(Android.Net.Uri uri, Context context = null)
        {
            using (var builder = new CustomTabsIntent.Builder())
            using (var customTabsIntent = builder.Build())
            {
                if (IsNewTask)
                    customTabsIntent.Intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.NoHistory | ActivityFlags.ClearTask);
                customTabsIntent.LaunchUrl(context, uri);
            }
        }
    }

Then pass this one as Browser when creating the Auth0Client instance.

new Auth0Client(new Auth0ClientOptions
{
    Browser = new MyChromeCustomTabsBrowser();
});

I will continue to try and fix running Xamarin.Forms, but might be good if you could give this a try to verify it works in your situation.

juniorsaraviao commented 1 year ago

I used the code above but the browser stayed in the background.

frederikprijck commented 1 year ago

I have been unable to reproduce the last behavior you mentioned here using the sample you mentioned as well.

Not sure what's causing this, but I am testing on a One Plus 10 physical device, as well as a Pixel Emulator, and both do not show the browser when clicking the overview button.

juniorsaraviao commented 1 year ago

I used the Genymotion Custom Phone Android v10 (emulator) and I saw the behavior described here. I'm not sure if this issue could be related to the Android OS. I also tested with a physical Samsung A53 (Android v13) and it didn't show the browser.

frederikprijck commented 1 year ago

I'm going to close this, happy to reopen if this would come up with other devices, but I can't reproduce it using a couple of different emulators and devices.