Skip to content

Commit

Permalink
review - using urlparse
Browse files Browse the repository at this point in the history
  • Loading branch information
kudj committed Oct 24, 2024
1 parent d2bb1af commit 366d830
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions python-sync-actions/src/http_generic/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from abc import ABC, abstractmethod
from typing import Callable, Union, Dict, Literal
from urllib.parse import urlencode
from urllib.parse import urlparse, parse_qs, urlencode, urlunparse

import requests
from requests import auth
Expand Down Expand Up @@ -167,10 +167,12 @@ def __call__(self, r):
r.headers[self.key] = f"{self.token}"

elif self.position == 'query':
if '?' in r.url:
r.url = f"{r.url}&{urlencode({self.key: self.token})}"
else:
r.url = f"{r.url}?{urlencode({self.key: self.token})}"
parsed_url = urlparse(r.url)
query_params = parse_qs(parsed_url.query)
query_params.update({self.key: self.token})
new_query = urlencode(query_params, doseq=True)
r.url = urlunparse(parsed_url._replace(query=new_query))

else:
raise AuthBuilderError(f"Unsupported position {self.position} for API Key auth method")
return r
Expand Down

0 comments on commit 366d830

Please sign in to comment.