api calling from web application ajax (401 unauthorize error). all cookie get in api ,in this cookie access token available but api will not authorize in this code used a withCredentials: true and using identity server 6
web application ajax code below hare
$(document).ready(function () {
GetData();
function GetData() {
$.ajax({
type: "GET",
url: "https://localhost:7129/Customer",
crossDomain: true,
xhrFields: {
withCredentials: true
},
dataType: "json",
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "*",
'Content-Type': 'application/json'
},
credentials: 'include',
success: function (data)
{
alert(JSON.stringify(data));
}); //End of foreach Loop
}, //End of AJAX Success function
failure: function (data) {
alert( "failure " + data.responseText);
}, //End of AJAX failure function
error: function (xhr, status, error) {
// Handle the error
console.log("AJAX request failed.");
console.log("Status: " + status);
console.log("Error: " + error);
} //End of AJAX error function
});
}
});
in this ajax code send access token in header api authorize successful
headers: {
"Authorization": "Bearer " + "Access Token",
},
but cookie base authorize not working getting (error 401 unauthorize)
solving this error 401 unauthorized when calling api from web appllication