Dave351
Dave351

Reputation: 41

Windows authentication using AD group in Asp.net WebApi not working

I have a developed a Restful webservice using Asp.net WebAPI and used the windows authentication in the web.config file. This WebService is called by inhouse windows application in the internal network. Now the problem is when i send the request from the IE browser to the webService it authentication and authorization works fine. but when i send the request through the Widows application the user are not authenticated. scenario : When i use below config, The Request from the webbrowser is authenticated correctly, But request from windows application are not authenticated even if users are in correct AD group with correct roles.

   <authentication mode="Windows"/>
    <authorization>
       <allow roles = "someGroup1"/>
       <allow roles = "Somegroup2"/>
       <deny users="*" />
    </authorization>

what could be the problem please provide any suggestion.

Upvotes: 1

Views: 2622

Answers (1)

Dave351
Dave351

Reputation: 41

I found out the problem, The windows client was not sending the User Information to the Webhost so the authentication and Authorization was failing. Since I was using NTML Authentication, so to resolve this issue i had to add a Authenticator to the restClient as below:

var client = new RestClient();
     client.BaseUrl = ServiceUrl;
     client.RemoveHandler("application/json");
     client.RemoveHandler("text/json");
     **client.Authenticator = new NtlmAuthenticator();** 

Upvotes: 3

Related Questions