Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import time, os, base64, urllib;
CONSUMER_KEY='xxxxxxxxxxxxxxxx'
CONSUMER_SECRET='xxxxxxxxxxxxxxxxxxxxxxxxx'
TIMESTAMP=str(int(time.time()));
ONCE=base64.b64encode(TIMESTAMP);
BASE_URL="https://api.xero.com/api.xro/2.0/organisation"
BASE_URL_ENCODED=urllib.quote_plus(BASE_URL);
# Notice I have taken the care to sort the name=value pairs alphabetically
REQUEST="oauth_consumer_key=" + CONSUMER_KEY + "&oauth_nonce=" + ONCE + "&oauth_signature_method=RSA-SHA1&oauth_timestamp=" + TIMESTAMP + "&oauth_token=" + CONSUMER_KEY
REQUEST_ENCODED=urllib.quote_plus(REQUEST);
SIG_TEXT="GET&" + BASE_URL_ENCODED + "&" + REQUEST_ENCODED
temp = open("text.txt", "wb");
temp.write(SIG_TEXT);
temp.close();
os.system("cat text.txt | openssl dgst -sha1 -sign privatekey.pem -binary > signature.bin")
SIG_BIN = open( "signature.bin", 'r' ).read()
SIGNATURE=base64.b64encode(SIG_BIN);
URL=BASE_URL+ "?" + REQUEST + "&oauth_signature=" + SIGNATURE;
print "Consumer Key: " + CONSUMER_KEY;
print "Unix epoch time: " + TIMESTAMP;
print "Once key: " + ONCE;
print "Base URL: " + BASE_URL;
print "Base URL encoded: " + BASE_URL_ENCODED;
print "Request parameters: " + REQUEST;
print "Request parameters encoded: " + REQUEST_ENCODED;
print "Text that we sign: " + SIG_TEXT;
#print "Signature binary: " + SIG_BIN;
print "Signature: " + SIGNATURE;
print "Complete Request: " + URL
print "Result..."
os.system('curl --pubkey publickey.cer --key privatekey.pem "' + URL + '"');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.