"""One-time login to Garmin Connect; saves OAuth tokens to .secrets/. Usage: uv run auth.py Prompts for email + password (and MFA code if your account has 2FA). Tokens are refreshed automatically by sync.py on subsequent runs (valid ~1 year). """ import getpass import os from pathlib import Path import garth TOKEN_DIR = Path(__file__).parent / ".secrets" def main() -> None: TOKEN_DIR.mkdir(exist_ok=True) email = os.environ.get("GARMIN_EMAIL") or input("Garmin email: ").strip() password = os.environ.get("GARMIN_PASSWORD") or getpass.getpass("Garmin password: ") garth.login(email, password) garth.save(TOKEN_DIR) profile = garth.client.username print(f"Logged in as {profile}. Tokens saved to {TOKEN_DIR}.") if __name__ == "__main__": main()