From 2be6cd70d94b7fc04955548b78f9270e2a2a3549 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 26 Sep 2020 14:00:48 +0200 Subject: [PATCH] sources/oauth: fix handling of token for do_request --- passbook/sources/oauth/clients/base.py | 2 +- passbook/sources/oauth/clients/oauth1.py | 3 --- passbook/sources/oauth/clients/oauth2.py | 3 ++- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/passbook/sources/oauth/clients/base.py b/passbook/sources/oauth/clients/base.py index 5fcbf0b7f..e45fba973 100644 --- a/passbook/sources/oauth/clients/base.py +++ b/passbook/sources/oauth/clients/base.py @@ -40,7 +40,7 @@ class BaseOAuthClient: def get_profile_info(self, token: Dict[str, str]) -> Optional[Dict[str, Any]]: "Fetch user profile information." try: - response = self.do_request("get", self.source.profile_url, token=token,) + response = self.do_request("get", self.source.profile_url, token=token) response.raise_for_status() except RequestException as exc: LOGGER.warning("Unable to fetch user profile", exc=exc) diff --git a/passbook/sources/oauth/clients/oauth1.py b/passbook/sources/oauth/clients/oauth1.py index 42d34d116..458946cb0 100644 --- a/passbook/sources/oauth/clients/oauth1.py +++ b/passbook/sources/oauth/clients/oauth1.py @@ -76,9 +76,6 @@ class OAuthClient(BaseOAuthClient): def parse_raw_token(self, raw_token: str) -> Dict[str, Any]: "Parse token and secret from raw token response." return dict(parse_qsl(raw_token)) - # token = query_string["oauth_token"] - # secret = query_string["oauth_token_secret"] - # return (token, secret) def do_request(self, method: str, url: str, **kwargs) -> Response: "Build remote url request. Constructs necessary auth." diff --git a/passbook/sources/oauth/clients/oauth2.py b/passbook/sources/oauth/clients/oauth2.py index a60e81a10..6975d35a9 100644 --- a/passbook/sources/oauth/clients/oauth2.py +++ b/passbook/sources/oauth/clients/oauth2.py @@ -97,7 +97,7 @@ class OAuth2Client(BaseOAuthClient): def do_request(self, method: str, url: str, **kwargs) -> Response: "Build remote url request. Constructs necessary auth." if "token" in kwargs: - token = self.parse_raw_token(kwargs.pop("token")) + token = kwargs.pop("token") params = kwargs.get("params", {}) params["access_token"] = token["access_token"] @@ -105,6 +105,7 @@ class OAuth2Client(BaseOAuthClient): headers = kwargs.get("headers", {}) headers["Authorization"] = f"{token['token_type']} {token['access_token']}" + kwargs["headers"] = headers return super().do_request(method, url, **kwargs) @property