How can I pass windows authentication to webservice using jQuery?

I think nowadays you can just set the withCredentials property of the request object to true, e.g.:

$.ajax({
    type: "GET",
    url: service_url,
    dataType: "xml",
    data: "ParamId=" + FormId.value,
    processData: false,
    xhrFields: {
        withCredentials: true
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) { ajaxError(XMLHttpRequest, textStatus, errorThrown); },
    success: function(xml) { DoSomething(xml); }
});

That causes existing authentication headers/cookies to be passed along in the AJAX request, works for me. No need to do your own Base encoding, etc.

Leave a Comment