Skip to content

Commit

Permalink
Merge pull request #315 from relictMarauder/fix-403-response
Browse files Browse the repository at this point in the history
Prevent 403-response from api-server
  • Loading branch information
quarckster authored Nov 27, 2023
2 parents 2b70113 + a8860d1 commit d812eee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/resources/lib/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ def __init__(self, plugin: "Plugin") -> None:
def _make_request(self, payload):
self.plugin.logger.debug(f"Sending payload {payload} to oauth api")
try:
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
}
response = urllib.request.urlopen(
urllib.request.Request(self.plugin.settings.oauth_api_url),
urllib.request.Request(self.plugin.settings.oauth_api_url, headers=headers),
urllib.parse.urlencode(payload).encode("utf-8"),
).read()
return json.loads(response)
Expand Down
10 changes: 10 additions & 0 deletions src/resources/lib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def https_request(self, request: urllib.request.Request) -> urllib.request.Reque
f"Sending {request.get_method()} request to {request.get_full_url()}"
)
request.add_header("Authorization", f"Bearer {self.plugin.settings.access_token}")
request.add_header(
"user-agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
)
return request

http_request = https_request
Expand Down Expand Up @@ -138,6 +143,11 @@ def _handle_response(
def _make_request(self, request: urllib.request.Request) -> Dict[str, Any]:
request.recursion_counter_401 = 0 # type: ignore[attr-defined]
request.recursion_counter_429 = 0 # type: ignore[attr-defined]
request.add_header(
"user-agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
)
try:
response = self.opener.open(request, timeout=TIMEOUT)
except Exception:
Expand Down

0 comments on commit d812eee

Please sign in to comment.