Skip to content

Commit

Permalink
chore: Use a single session to handle authentication steps in DummyJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Sep 23, 2024
1 parent 7149be0 commit de61aeb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions samples/sample_tap_dummy_json/tap_dummyjson/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, auth_url, refresh_token_url, username, password):
self.refresh_token = None

self.expires = 0
self.session = requests.Session()

def __call__(self, request):
if not self.refresh_token:
Expand All @@ -45,13 +46,13 @@ def _handle_response(self, response):
response.raise_for_status()

data = response.json()
self.token = data["token"]
self.token = data["accessToken"]
self.refresh_token = data["refreshToken"]
self.expires = time.time() + EXPIRES_IN_MINS * 60
logger.info("Authenticated")

def refresh(self):
response = requests.post(
response = self.session.post(
self.refresh_token_url,
json={
"refreshToken": self.refresh_token,
Expand All @@ -61,7 +62,7 @@ def refresh(self):
self._handle_response(response)

def auth(self):
response = requests.post(
response = self.session.post(
self.auth_url,
json={
"username": self.username,
Expand Down

0 comments on commit de61aeb

Please sign in to comment.