From c4ffde715cf19845bfd5be9b9ef463a86bfc1292 Mon Sep 17 00:00:00 2001 From: gradinazz <95712678+gradinazz@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:09:32 +0200 Subject: [PATCH] Enable access token useage (#586) * Update http.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add flag to be able to tune this * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: James Hilton-Balfe --- steam/http.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/steam/http.py b/steam/http.py index 196e496a..daacd0b2 100644 --- a/steam/http.py +++ b/steam/http.py @@ -79,7 +79,13 @@ def clear(self) -> None: ) async def request( - self, method: str, url: StrOrURL, /, api_needs_auth: bool = True, **kwargs: Any + self, + method: str, + url: StrOrURL, + /, + api_needs_auth: bool = True, + supports_access_token: bool = True, + **kwargs: Any, ) -> Any: # adapted from d.py kwargs["headers"] = {"User-Agent": self.user_agent, **kwargs.get("headers", {})} payload = kwargs.get("data") @@ -88,11 +94,10 @@ async def request( if url.host == URL.API.host: if api_needs_auth: - kwargs["params"] |= ( # if valve ever decide to make this work, this'd be nice - # {"access_token": await self._client._state.ws.access_token()} - # if self._client._state.login_complete.is_set() - # else - {"key": await self.get_api_key()} + kwargs["params"] |= ( + {"access_token": await self._client._state.ws.access_token()} + if self._client._state.login_complete.is_set() and supports_access_token + else {"key": await self.get_api_key()} ) elif url.host in (URL.COMMUNITY.host, URL.STORE.host, URL.HELP.host):