xamarin / Xamarin.Auth

Xamarin.Auth
Apache License 2.0
541 stars 351 forks source link

ERR_UNKNOWN_URL_SCHEME #438

Open mjromka opened 4 years ago

mjromka commented 4 years ago

On some Android devices users get ERR_UNKNOWN_URL_SCHEME during authentication on redirect, see attachment:

8fb8f8be-5142-4d16-8ce2-546fb5919436 jpg 2020-04-25 00-27-07

Happened on Alcatel, Pop 4S and on some other model.

This is my intercepting intent: Activity(Label = "CustomUrlSchemeInterceptorActivity", NoHistory = true, LaunchMode = LaunchMode.SingleTop)] [IntentFilter( new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataSchemes = new[] { "***.co.identity.oauth" }, DataPath = "/oauth2redirect")] public class CustomUrlSchemeInterceptorActivity : Activity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); var uri = new Uri(Intent.Data.ToString()); new System.Threading.Tasks.Task(() => { var intent = new Intent(ApplicationContext, typeof(MainActivity)); intent.AddFlags(ActivityFlags.IncludeStoppedPackages); intent.AddFlags(ActivityFlags.ReorderToFront); StartActivity(intent); }).Start(); App.Authenticator.OnPageLoading(uri); Finish(); } }

It works fine on other devices although I see no appropriate automatically inserted into AndroidManifest.xml

mjromka commented 4 years ago

The issue seems to be only on Android <= 6.0 (Marshmallow) as it was also pointed here #395 Do you think you will take care of it one day or will wait until this Android version will be deprecated?

linehammer commented 3 years ago

This error is appeared because the WebView can’t recognize the URL Scheme,for example, the WebView will usually recognize only http and https, anything other than these. So WebView cannot parse it to right place, we should use intent to redirect the url. for example – intent://,market://,app://,mail:// etc will not be recognized by webview unless we add a handler to handle these url scheme or by disabling these schemes and only load http and https schemes.

This error has no any specific solution till now. Android user and PC user all are facing this error which needs to be sought out. There's a long-standing bug in Chromium regarding how links without protocols are handled. It occasionally is patched, but seems to keep resurfacing. In some cases, prefixing your links with http:// (or https://) should resolve the issue for you.

Also, in some cases, try to add target="_blank" in your URL Scheme/Code. for example:

<a href="mailto:my@email.com" target="_blank">Link Text</a>