UWP Application setting default proxy with default windows authentication

Viewed 228

I have a UWP app that signs in using Azure AD. I deployed it to a customer site and it stopped logging in. They have a network with a proxy and I don't have access to their network, so I can't debug it properly. All the information I was provided is:

There's a proxy, you might want to use the default proxy settings. The proxy requires default windows authentication.

So with that information, here's what I've tried:

  1. Update my PublicApplicationBuilder to use a custom HttpClientFactory
this.publicClientApp = PublicClientApplicationBuilder.Create(ClientId)
     .WithAuthority(Authority)
     .WithHttpClientFactory(new MsalHttpClientFactory())
     .OtherNonRelevantMethods()
     .Build();
  1. I created a custom implementation of IMsalHttpClientFactory which attempts to set the proxy. There's a function, GetHttpClient which should setup (as the name says) an HttpClient object with all the necesary configuration
private HttpClient GetHttpClient()
{
     var handler = new HttpClientHandler();
     handler.UseProxy = true;
     handler.UseDefaultCredentials = true;
     return new HttpClient(handler);
}

This doesn't seem to work. It was my first attempt at using both the default proxy and default windows credentials.

I have also tried to manually set the proxy credentials with the following code

private HttpClient GetHttpClient()
{
     var handler = new HttpClientHandler();
     handler.UseProxy = true;
     handler.DefaultProxyCredentials = CredentialCache.DefaultCredentials
     return new HttpClient(handler);
}

But it seems to do the same thing, and therefore doesn't work.

And finally I tried to manually retrieve the proxy from WebRequest and Credentials from CredentialCache but again... no luck.

private HttpClient GetHttpClient()
{
     var handler = new HttpClientHandler();
     handler.UseProxy = true;
     handler.Proxy = WebRequest.DefaultWebProxy;
     handler.Proxy.Credentials = CredentialCache.DefaultCredentials;
     return new HttpClient(handler);
}

I'm unfortunately running out of ideas, I have been able to make this work by running it through Telerik Fiddler, so obviously Fiddler can reach the proxy just fine and when Fiddler operates as a man in the middle, my application works fine. But I can't simply ask them to run fiddler every time haha

Do you have any ideas? Am I missing something super easy?

Thanks

1 Answers

I'm afraid Proxy does not work in UWP platform. please refer to blog here.

For both APIs, proxy settings are automatically obtained from Internet Explorer/Microsoft Edge settings and are used for all the HTTP calls by default. This enables apps to automatically work even if the user is connected to the internet through a proxy. Neither API provides a way to specify a custom proxy for your app. However, you can choose to not use the default proxy by setting HttpClientHandler.UseProxy to false (for System.Net.Http) or HttpBaseProtocolFilter.UseProxy to false (for Windows.Web.Http).

So we can't use a custom proxy for a single HTTP request by now. If you do want this please feel free post your feature request with windows feed back hub app.

Related