Source code for fitrequest.token_auth

from collections.abc import Generator

import httpx


# https://www.python-httpx.org/advanced/authentication/#custom-authentication-schemes
[docs] class HeaderTokenAuth(httpx.Auth): def __init__(self, token: str) -> None: self.token = token
[docs] def auth_flow(self, request: httpx.Request) -> Generator[httpx.Request, httpx.Response, None]: """Send the request, with a custom ``X-Authentication`` header.""" request.headers['X-Authentication'] = self.token yield request
[docs] class ParamsTokenAuth(httpx.Auth): def __init__(self, token: str) -> None: self.token = token
[docs] def auth_flow(self, request: httpx.Request) -> Generator[httpx.Request, httpx.Response, None]: """Send the request, with a custom ``token`` url parameter.""" request.url = request.url.copy_merge_params({'token': self.token}) yield request