我正在使用dotnet core 1.1.2构建RESTful API.
这个api的很大一部分需要向外部WCF服务发出请求.这些请求使用基于Windows的身份验证与用户名,密码和域进行身份验证.
我目前正在准备api生产,我想尝试将它停靠.
我遇到的问题是,一旦从docker容器中调用它,就会对第三方WCF服务进行身份验证失败.使用dotnet运行时运行API可以从windows和mac运行,并且服务将按照应有的方式进行身份验证.
我使用Visual Studio 2017的Connect wcf服务功能使用WCF服务,然后使用正确的身份验证模式修改端点绑定.
public ServiceSoapClient(EndpointConfiguration endpointConfiguration, string username, string password, string domain) :
base(ServiceSoapClient.GetBindingForEndpoint(endpointConfiguration), ServiceSoapClient.GetEndpointAddress(endpointConfiguration))
{
this.ChannelFactory.Credentials.Windows.ClientCredential.UserName = username;
this.ChannelFactory.Credentials.Windows.ClientCredential.Password = password;
this.ChannelFactory.Credentials.Windows.ClientCredential.Domain = domain;
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.ServiceSoap))
{
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
result.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
return result;
}
throw new System.InvalidOperationException(string.Format("Could not …Run Code Online (Sandbox Code Playgroud) 我正在构建一个我正在构建的Web应用程序的问题.Web应用程序由一个有角度的4前端和一个dotnet核心RESTful api后端组成.其中一个要求是需要使用SSL相互身份验证对后端的请求进行身份验证; 即客户证书.
目前我将前端和后端托管为Azure应用服务,它们位于不同的子域中.
后端设置为需要客户端证书,遵循本指南,我认为这是为Azure应用程序服务执行此操作的唯一方法:https: //docs.microsoft.com/en-us/azure/app-service/app-服务网络的配置-TLS-互AUTH
当前端向后端发出请求时,我设置withCredentials为true- [根据文档] [1],也应该使用客户端证书.
XMLHttpRequest.withCredentials属性是一个布尔值,指示是否应使用cookie,授权标头或TLS客户端证书等凭据进行跨站点访问控制请求.设置withCredentials对同一站点请求没有影响.
来自前端的相关代码:
const headers = new Headers({ 'Content-Type': 'application/json' });
const options = new RequestOptions({ headers, withCredentials: true });
let apiEndpoint = environment.secureApiEndpoint + '/api/transactions/stored-transactions/';
return this.authHttp.get(apiEndpoint, JSON.stringify(transactionSearchModel), options)
.map((response: Response) => {
return response.json();
})
.catch(this.handleErrorObservable);
Run Code Online (Sandbox Code Playgroud)
在Chrome上,这是有效的,当发出请求时,浏览器会提示用户输入证书,并且它会包含在预检请求中,一切正常.
然而,对于所有其他主要浏览器,情况并非如此.Firefox,Edge和Safari都会使预检请求失败,因为服务器在请求中不包含客户端证书时会关闭连接.
直接浏览到api端点会使每个浏览器都提示用户输入证书,因此我非常确定这与大多数浏览器如何使用客户端证书处理预检请求明确相关.
我做错了什么?或者其他浏览器是否通过在发出请求时不提示输入证书而做错了?
我需要支持除Chrome以外的其他浏览器,所以我需要以某种方式解决这个问题.
我已经看到类似的问题通过后端允许而不是需要证书来解决.唯一的问题是我还没有找到一种方法来实际使用Azure应用服务.它要么需要要么不要求.
有没有人对我如何继续前进有任何建议?