Gazouu
Gazouu

Reputation: 382

Deep Linking inside WebView in Xamarin

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.

Upvotes: 3

Views: 1052

Answers (1)

Gazouu
Gazouu

Reputation: 382

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

Upvotes: 2

Related Questions