-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
28 lines (22 loc) · 862 Bytes
/
utils.py
File metadata and controls
28 lines (22 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
sys.path.insert(1, 'Swagger')
import json
import requests
import swagger_client
CLIENT_ID = 'clientId'
CLIENT_SECRET = 'clientSecret'
HOST = "https://api.globalforester.com"
def get_access_token():
token_url = 'https://auth2.globalforester.com/oauth2/token'
grant_type='client_credentials'
headers = {'Content-Type':'application/x-www-form-urlencoded'}
basic_auth = requests.auth.HTTPBasicAuth(CLIENT_ID, CLIENT_SECRET)
response = requests.post(token_url, params={'grant_type':grant_type}, headers = headers, auth=basic_auth)
resp_json = json.loads(response.text)
access_token=resp_json['access_token']
return access_token
def configure_swagger_client():
configuration = swagger_client.Configuration()
configuration.access_token = get_access_token()
configuration.host = HOST
return configuration