-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobtentoken.py
54 lines (43 loc) · 1.29 KB
/
obtentoken.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import requests
def get_token(APP_ID, SECRET, IYO_URL):
"""
:return: Regresa los headers para poder hacer las llamadas a las apis de GIG
Utiliza las variables de IYO_URL, APP_ID y SECRET
"""
data = {
'grant_type': 'client_credentials',
'client_id': APP_ID,
'client_secret': SECRET,
'response_type': 'id_token'
}
print (data)
print (IYO_URL)
iyo_token = requests.post(IYO_URL, data=data)
headers = {
'Accept': 'application/json',
'Authorization': "bearer {0}".format(iyo_token.text)
}
if iyo_token.status_code == requests.codes.ok:
myheaders = {
'Accept': 'application/json',
'Authorization': "bearer %s" % (iyo_token.text),
}
else:
print("no se obtuvieron el token de acceso")
myheaders = {
'Accept': 'application/json',
'Authorization': "bearer %s" % (iyo_token.text)
}
return iyo_token.text
def get_headers_js(token):
myheaders = {
'Accept': 'application/json',
'Authorization': "bearer %s" % (token),
}
return myheaders
def get_headers_os(token):
myheaders = {
'Accept': 'application/octet-stream',
'Authorization': "bearer %s" % (token),
}
return myheaders