xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.53k stars 505 forks source link

Open uri with User and password #2069

Open gabrielrvd opened 1 year ago

gabrielrvd commented 1 year ago

Description

Hi, I try open a URL with user and password in Browser.OpenAsync() and the internal method "Browser.EscapeUri" intercept and create a new URI before call native plataform method and remove userinfo from the URI.

Original URI: http://user:password@www.example.com New URI create by Browser.EscapeUri: http://www.example.com

Why method EscapeUri exists? Is possible remove him?

If is not possible remove EscapeUri, create a new method that not call him.

Steps to Reproduce

  1. Open URI with user and password with Browser.OpenAsync(...)
  2. Browser prompt again for user and password

Expected Behavior

Not change URI

Actual Behavior

Remove user and password from new generated URI

Basic Information

Workaround

For now I call same internal method that Browser.OpenAsync run by reflection

var type = typeof(Xamarin.Essentials.Browser);
var method = type.GetMethod(
                 "PlatformOpenAsync",
                 BindingFlags.NonPublic
                 | BindingFlags.Public
                 | BindingFlags.Static
                 | BindingFlags.FlattenHierarchy)
             ?? throw new NotImplementedException(
                 "Método 'PlatformOpenAsync' não encontrado para a plataforma");

var task = (Task<bool>)method.Invoke(null, new[] { (object)uri, options });
await task;