Debian Codegraph @

keystoneclient/v3/contrib/oauth1/utils.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 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