Files
phaseflow/scripts/garmin_auth.py
Petru Paler c8a738d0c4
All checks were successful
Deploy / deploy (push) Successful in 1m36s
Fix garth token serialization using Pydantic v2 API
The garth library uses Pydantic dataclasses for OAuth tokens which don't
have a serialize() method. Use model_dump() instead, and fix expires_at
handling since it's an integer timestamp not a datetime object.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 16:49:16 +00:00

40 lines
1.1 KiB
Python

#!/usr/bin/env python3
# ABOUTME: PhaseFlow Garmin Token Generator using garth library.
# ABOUTME: Run this locally to authenticate with Garmin (supports MFA).
"""
PhaseFlow Garmin Token Generator
Run this locally to authenticate with Garmin (supports MFA)
Usage:
pip install garth
python3 garmin_auth.py
"""
import json
from datetime import datetime
from getpass import getpass
try:
import garth
except ImportError:
print("Error: garth library not installed.")
print("Please install it with: pip install garth")
exit(1)
email = input("Garmin email: ")
password = getpass("Garmin password: ")
# MFA handled automatically - prompts if needed
garth.login(email, password)
tokens = {
"oauth1": garth.client.oauth1_token.model_dump(),
"oauth2": garth.client.oauth2_token.model_dump(),
"expires_at": garth.client.oauth2_token.expires_at
}
print("\n--- Copy everything below this line ---")
print(json.dumps(tokens, indent=2))
print("--- Copy everything above this line ---")
expires_dt = datetime.fromtimestamp(tokens['expires_at'])
print(f"\nTokens expire: {expires_dt.isoformat()}")