sources/oauth: fix handling of token for do_request

This commit is contained in:
Jens Langhammer 2020-09-26 14:00:48 +02:00
parent 2b9705b33c
commit 2be6cd70d9
3 changed files with 3 additions and 5 deletions

View file

@ -40,7 +40,7 @@ class BaseOAuthClient:
def get_profile_info(self, token: Dict[str, str]) -> Optional[Dict[str, Any]]: def get_profile_info(self, token: Dict[str, str]) -> Optional[Dict[str, Any]]:
"Fetch user profile information." "Fetch user profile information."
try: 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() response.raise_for_status()
except RequestException as exc: except RequestException as exc:
LOGGER.warning("Unable to fetch user profile", exc=exc) LOGGER.warning("Unable to fetch user profile", exc=exc)

View file

@ -76,9 +76,6 @@ class OAuthClient(BaseOAuthClient):
def parse_raw_token(self, raw_token: str) -> Dict[str, Any]: def parse_raw_token(self, raw_token: str) -> Dict[str, Any]:
"Parse token and secret from raw token response." "Parse token and secret from raw token response."
return dict(parse_qsl(raw_token)) 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: def do_request(self, method: str, url: str, **kwargs) -> Response:
"Build remote url request. Constructs necessary auth." "Build remote url request. Constructs necessary auth."

View file

@ -97,7 +97,7 @@ class OAuth2Client(BaseOAuthClient):
def do_request(self, method: str, url: str, **kwargs) -> Response: def do_request(self, method: str, url: str, **kwargs) -> Response:
"Build remote url request. Constructs necessary auth." "Build remote url request. Constructs necessary auth."
if "token" in kwargs: if "token" in kwargs:
token = self.parse_raw_token(kwargs.pop("token")) token = kwargs.pop("token")
params = kwargs.get("params", {}) params = kwargs.get("params", {})
params["access_token"] = token["access_token"] params["access_token"] = token["access_token"]
@ -105,6 +105,7 @@ class OAuth2Client(BaseOAuthClient):
headers = kwargs.get("headers", {}) headers = kwargs.get("headers", {})
headers["Authorization"] = f"{token['token_type']} {token['access_token']}" headers["Authorization"] = f"{token['token_type']} {token['access_token']}"
kwargs["headers"] = headers
return super().do_request(method, url, **kwargs) return super().do_request(method, url, **kwargs)
@property @property