vanilla js authentication code example
Example: Authentication handling in javascript
var token_
var userName = "clientID";
var passWord = "secretKey";
var caspioTokenUrl = "https://xxx123.caspio.com/oauth/token";
var request = new XMLHttpRequest();
function getToken(url, clientID, clientSecret) {
var key;
request.open("POST", url, true);
request.setRequestHeader("Content-type", "application/json");
request.send("grant_type=client_credentials&client_id="+clientID+"&"+"client_secret="+clientSecret);
request.onreadystatechange = function () {
if (request.readyState == request.DONE) {
var response = request.responseText;
var obj = JSON.parse(response);
key = obj.access_token;
token_ = key;
}
}
}
getToken(caspioTokenUrl, userName, passWord);