source: TI12-security/trunk/NDGSecurity/python/Tests/oauth2/sign_request.py @ 7756

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/Tests/oauth2/sign_request.py@7756
Revision 7756, 1.2 KB checked in by pjkersha, 10 years ago (diff)

Incomplete - task 16: NDG Security 2.x.x - incl. updated Paster templates

Line 
1import oauth2 as oauth
2import time
3
4if __name__ == "__main__":
5    # Set the API endpoint
6    url = "http://example.com/photos"
7   
8    # Set the base oauth_* parameters along with any other parameters required
9    # for the API call.
10    params = {
11        'oauth_version': "1.0",
12        'oauth_nonce': oauth.generate_nonce(),
13        'oauth_timestamp': int(time.time()),
14        'user': 'joestump',
15        'photoid': 555555555555
16    }
17   
18    # Set up instances of our Token and Consumer. The Consumer.key and
19    # Consumer.secret are given to you by the API provider. The Token.key and
20    # Token.secret is given to you after a three-legged authentication.
21    token = oauth.Token(key="tok-test-key", secret="tok-test-secret")
22    consumer = oauth.Consumer(key="con-test-key", secret="con-test-secret")
23   
24    # Set our token/key parameters
25    params['oauth_token'] = token.key
26    params['oauth_consumer_key'] = consumer.key
27   
28    # Create our request. Change method, etc. accordingly.
29    req = oauth.Request(method="GET", url=url, parameters=params)
30   
31    # Sign the request.
32    signature_method = oauth.SignatureMethod_HMAC_SHA1()
33    req.sign_request(signature_method, consumer, token)
34   
35    print req
Note: See TracBrowser for help on using the repository browser.