refresh problem in salesforce oauth 2 authentication.

You must Login before you can answer or comment on any questions.

I am able to get the access_token for the salesforce oath2. access token can expire after some time and after that we need to refresh the access token. But I am always getting "Bad Request" error in this code.

function getRefreshToken(refreshToken) {
    var url = loginUrl + 'token';
    var client = Ti.Network.createHTTPClient({
 
        // // function called when the response data is available
        onload : function(e) {
            Ti.API.info("Received text: " + this.ResponseText);
            alert(this.status);
            alert(this.responseText);
 
        },
        //  function called when an error occurs, including a timeout
        onerror : function(e) {
            Ti.API.debug(e.error);
            alert(this.status);
            alert(e.error);
        },
        timeout : 5000   //in milliseconds
    });
    //Prepare the connection.
    client.open("POST", url);
    client.setRequestHeader("content-type", "application/json");
    //Send the request.
    var param = 'grant_type=refresh_token&client_id=' + escape(clientId) + '&client_secret='+ escape(clientSecret) + '&refresh_token=' + escape(refreshToken);
    Ti.API.info(param);
    client.send(param);
 
}
am I missing something in this code? expected result is a json response with new access_token.

1 Answer

problem solved I need change the request header line.

client.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

Your Answer

Think you can help? Login to answer this question!