| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
from keystoneclient.auth.identity import v3 |
| 15 |
|
| 16 |
try: |
| 17 |
from oauthlib import oauth1 |
| 18 |
except ImportError: |
| 19 |
oauth1 = None |
| 20 |
|
| 21 |
|
| 22 |
class OAuthMethod(v3.AuthMethod): |
| 23 |
"""OAuth based authentication method. |
| 24 |
|
| 25 |
:param string consumer_key: Consumer key. |
| 26 |
:param string consumer_secret: Consumer secret. |
| 27 |
:param string access_key: Access token key. |
| 28 |
:param string access_secret: Access token secret. |
| 29 |
""" |
| 30 |
|
| 31 |
_method_parameters = ['consumer_key', 'consumer_secret', |
| 32 |
'access_key', 'access_secret'] |
| 33 |
|
| 34 |
def __init__(self, **kwargs): |
| 35 |
super(OAuthMethod, self).__init__(**kwargs) |
| 36 |
if oauth1 is None: |
| 37 |
raise NotImplementedError('optional package oauthlib' |
| 38 |
' is not installed') |
| 39 |
|
| 40 |
def get_auth_data(self, session, auth, headers, **kwargs): |
| 41 |
|
| 42 |
oauth_client = oauth1.Client(self.consumer_key, |
| 43 |
client_secret=self.consumer_secret, |
| 44 |
resource_owner_key=self.access_key, |
| 45 |
resource_owner_secret=self.access_secret, |
| 46 |
signature_method=oauth1.SIGNATURE_HMAC) |
| 47 |
o_url, o_headers, o_body = oauth_client.sign(auth.token_url, |
| 48 |
http_method='POST') |
| 49 |
|
| 50 |
headers.update(o_headers) |
| 51 |
return 'oauth1', {} |
| 52 |
|
| 53 |
|
| 54 |
class OAuth(v3.AuthConstructor): |
| 55 |
_auth_method_class = OAuthMethod |