Created
October 11, 2012 11:32
-
-
Save john2x/3871758 to your computer and use it in GitHub Desktop.
xero 2-legged oauth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test() { | |
var requestURL = "https://api.xero.com/api.xro/2.0/Accounts", | |
timestamp = (new Date().valueOf()/1000).toFixed(0), | |
nonce = createGuid(), | |
key = "consumer key from xero private app", | |
publickey = "content of publickey.cer", | |
requestData = { | |
"method": "GET", | |
"contentType": "application/xml", | |
"headers": { | |
"AUTHORIZATION": "OAuth realm=\"https://api.xero.com/\"," + | |
"oauth_consumer_key=\"" + key + "\"," + | |
"oauth_token=\"" + key + "\"," + | |
"oauth_signature_method=\"" + "RSA-SHA1" + "\"," + | |
"oauth_signature=\"" + publickey + "\"," + | |
"oauth_timestamp=\"" + timestamp + "\"," + | |
"oauth_nonce=\"" + nonce + "\"," + | |
"oauth_version=\"1.0\"", | |
"User-Agent": "my-private-app" | |
} | |
}; | |
var result = UrlFetchApp.fetch(requestURL, requestData); | |
Logger.log(result.getContentText()); | |
} | |
function createGuid() { | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); | |
return v.toString(16) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment