Hi Have been creating an ASP.net WebApi.
Currently I have used the Thinktecture.IdentityModel.40 to setup a Basic Authentication Service.
When I browse to my API Url in the browser, a username and password dialog popup and if I enter the credentials, I then see the correct data.
I would now like to create a javascript client using JQuery to authenticate to my API and then return the relevant data.
Here is my attempt, it appears that the username and password are not getting to the server or the server is not understanding what it is getting.
Here is my Code:
$(document).ready(function () {
$.ajax({
url: "http://localhost:21095/api/customers",
beforeSend: function (xhr) {
xhr.setRequestHeader("UserName", "user");
xhr.setRequestHeader("Password", "pwd");
},
dataType: "jsonp",
type: "GET",
success: function (data) {
alert(data);
debugger
}
});
});
How should I authenticate to my api using Jquery