Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Use a single session to handle authentication steps in DummyJSON #2684

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading