Debian Codegraph @

keystoneclient/v3/contrib/oauth1/auth.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10 # implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
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 # Add the oauth specific content into the headers
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