Created
October 25, 2012 22:32
-
-
Save alex-ethier/3955898 to your computer and use it in GitHub Desktop.
oauth request
This file contains 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
import requests | |
from requests.auth import OAuth1 | |
import json | |
client_key = u'9fac88f8645bdfbd6f8a68f60c5130d082244a8a8787674e82e85f68ff3716b8' | |
client_secret = u'bc0cd9097930832c6308e76ae3600b8d4aff47d2190df4960abc35208d291fc0' | |
headeroauth = OAuth1( | |
client_key, | |
client_secret, | |
None, | |
None, | |
signature_type='auth_header' | |
) | |
payload = { | |
"opType": "command_line", | |
"params": { | |
"command": "sleep 0" | |
} | |
} | |
url = u'http://localhost:8003/jobs' | |
data = json.dumps(payload, sort_keys=True, indent=4) | |
headers = {'content-type': 'application/json'} | |
r = requests.post(url, auth=headeroauth, data=data, headers=headers) | |
# Request result | |
# { | |
# 'Content-Length': '23', | |
# 'Accept-Encoding': 'gzip,deflate, compress', | |
# 'Accept': '*/*', | |
# 'User-Agent': 'python-requests/0.14.1 CPython/2.7.1 Darwin/11.4.2', | |
# 'Host': 'localhost:8003', | |
# 'Content-Type': 'application/json' | |
# } |
This file contains 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
require 'oauth' | |
require 'json' | |
client_key = '9fac88f8645bdfbd6f8a68f60c5130d082244a8a8787674e82e85f68ff3716b8' | |
client_secret = 'bc0cd9097930832c6308e76ae3600b8d4aff47d2190df4960abc35208d291fc0' | |
consumer = OAuth::Consumer.new(client_key, client_secret, { | |
:site => 'http://localhost:8003', | |
:scheme => :header | |
}) | |
payload = { | |
"job" => { | |
"opType"=> "command_line", | |
"params"=> { | |
"command"=> "sleep 0" | |
} | |
} | |
} | |
resp = consumer.request(:post, '/jobs', nil, {}, payload.to_json, {'content-type'=> 'application/json'}) | |
# Request result | |
# { | |
# 'Content-Length': '64', | |
# 'Host': 'localhost:8003', | |
# 'Accept': '*/*', | |
# 'User-Agent': 'OAuth gem v0.4.7', | |
# Connection': 'close', | |
# 'Content-Type': 'application/json', | |
# 'Authorization': 'OAuth oauth_body_hash="GGJhVEyTYM4tq1MJphxTH5pmGJ0%3D", | |
# oauth_consumer_key="9fac88f8645bdfbd6f8a68f60c5130d082244a8a8787674e82e85f68ff3716b8", | |
# oauth_nonce="oKH40kpd7e0VBYGIScBBViseEHavg5TXkMMcUKOY", | |
# oauth_signature="WwifhXaOrT861b1HjaDjozbfdD0%3D", | |
# oauth_signature_method="HMAC-SHA1", | |
# oauth_timestamp="1351233310", | |
# oauth_version="1.0"' | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment