Debian Codegraph @

keystoneclient/v3/contrib/oauth1/access_tokens.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 keystoneauth1 import plugin
15
16 from keystoneclient import base
17 from keystoneclient.v3.contrib.oauth1 import utils
18
19 try:
20 from oauthlib import oauth1
21 except ImportError:
22 oauth1 = None
23
24
25 class AccessToken(base.Resource):
26 pass
27
28
29 class AccessTokenManager(base.CrudManager):
30 """Manager class for manipulating identity OAuth access tokens."""
31
32 resource_class = AccessToken
33
34 def create(self, consumer_key, consumer_secret, request_key,
35 request_secret, verifier):
36 endpoint = utils.OAUTH_PATH + '/access_token'
37 oauth_client = oauth1.Client(consumer_key,
38 client_secret=consumer_secret,
39 resource_owner_key=request_key,
40 resource_owner_secret=request_secret,
41 signature_method=oauth1.SIGNATURE_HMAC,
42 verifier=verifier)
43 url = self.client.get_endpoint(interface=plugin.AUTH_INTERFACE).rstrip(
44 '/')
45 url, headers, body = oauth_client.sign(url + endpoint,
46 http_method='POST')
47 resp, body = self.client.post(endpoint, headers=headers)
48 token = utils.get_oauth_token_from_body(resp.content)
49 return self._prepare_return_value(resp,
50 self.resource_class(self, token))