简体   繁体   English

UWP 应用程序设置默认代理,默认 windows 身份验证

[英]UWP Application setting default proxy with default windows authentication

I have a UWP app that signs in using Azure AD.我有一个使用 Azure AD 登录的 UWP 应用程序。 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.代理需要默认的 windows 身份验证。

So with that information, here's what I've tried:因此,有了这些信息,这就是我尝试过的:

  1. Update my PublicApplicationBuilder to use a custom HttpClientFactory更新我的PublicApplicationBuilder以使用自定义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.我创建了一个尝试设置代理的IMsalHttpClientFactory的自定义实现。 There's a function, GetHttpClient which should setup (as the name says) an HttpClient object with all the necesary configuration有一个 function, GetHttpClient应该设置(如名称所示)一个具有所有必要配置的HttpClient object
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.这是我第一次尝试同时使用默认代理和默认 windows 凭据。

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.最后,我尝试从WebRequest手动检索代理,从CredentialCache手动检索凭据,但又一次......没有运气。

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.不幸的是,我没有想法了,我已经能够通过 Telerik Fiddler 运行它来完成这项工作,所以显然 Fiddler 可以很好地到达代理,当 Fiddler 作为中间人运行时,我的应用程序运行良好。 But I can't simply ask them to run fiddler every time haha但我不能简单地要求他们每次都运行 fiddler 哈哈

Do you have any ideas?你有什么想法? Am I missing something super easy?我错过了一些超级简单的东西吗?

Thanks谢谢

I'm afraid Proxy does not work in UWP platform.恐怕代理在 UWP 平台上不起作用。 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.对于这两个 API,代理设置会自动从 Internet Explorer/Microsoft Edge设置中获取,并默认用于所有 HTTP 调用。 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. API 都没有提供为您的应用程序指定自定义代理的方法。 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).但是,您可以通过将 HttpClientHandler.UseProxy 设置为 false(对于 System.Net.Http)或 HttpBaseProtocolFilter.UseProxy 设置为 false(对于 Windows.Web.Http)来选择不使用默认代理。

So we can't use a custom proxy for a single HTTP request by now.所以我们现在不能对单个 HTTP 请求使用自定义代理。 If you do want this please feel free post your feature request with windows feed back hub app.如果您确实想要这个,请随时使用 windows 反馈中心应用程序发布您的功能请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM