Xamarin.Auth: Browser doesn't close itself on Android with native renderers

Xamarin.Auth Issue

IF BUG, INCLUDE THIS PART:

Version

  • nuget version = 1.5.0.3
  • Xamarin Forms = 2.3.4.270

Steps to reproduce

Call OAuth2Autenticator on Android with native renderers, using presenter or AuthenticatorPage. Custom URL scheme is registered

     OAuth2Authenticator authenticator = new OAuth2Authenticator(
              "mobile",
              "secret",
              "openid profile api1",
              new Uri(Settings.Server + "/connect/authorize"),
              new Uri("myapplogin://localhost/oauth2redirect"),
              new Uri(Settings.Server + "/connect/token"),
              null,
              true);
            authenticator.Completed += Authenticator_Completed;
            var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
            presenter.Login(authenticator);

`` Custom URL scheme interceptor Activity and Authenticator_Completed are called.

Platform:

  • [] .NET version = Xamarin 4.6.0.299
  • [] Android SDK = 7.1
  • [] Authentication server : custom platform using IdentityServer4
  • [] Android : tested on Moto X Android 6.0 with Chrome, and Visual Studio Android Emulator with Android 6.0 and Browser

Expected behaviour

Web browser should close itself after authentication

Actual behaviour

The web browser doesn’t close itself after authentication. This is working well on IOS (both native and not) and on Android when isUsingNativeUi=false

image

VS bug #733077, VS bug #1057144

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 6
  • Comments: 24 (5 by maintainers)

Most upvoted comments

@akamud Here is how I’ve been getting around this

[Activity(Label = "CustomUrlSchemeInterceptorActivity", NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
    [IntentFilter(
        new[] { Intent.ActionView },
        Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
        DataSchemes = new[] { "myapplogin" },
        DataPath = "/oauth2redirect")]
    public class CustomUrlSchemeInterceptorActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Convert Android.Net.Url to Uri
            global::Android.Net.Uri uri = Intent.Data;
           //This is the part that hides the Custom Tabs message
            CustomTabsConfiguration.CustomTabsClosingMessage = null;
            Uri uri_netfx = new Uri(uri.ToString());

            // Load redirectUrl page
            AppAuth.Authenticator.OnPageLoading(uri_netfx);

            //This is what forces the page to close.
            var intent = new Intent(this, typeof(MainActivity));
            intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            StartActivity(intent);

            this.Finish();

            return;
        }
    }

AuthTest.zip Here is a complete minimal sample with google login, showing that the login-browser doesn’t Close after successfully completing the login process.

Is anyone working on this?

Can you please tell us about this issue status? Should I use hacks to handle the issue myself or somebody gonna fix it soon in library?

Moving it to High Priority

In order to speed up the bugfixing, please add link to the repo with minimal sample (with removed sensitve data)

To switch back to the previous activity I used

var intent = new Intent(this, typeof(MainActivity)).SetFlags(ActivityFlags.ReorderToFront);
StartActivity(intent);

instead of

Finish();

@newky2k Still the same with latest version