oAuth token request fails, returns "403: Forbidden"


#1

Here’s my source:

Tiles
Click Me!

The sendPostRequestWithAuth method is as follows:

function sendPostRequestWithAuth(url, params, auth, onComplete)
{
xmlHttpReq.open(“POST”, url, true);
xmlHttpReq.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);
xmlHttpReq.setRequestHeader(“Content-Length”, params.length);
xmlHttpReq.setRequestHeader(“Authorization”, "OAuth " + auth);
xmlHttpReq.onreadystatechange = function() {
if(xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200)
onComplete(xmlHttpReq.responseXML);
else if(xmlHttpReq.readyState == 4)
alert(xmlHttpReq.getResponseHeader(“oauth_token”) + xmlHttpReq.status);
};
xmlHttpReq.send(params);
}

Firefox initiates a preflight (because of the Authorization header, though it’s not documented), then I get a 403. What’s wrong?


#2

Usage of OAuth from Javascript in a browser environment is extremely frowned upon. Client-side Javascript is not an appropriate environment for OAuth 1.0A. Please use a server-based solution for OAuth or otherwise use Web Intents if you prefer a client-side integration.


#3

I know. I am new into this, and this is for learning purpose.


#4

I’m having the same problem.
I’m needs in Javascript , any solution?