Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Authentication handling in javascript

var token_ // variable will store the token
var userName = "clientID"; // app clientID
var passWord = "secretKey"; // app clientSecret
var caspioTokenUrl = "https://xxx123.caspio.com/oauth/token"; // Your application token endpoint  
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; // store token in your global variable "token_" or you could simply return the value of the access token from the function
        }
    }
}
// Get the token
getToken(caspioTokenUrl, userName, passWord);
Comment

PREVIOUS NEXT
Code Example
Javascript :: display component in popup angular 8 
Javascript :: tutorial of machine learning js 
Javascript :: return this javascript 
Javascript :: location maps react native 
Javascript :: js while loop 
Javascript :: rxjs takeuntil 
Javascript :: upload file angular rest api 
Javascript :: javasccript this.innerHTML 
Javascript :: js regrex 
Javascript :: vue js override component css 
Javascript :: append item to array javascript 
Javascript :: js update query string without refresh 
Javascript :: frames[i] javascript 
Javascript :: usereduce 
Javascript :: web3.js tutorials 
Javascript :: utc clock 
Javascript :: jquery scroll to bottom of div 
Javascript :: react-native-shadow-generator 
Javascript :: asynchronous javascript 
Javascript :: type of jvascript data 
Javascript :: fastest way to check a number is palindrome 
Javascript :: js regular expression 
Javascript :: factory function vs constructor javascript 
Javascript :: datepicker range npm reactjs 
Javascript :: javascript loading animation on button click 
Javascript :: html-pdf nodejs 
Javascript :: metadata object ANGULAR 
Javascript :: nodejs ecommerce cms 
Javascript :: how to turn of autocomplete in react hook form material ui 
Javascript :: js concate map 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =