mirror of
https://github.com/Xevion/indexer-analyze.git
synced 2025-12-06 01:15:20 -06:00
initial commit
This commit is contained in:
29
auth.py
Normal file
29
auth.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import httpx
|
||||
import structlog
|
||||
from config import AUTHELIA_URL, get_async_logger
|
||||
from hooks import add_sonarr_api_key
|
||||
|
||||
logger: structlog.stdlib.AsyncBoundLogger = get_async_logger()
|
||||
|
||||
|
||||
async def authelia_login(username: str, password: str) -> httpx.AsyncClient:
|
||||
"""
|
||||
Perform Authelia login and return an authenticated httpx.AsyncClient with Sonarr API key added.
|
||||
"""
|
||||
client = httpx.AsyncClient(
|
||||
event_hooks={"request": [add_sonarr_api_key]},
|
||||
http2=True,
|
||||
limits=httpx.Limits(
|
||||
keepalive_expiry=60, max_connections=200, max_keepalive_connections=30
|
||||
),
|
||||
)
|
||||
|
||||
login_url = f"{AUTHELIA_URL}/api/firstfactor"
|
||||
payload = {"username": username, "password": password}
|
||||
resp = await client.post(login_url, json=payload)
|
||||
resp.raise_for_status()
|
||||
|
||||
# If login is successful, cookies are set in the client
|
||||
await logger.info("Authelia login successful", username=username)
|
||||
|
||||
return client
|
||||
Reference in New Issue
Block a user