Skip to content

Commit

Permalink
refactor: I was besting the request
Browse files Browse the repository at this point in the history
  • Loading branch information
calenzo committed Mar 21, 2023
1 parent 2228d01 commit fc1fb1a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/balance_nubank/utils/certificate_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ def __init__(self, login, password, device_id, encrypted_code=None):
self.url = discovery.get_app_url('gen_certificate')

def request_code(self) -> str:
response = requests.post(self.url, json=self._get_payload())
try:
response = requests.post(self.url, json=self._get_payload())

print('balance_nubank response ->', response)
print('balance_nubank ->', response.json())

if response.status_code != 401 or not response.headers.get('WWW-Authenticate'):
raise NuException('Authentication code request failed.')

parsed = self._parse_authenticate_headers(response.headers.get('WWW-Authenticate'))
self.encrypted_code = parsed.get('device-authorization_encrypted-code')
parsed = self._parse_authenticate_headers(response.headers.get('WWW-Authenticate'))
self.encrypted_code = parsed.get('device-authorization_encrypted-code')
return parsed.get('sent-to')

return parsed.get('sent-to')
finally:
raise NuException('Authentication code request failed.')

def exchange_certs(self, code: str):
if not self.encrypted_code:
Expand Down

0 comments on commit fc1fb1a

Please sign in to comment.