Skip to content

Commit

Permalink
Change from urllib to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollins-ttd committed Jun 21, 2024
1 parent 8506445 commit 7d900ac
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = [
"requests",
"pycryptodome",
"bitarray"
]
Expand Down
2 changes: 1 addition & 1 deletion uid2_client/identity_map_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ def generate_identity_map(self, identity_map_input):
req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc),
identity_map_input.get_identity_map_input_as_json_string().encode())
resp = post(self._base_url, '/v2/identity/map', headers=auth_headers(self._api_key), data=req)
resp_body = parse_v2_response(self._client_secret, resp.read(), nonce)
resp_body = parse_v2_response(self._client_secret, resp.text, nonce)
return IdentityMapResponse(resp_body, identity_map_input)
4 changes: 2 additions & 2 deletions uid2_client/publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ def generate_token(self, token_generate_input):
req, nonce = make_v2_request(self._secret_key, dt.datetime.now(tz=timezone.utc),
token_generate_input.get_as_json_string().encode())
resp = post(self._base_url, '/v2/token/generate', headers=auth_headers(self._auth_key), data=req)
resp_body = parse_v2_response(self._secret_key, resp.read(), nonce)
resp_body = parse_v2_response(self._secret_key, resp.text, nonce)
return TokenGenerateResponse(resp_body)

def refresh_token(self, current_identity):
resp = post(self._base_url, '/v2/token/refresh', headers=auth_headers(self._auth_key),
data=current_identity.get_refresh_token().encode())
resp_bytes = base64_to_byte_array(resp.read())
resp_bytes = base64_to_byte_array(resp.text)
decrypted = _decrypt_gcm(resp_bytes, base64_to_byte_array(current_identity.get_refresh_response_key()))
return TokenRefreshResponse(decrypted.decode(), dt.datetime.now(tz=timezone.utc))
2 changes: 1 addition & 1 deletion uid2_client/refresh_keys_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _fetch_keys(base_url, path, auth_key, secret_key):
try:
req, nonce = make_v2_request(secret_key, dt.datetime.now(tz=timezone.utc))
resp = post(base_url, path, headers=auth_headers(auth_key), data=req)
resp_body = json.loads(parse_v2_response(secret_key, resp.read(), nonce)).get('body')
resp_body = json.loads(parse_v2_response(secret_key, resp.text, nonce)).get('body')
keys = _parse_keys_json(resp_body)
return RefreshResponse.make_success(keys)
except Exception as exc:
Expand Down
5 changes: 2 additions & 3 deletions uid2_client/request_response_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import base64
from importlib.metadata import version
import os
from urllib import request
import requests

from uid2_client.encryption import _encrypt_gcm, _decrypt_gcm

Expand Down Expand Up @@ -41,5 +41,4 @@ def parse_v2_response(secret_key, encrypted, nonce):


def post(base_url, path, headers, data):
req = request.Request(_make_url(base_url, path), headers=headers, method='POST', data=data)
return request.urlopen(req)
return requests.post(_make_url(base_url, path), data=data, headers=headers)

0 comments on commit 7d900ac

Please sign in to comment.