Source code for SlyAPI.auth
from abc import ABC, abstractmethod
from aiohttp import ClientSession as Client
from .web import Request
[docs]class UrlApiKey(Auth):
'URL parameter with a secret to authorize requests.'
params: dict[str, str]
def __init__(self, param_name: str, secret: str):
self.params = {param_name: secret}
[docs] async def sign(self, client: Client, request: Request) -> Request:
request.query_params |= self.params
return request
[docs]class HeaderApiKey(Auth):
'Header with a secret to authorize requests.'
headers: dict[str, str]
def __init__(self, param_name: str, secret: str):
self.headers = {param_name: secret}
[docs] async def sign(self, client: Client, request: Request) -> Request:
request.headers |= self.headers
return request