Skip to content

WCF client credentials are not used for proxy authentication #3551

Closed
@Darkmace

Description

@Darkmace

When passing a WCF client request through a proxy requiring username/password authentication, the clients ClientCredentials are not used and it results in a "(407) Proxy Authentication Required" error. There does not appear to be any way in dotnet core to set whether to use default credentials or not for the proxy.

var binding = new BasicHttpBinding();

            binding.Security.Mode = BasicHttpSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

            binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
            binding.UseDefaultWebProxy = false;
            binding.ProxyAddress = new Uri("http://proxyURL.com:9293");

            using (var webClient = new CustomWCFClient(binding, "endpoint")))
            {
                webClient.ClientCredentials.ClientCertificate.Certificate = Certificate;
                webClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust;
                var xmlString = XmlString(xml);

                webClient.ClientCredentials.UserName.UserName = "username";
                webClient.ClientCredentials.UserName.Password = "password";

                var requestResult = webClient.sendMessage("anystring");
            }

A work around exists to get the proxy credentials working by creating a CustomBinding

var binding = new BasicHttpBinding();

            binding.Security.Mode = BasicHttpSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; 
           
            var customBinding = new CustomBinding(binding);
            var httpElement = customBinding.Elements.Find<HttpTransportBindingElement>();
            httpElement.ProxyAddress = new Uri("http://proxyURL.com:9293");
            httpElement.ProxyAuthenticationScheme = AuthenticationSchemes.Basic;
            httpElement.UseDefaultWebProxy = false;

This results in the SendMessage request throwing an "The HTTP request was forbidden with client authentication scheme 'Anonymous" exception. There does not seem to be a way to configure the CustomBinding to use certificate authentication for the final endpoint.

This makes it seemingly impossible to interact with a WCF service that requires certificate authentication through a proxy requiring username/password authentication.

Metadata

Metadata

Assignees

Labels

BacklogLegitimate tasks of lower priority not in current dev schedule.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions