0

I am writing API automation via. MStest framework. The wsdl I am trying to automate takes Kerberos authentication. Even though I have provided client_Id, client_secret and user/pass authentication I am still getting 401 unauthorized error. As I am new to this, I might be asking something silly here but I didn't get any answer anywhere so far.

Exception : "The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'default'."

Inner Exception: "The remote server returned an error: (401) Unauthorized."

'''
[TestMethod]

    public void GetUsers()
    {
        APIClient= new AutoStudioFW.APIService.APIServiceclient();

        System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

       

        System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

        


        APIClient.ClientCredentials.UserName.UserName = "userabc";
        APIClient.ClientCredentials.UserName.Password = "passabc";

        _httpRequestProperty = new HttpRequestMessageProperty();
        _httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(APIClient.ClientCredentials.UserName.UserName + ":" + OrionAPIClient.ClientCredentials.UserName.Password));
        _httpRequestProperty.Headers.Add("client_id", "01ab34cd");
        _httpRequestProperty.Headers.Add("client_secret", "abc123secret");


        scope = new System.ServiceModel.OperationContextScope(APIClient.InnerChannel);


        System.ServiceModel.OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = _httpRequestProperty;
        

        var GetUser = APIClient.getCurrentUser("555");

    }

1 Answers1

0

You can try to set the security mode in the config:

<security mode="TransportCredentialOnly">
  <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
  <message clientCredentialType="UserName" algorithmSuite="Default" />
</security>

WCFTestClient The HTTP request is unauthorized with client authentication scheme 'Anonymous'

Lan Huang
  • 613
  • 2
  • 5