Now client wants to access all services offered by
example_services.com by Windows Authentication. Hence here both are
hosted on different domains(cross domain).
First, you are going to need to enable Cross Origin Resource Sharing. If you are unfamiliar with this concept, I refer you to RFC6454
Enabling CORS in WebAPI is really, really easy (it is in most web frameworks, actually).
You're going to want to reference System.Web.Cors
in your WebAPI Project. Then, to enable controller-based sharing, decorate your ApiController with the following attribute
using System.Web.Http;
namespace Example.WebAPI.Controllers
{
[EnableCors(origins:"example_client.com", headers:"*",methods:"*",SupportsCredentials=true)]
public class ExampleController : ApiController
{
//The kickers in that attribute are the "origins" and "SupportsCredentials"
//Note that SupportsCredentials is not supported with wildcard origins
}
}
What this does is set the [Access-Control-Allow-Origin] response header based on a valid [Origin] request header being set. Doing this should open up your WebAPI to your calling client.
As you might imagine, the "methods" property of the attribute allows you to lock down specific HttpVerbs to access.
How to pass credentials of an "logged on users" to service.
There is also a "SupportsCredentials" property on that attribute that would allow you to pass credentials with a request.
If you're trying to use NTLM Authentication, setting the "SupportsCredentials" property of the EnableCors attribute to true. This will enable the Access-Control-Allow-Credentials
HTTPHeader. Your credentials will not be sent down automagically, but you can send credentials by setting withCredentials: true
on your XHR.
If your client is comfortable with basic auth, you should be able to do that in this way:
$.ajax({
url: url,
data: {},
username: "corp.domain\corp.username"
password: "69iNgCh1pmunk5"
xhrFields: {
withCredentials: true
}
});
CORS and Windows Authentication
More About Origin, Access-Control-Allow-Origin, and CORS
Enabling Cross Origin Requests in Web API
Is it possible to bypass "windows authentication windows pop" every
time client tries to access any services.
You're likely looking for a Single Sign-On solution. They are non-trivial as well.
[Edit]
withCredentials and basicAuth properties on a CORS Enabled endpoint should bypass the challenge popup. I initially interpreted that question wrong.