clean: just handle auth as configure handles the rest of the flow

This commit is contained in:
2025-12-14 09:11:55 +01:00
parent 7fee7e56cf
commit ce0d313187

View File

@@ -1,6 +1,5 @@
"""Authentication helpers for the Auditui app.""" """Authentication helpers for the Auditui app."""
from getpass import getpass
from pathlib import Path from pathlib import Path
from typing import Tuple from typing import Tuple
@@ -13,30 +12,14 @@ def authenticate(
auth_path: Path = AUTH_PATH, auth_path: Path = AUTH_PATH,
) -> Tuple[audible.Authenticator, audible.Client]: ) -> Tuple[audible.Authenticator, audible.Client]:
"""Authenticate with Audible and return authenticator and client.""" """Authenticate with Audible and return authenticator and client."""
auth_path.parent.mkdir(parents=True, exist_ok=True) if not auth_path.exists():
raise FileNotFoundError(
"Authentication file not found. Please run 'auditui configure' to set up authentication.")
if auth_path.exists(): try:
try: authenticator = audible.Authenticator.from_file(str(auth_path))
authenticator = audible.Authenticator.from_file(str(auth_path)) audible_client = audible.Client(auth=authenticator)
audible_client = audible.Client(auth=authenticator) return authenticator, audible_client
return authenticator, audible_client except (OSError, ValueError, KeyError) as exc:
except (OSError, ValueError, KeyError) as exc: raise ValueError(
print(f"Failed to load existing auth: {exc}") f"Failed to load existing authentication: {exc}") from exc
print("Please re-authenticate.")
print("Please authenticate with your Audible account.")
email = input("\nEmail: ")
password = getpass("Password: ")
marketplace = input(
"Marketplace locale (default: US): ").strip().upper() or "US"
authenticator = audible.Authenticator.from_login(
username=email, password=password, locale=marketplace
)
auth_path.parent.mkdir(parents=True, exist_ok=True)
authenticator.to_file(str(auth_path))
print("Authentication successful!")
audible_client = audible.Client(auth=authenticator)
return authenticator, audible_client