I have implemented a sign in form an button in html:
<ons-buttononclick="login()">Sign in</ons-button>
The following Javascript is as follows:
var token_
var userName = "clientID";
var passWord = "secretKey"; // app clientSecret
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); // specify the credentials to receive the token on request
request.onreadystatechange = function () {
if (request.readyState == request.DONE) {
var response = request.responseText;
var obj = JSON.parse(response);
key = obj.access_token; //store the value of the accesstoken
token_ = key;
}
}
}
getToken(caspioTokenUrl, userName, passWord);
var login = function CallWebAPI() {
var params {"ClientID" : "username", "ClientSecret" : "password"};
var request_ = new XMLHttpRequest(params);
request_.open("GET", "https://xxx123.caspio.com/rest/v1/tables", true);
request_.setRequestHeader("Authorization", "Bearer "+ token_);
request_.send();
request_.onreadystatechange = function () {
if (request_.readyState == 4 && request_.readyState == 200) {
var response = request_.responseText;
var obj = JSON.parse(response);
}
}
}
It still does not work for me and I'm not quite sure what I am doing wrong.
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Question
MLaya
Hellow everyone,
I have implemented a sign in form an button in html:
The following Javascript is as follows:
var token_ var userName = "clientID"; var passWord = "secretKey"; // app clientSecret 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); // specify the credentials to receive the token on request request.onreadystatechange = function () { if (request.readyState == request.DONE) { var response = request.responseText; var obj = JSON.parse(response); key = obj.access_token; //store the value of the accesstoken token_ = key; } } } getToken(caspioTokenUrl, userName, passWord); var login = function CallWebAPI() { var params {"ClientID" : "username", "ClientSecret" : "password"}; var request_ = new XMLHttpRequest(params); request_.open("GET", "https://xxx123.caspio.com/rest/v1/tables", true); request_.setRequestHeader("Authorization", "Bearer "+ token_); request_.send(); request_.onreadystatechange = function () { if (request_.readyState == 4 && request_.readyState == 200) { var response = request_.responseText; var obj = JSON.parse(response); } } }
It still does not work for me and I'm not quite sure what I am doing wrong.
Any help is very much appreciated! Thank you all!
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.