| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
import urllib.parse as urlparse |
| 15 |
|
| 16 |
|
| 17 |
OAUTH_PATH = '/OS-OAUTH1' |
| 18 |
|
| 19 |
|
| 20 |
def get_oauth_token_from_body(body): |
| 21 |
"""Parse the URL response body to retrieve the oauth token key and secret. |
| 22 |
|
| 23 |
The response body will look like: |
| 24 |
'oauth_token=12345&oauth_token_secret=67890' with |
| 25 |
'oauth_expires_at=2013-03-30T05:27:19.463201' possibly there, too. |
| 26 |
""" |
| 27 |
body = body.decode('utf-8') |
| 28 |
|
| 29 |
credentials = urlparse.parse_qs(body) |
| 30 |
key = credentials['oauth_token'][0] |
| 31 |
secret = credentials['oauth_token_secret'][0] |
| 32 |
token = {'key': key, 'id': key, 'secret': secret} |
| 33 |
expires_at = credentials.get('oauth_expires_at') |
| 34 |
if expires_at: |
| 35 |
token['expires'] = expires_at[0] |
| 36 |
return token |