示例#1
0
    def test_make_access_header(self):
        params = {
            "oauth_version": "1.0",
            "oauth_signature_method": "HMAC-SHA1",
            "oauth_timestamp": 1234567890,
            "oauth_nonce": "asdf1234",
            "oauth_consumer_key": "consumerasdf",
            "oauth_callback": "http://example.net/",
            "oauth_token": "tokenasdf",
        }
        signer = pyoauth.Signer("http", "GET", "localhost", 80, "/?%s" % pyoauth.url_encode(params))
        signer.realm = "admins"

        expected_header = ",".join(
            [
                'OAuth realm="admins"',
                'oauth_callback="http%3A%2F%2Fexample.net%2F"',
                'oauth_consumer_key="consumerasdf"',
                'oauth_nonce="asdf1234"',
                'oauth_signature="6xtmCsWZCcSky02%2BScTH7M%2FQvqw%3D"',
                'oauth_signature_method="HMAC-SHA1"',
                'oauth_timestamp="1234567890"',
                'oauth_token="tokenasdf"',
                'oauth_version="1.0"',
            ]
        )
        self.assertEquals(expected_header, signer.make_oauth_header())
示例#2
0
    def test_make_request_header(self):
        params = {
            "oauth_version": "1.0",
            "oauth_signature_method": "HMAC-SHA1",
            "oauth_timestamp": 1234567890,
            "oauth_nonce": "asdf1234",
            "oauth_consumer_key": "consumerasdf",
            "oauth_callback": "http://example.net/",
        }
        signer = pyoauth.Signer("http", "GET", "localhost", 80, "/?%s" % pyoauth.url_encode(params))
        signer.realm = "admins"

        expected_header = ",".join(
            [
                'OAuth realm="admins"',
                'oauth_callback="http%3A%2F%2Fexample.net%2F"',
                'oauth_consumer_key="consumerasdf"',
                'oauth_nonce="asdf1234",' 'oauth_signature="jxhGaw6dKp7PMHuy1P0TbyvfWqI%3D"',
                'oauth_signature_method="HMAC-SHA1"',
                'oauth_timestamp="1234567890"',
                'oauth_version="1.0"',
            ]
        )
        self.assertEquals(expected_header, signer.make_oauth_header())
示例#3
0
consumer_key = "YOUR KEY HERE"
consumer_secret = "YOUR SECRET HERE"

####################
# Request token step
####################
current_time = time()
params = {
    "oauth_callback": "oob",
    "oauth_consumer_key": consumer_key,
    "oauth_nonce": hashlib.sha1(str(current_time)).hexdigest(),
    "oauth_signature_method": "HMAC-SHA1",
    "oauth_timestamp": int(current_time),
    "oauth_version": 1.0,
}
signer = pyoauth.Signer("https", "POST", host, port, "%s?%s" % (request_token_url, pyoauth.url_encode(params)))
signer.consumer_secret_finder = lambda _x: consumer_secret
oauth_header = signer.make_oauth_header()

conn = httplib.HTTPSConnection(host, port)
conn.request("POST", request_token_url, "", {"Authorization": oauth_header})
response = conn.getresponse()
status = response.status
body = response.read()
response.close()
conn.close()
if status != 200:
    raise ValueError(body)

response_params = dict(parse_qsl(body))
request_token_key = response_params["oauth_token"]