Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

WkWebViewRenderer and Blazor App with AAD Authentication via Microsoft.Identity.Web #14391

Open
wjvii opened this issue Jul 4, 2021 · 0 comments
Labels

Comments

@wjvii
Copy link

wjvii commented Jul 4, 2021

I am trying to use the Xamarin Forms WebView to open a Blazor website that is protected using MSAL and I need to set a custom header. From everything I read the best way to accomplish this was to use a custom WkWebViewRenderer. I went that route, and it works great on the Android side but not so well on the iOS side. On iOS the first time it fails, apparently when trying to authenticate or some combination of the custom header and the authentication but if I navigate away from the WebView page in the Xamarin iOS app and come back to it, it works as expected.

The custom renderer I am using is:

`public class HybridWebViewRenderer : WkWebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);

    if (e.NewElement != null)
    {
        WKWebView wkWebView = this;
        var headerKey = new NSString("Key");
        var headerValue = new NSString("BR549");
        var dictionary = new NSDictionary(headerKey, headerValue);
        var webRequest = new NSMutableUrlRequest(wkWebView.Url);
        webRequest.Headers = dictionary;
        LoadRequest(webRequest);
    }
}

}`

Is there something else I need to do on iOS WkWebViewRenderer to deal with the MSAL authentication from my Blazor web application?

Thank you in advance for any guidance.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants