-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathistsos_auth.py
104 lines (74 loc) · 2.53 KB
/
istsos_auth.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*- coding: utf-8 -*-
from . import settings
import requests
# Courtesy of: https://stackoverflow.com/a/1794540/1039510
join_url_path = lambda *pieces: "/".join(s.strip("/") for s in pieces)
class IstsosAuth(object):
"""docstring for IstsosAuth."""
url = None
headers = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"}
DEFAULTS = {"grant_type": "password", "client_id": "istsos-istsos"}
def __init__(self, username, password):
super(IstsosAuth, self).__init__()
self.args = dict(self.DEFAULTS, username=username, password=password)
def __call__(self):
response = requests.post(self.url, data=self.args, headers=self.headers)
return response
def json(self):
return self().json()
def get_token(self):
response = self()
return response.json()["access_token"]
class IstsosCeresioAuth(IstsosAuth):
""" """
url = join_url_path(
settings.ISTSOS_CERESIO_BASEURL, settings.ISTSOS_CERESIO_AUTH_ENDPOINT
)
def __init__(
self,
username=settings.ISTSOS_CERESIO_USERNAME,
password=settings.ISTSOS_CERESIO_PASSWORD,
):
super(IstsosCeresioAuth, self).__init__(username, password)
class IstsosVerbanoAuth(IstsosAuth):
""" """
url = join_url_path(
settings.ISTSOS_VERBANO_BASEURL, settings.ISTSOS_VERBANO_AUTH_ENDPOINT
)
def __init__(
self,
username=settings.ISTSOS_VERBANO_USERNAME,
password=settings.ISTSOS_VERBANO_PASSWORD,
):
super(IstsosVerbanoAuth, self).__init__(username, password)
class IstsosLarioAuth(IstsosAuth):
""" """
url = join_url_path(
settings.ISTSOS_LARIO_BASEURL, settings.ISTSOS_LARIO_AUTH_ENDPOINT
)
def __init__(
self,
username=settings.ISTSOS_LARIO_USERNAME,
password=settings.ISTSOS_LARIO_PASSWORD,
):
super(IstsosLarioAuth, self).__init__(username, password)
class IstsosVareseAuth(IstsosAuth):
""" """
url = join_url_path(
settings.ISTSOS_VARESE_BASEURL, settings.ISTSOS_VARESE_AUTH_ENDPOINT
)
def __init__(
self,
username=settings.ISTSOS_VARESE_USERNAME,
password=settings.ISTSOS_VARESE_PASSWORD,
):
super(IstsosVareseAuth, self).__init__(username, password)
def test():
# istsos = IstsosLarioAuth()
# istsos = IstsosVerbanoAuth()
istsos = IstsosCeresioAuth()
token = istsos.get_token()
print(token)
if __name__ == "__main__":
istsos = IstsosAuth()
token = istsos.get_token()