I am somewhat novice at javascript, but I am trying to call a JSON web service that require basic authentication using jQuery (or anything that would work really).
I've not been able to come up with any real answers on Google. Is what I am trying to do possible?
With Basic Authentication, you pass your credentials (your Apigee account's email address and password) in each request to the Edge API. Basic Authentication is the least secure of the supported authentication mechanisms. Your credentials are not encrypted or hashed; they are Base64-encoded only.
Authentication JavaScript is nothing but JavaScript using the client ID to obtain Google ID token through Google Auth 2.0 server and then sending this generated token in request calls. Then the endpoint framework use client ID for authenticating the token ID that the JavaScript application has sent.
You will need to set the appropriate request header to pass the credentials. For example see here.
$.getJSON({
'url': 'http://host.com/action/',
'otherSettings': 'othervalues',
'beforeSend': function(xhr) {
//May need to use "Authorization" instead
xhr.setRequestHeader("Authentication",
"Basic " + encodeBase64(username + ":" + password)
},
success: function(result) {
alert('done');
}
});
FYI I searched Google for jquery post with basic auth
and this was the first link.
Here's the way to do it with jQuery for your copy and pasting needs:
$.ajax({
url: "/somewhere",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + window.btoa(username + ":" + password));
},
success: function(result) {
console.log(arguments);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With