Jump to content

MLaya

Members
  • Content Count

    3
  • Joined

  • Last visited

Posts posted by MLaya

  1. Hello!

    I was wondering if anyone had any trouble when refreshing their access tokens?  I successfully authenticated my users through RESTful API, but now have trouble using the POST call advised from the how to guide on the website.

    Any feedback is greatly appreciated!

  2. Hello!

    I am using the HTTP basic authentication method for my mobile app and have followed the POST request as outlined on the website.  My ajax call is as follows:

     

    $(document).ready (function () {
         
         $('button').click(function () {
             var Client_ID = $('clientid').val();
             var Client_Secret = $('clientsecret').val(); 
            
            $.ajax ({
                type: 'POST',
                url: 'Token endpoint',
                data: 'grant_type=client_credentials',
                headers: {
                    'Authorization' : 'Basic Q2xpZW50X0lEOkNsaWVudF9TZWNyZXQ='
                },
                
                success: function(data) {
                    window.location.href = 'page1.html';
                },
            });
         });
         
         

    I encoded the string "Client_ID:Client_Secret" as advised too.  Upon checking my network console, I'm getting a 400 error.

    Can anyone help?

  3. Hellow everyone, 

    I have implemented a sign in form an button in html:

    <ons-button onclick="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.

    Any help is very much appreciated!  Thank you all!

×
×
  • Create New...