main.py
#!/usr/bin/env/python
# -*- coding: utf-8 -*-
import json
try:
import requests
except ImportError:
print('[!] Please install the requests library')
print('[!] Example: pip install requests')
exit(1)
AUTH_URL = 'https://auth.developers.ar.ua.la'
TOKEN_URL = f'{AUTH_URL}/v2/api/auth/token'
class Auth:
def __init__(self, username: str, client_id: str, client_secret_id: str, grant_type: str) -> None:
self.username = username
self.client_id = client_id
self.client_secret_id = client_secret_id
self.grant_type = grant_type
def to_dict(self) -> dict:
return vars(self)
def to_json(self) -> str:
return json.dumps(self.to_dict())
def get_token(self):
try:
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
session = requests.Session()
response = session.post(
TOKEN_URL,
self.to_json(),
headers=headers)
return response.json()
except requests.exceptions.RequestException as e:
raise e('[!] Error while getting token')
if **name** == '**main**':
auth = Auth(
username='USERNAME',
client_id='CLIENT_ID',
client_secret_id='CLIENT_SECRET_ID_KEY',
grant_type='client_credentials'
)
response = auth.get_token()
print(json.dumps(response, indent=4))