I'm trying to use Amazon Cognito oauth2 in my Xamarin application but I have a problem.
I have this code to open my URL inside the WebView :
var browser = new WebView
{
Source = "https://[domain].auth.[region].amazoncognito.com/oauth2/authorize?client_id=[client_id]&response_type=code&redirect_uri=myapplication://home&scope=[scope]"
}
Content = browser;
I'm able to load the page in the WebView but, when the WebView tries to load the redirect_uri (myapplication://home) I got an Android Error Page "WebPage not available" with the error : net::ERR_UNKNOWN_URL_SCHEME.
Also, When I'm using Device.OpenUri([my_uri]) everything works well.
I'm using Android 8.0 to test my application.
I resolved my issue by adding this code before Content = browser :
browser.Navigating += async (s, e) =>
{
if (e.Url.StartsWith("myapplication://home"))
{
Uri uri = new Uri(e.Url);
((App)(Application.Current)).NavigateToLoginPage(uri);
}
};
NavigateToLoginPage(Uri uri) is just a basic function that change the MainPage in App.xaml.cs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With