Search code examples
jqueryiosweb-servicescordovawindows-authentication

PhoneGap - Windows Authentication Request with JQuery


I am trying to access a webservice that has Windows authentication. I am basically using most of what is written on this page:

$.ajax({
    url: url,
    method: 'GET',
    async: true,
    data: {},
    dataType: 'json',
    crossDomain: true,
    xhrFields: {
        withCredentials: true
    },
    beforeSend: function(xhr) {
        // set authorization header
        xhr.setRequestHeader("Authorization", "Basic " + Base64.encode(username + ":" + password));
    },
    success: function(data){
                // success
    },
    error: function(request, status, error) {
        // handle problem
    }
});

I also defined the external hosts on the .plist file. My issue is that I always get an error. To make it worst, nothing comes out on the error function that is slightly useful (this output is from Firefox, to simplify):

Object { readyState=0, status=0, statusText="error"}

I also tried on the simulator, but instead of immediately giving me the error I think its timing out. What I have been seeing, and what I am using, is a request using Basic authentication. So is there a way to actually implement this using Windows authentication?


Solution

  • In the end what I did:

     $.ajax( {
                                 url:webServiceLink,
                                 method: "GET",
                                 timeout:30000,
                                 data: "{}",  
                                 dataType: "xml",
                                 beforeSend : function(req) {
                                 req.setRequestHeader("Authorization", 
                                                      make_base_auth (username,password));                             
                                 },
                                 success: OnGetMemberSuccess,
                                 error: OnGetMemberError
                                 });
                          });
    

    In the external hosts I putted: *.


    Update 1.0: Stopped working again...

    Update 2.0 Found the issue:

    The base 64 encoding is accepting the following chars:

    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    If you put a login/password with something else, you will have problems. :)