-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.py
executable file
·64 lines (48 loc) · 1.87 KB
/
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
import threading
from time import sleep
import requests
import logging
import json
logging.basicConfig(level=logging.DEBUG)
class AuthenticationDaemon(threading.Thread):
logger = logging.getLogger('auth_daemon')
AUTH_URL = 'https://myaussie-auth.aussiebroadband.com.au/'
token = None
expiration = None # TODO: Implement expiration monitor for token refresh
cookie = None
username = ''
password = ''
def __init__(self, *args, **kwargs):
self.logger.debug('Initializing')
super().__init__(args=args, kwargs=kwargs)
def login(self):
self.logger.debug('Logging user in')
auth = requests.post(self.AUTH_URL + 'login', json={'username': self.username, 'password': self.password})
response_data = json.loads(auth.content)
if auth.status_code != 200:
self.logger.critical('Auth failed')
raise Exception('Failed to auth user')
self.token = response_data['refreshToken']
self.expiration = response_data['expiresIn']
self.cookie = auth.headers['Set-Cookie'].split(';')[0]
class Client:
logger = logging.getLogger('client')
API_URL = 'https://myaussie-api.aussiebroadband.com.au/'
customer = None
header = None
def __init__(self):
self.logger.debug('Initializing')
self.authentication = AuthenticationDaemon(daemon=True)
self.authentication.login()
while not self.authentication.token:
pass
self.logger.debug('Authed user and initialized Client')
self.header = {'Cookie': self.authentication.cookie}
def get_customer(self):
response = requests.get(self.API_URL + 'customer', headers=self.header)
self.logger.info('Refreshed Customer info')
self.customer = json.loads(response.content)
client = Client()
client.get_customer()
print(client.customer['services'])
sleep(5)