11"""Auth service for managing Privy authentication.
22
3- Handles loading, refreshing, and persisting auth tokens from ~/.amp-cli-config .
3+ Handles loading, refreshing, and persisting auth tokens from ~/.amp/cache .
44Compatible with the TypeScript CLI authentication system.
55"""
66
1717AUTH_PLATFORM_URL = 'https://auth.amp.thegraph.com/'
1818
1919# Storage location (matches TypeScript implementation)
20- # TypeScript CLI uses: ~/.amp-cli-config /amp_cli_auth (directory with file inside)
21- AUTH_CONFIG_DIR = Path .home () / '.amp-cli-config '
20+ # TypeScript CLI uses: ~/.amp/cache /amp_cli_auth (directory with file inside)
21+ AUTH_CONFIG_DIR = Path .home () / '.amp' / 'cache '
2222AUTH_CONFIG_FILE = AUTH_CONFIG_DIR / 'amp_cli_auth'
2323
2424
2525class AuthService :
2626 """Service for managing Privy authentication tokens.
2727
28- Loads tokens from ~/.amp-cli-config (shared with TypeScript CLI),
28+ Loads tokens from ~/.amp/cache (shared with TypeScript CLI),
2929 automatically refreshes expired tokens, and persists updates.
3030
3131 Example:
@@ -38,7 +38,7 @@ def __init__(self, config_path: Optional[Path] = None):
3838 """Initialize auth service.
3939
4040 Args:
41- config_path: Optional custom path to config file (defaults to ~/.amp-cli-config /amp_cli_auth)
41+ config_path: Optional custom path to config file (defaults to ~/.amp/cache /amp_cli_auth)
4242 """
4343 self .config_path = config_path or AUTH_CONFIG_FILE
4444 self ._http = httpx .Client (timeout = 30.0 )
@@ -47,7 +47,7 @@ def is_authenticated(self) -> bool:
4747 """Check if user is authenticated.
4848
4949 Returns:
50- True if valid auth exists in ~/.amp-cli-config
50+ True if valid auth exists in ~/.amp/cache
5151 """
5252 try :
5353 auth = self .load_auth ()
@@ -56,7 +56,7 @@ def is_authenticated(self) -> bool:
5656 return False
5757
5858 def load_auth (self ) -> Optional [AuthStorage ]:
59- """Load auth from ~/.amp-cli-config /amp_cli_auth file.
59+ """Load auth from ~/.amp/cache /amp_cli_auth file.
6060
6161 Returns:
6262 AuthStorage if found, None if not authenticated
@@ -75,7 +75,7 @@ def load_auth(self) -> Optional[AuthStorage]:
7575 return AuthStorage .model_validate (auth_data )
7676
7777 def save_auth (self , auth : AuthStorage ) -> None :
78- """Save auth to ~/.amp-cli-config /amp_cli_auth file.
78+ """Save auth to ~/.amp/cache /amp_cli_auth file.
7979
8080 Args:
8181 auth: Auth data to persist
@@ -97,7 +97,7 @@ def get_token(self) -> str:
9797 Valid access token string
9898
9999 Raises:
100- FileNotFoundError: If not authenticated (no ~/.amp-cli-config )
100+ FileNotFoundError: If not authenticated (no ~/.amp/cache )
101101 ValueError: If auth data is invalid or refresh fails
102102 """
103103 auth = self .load_auth ()
@@ -228,7 +228,7 @@ def login(self, verbose: bool = True, auto_open_browser: bool = True) -> None:
228228 """Perform interactive browser-based login.
229229
230230 Opens browser for OAuth2 device authorization flow with PKCE.
231- Saves authentication tokens to ~/.amp-cli-config /amp_cli_auth.
231+ Saves authentication tokens to ~/.amp/cache /amp_cli_auth.
232232
233233 Args:
234234 verbose: Print progress messages
@@ -240,7 +240,7 @@ def login(self, verbose: bool = True, auto_open_browser: bool = True) -> None:
240240 Example:
241241 >>> auth = AuthService()
242242 >>> auth.login() # Opens browser for authentication
243- >>> # Auth tokens saved to ~/.amp-cli-config /amp_cli_auth
243+ >>> # Auth tokens saved to ~/.amp/cache /amp_cli_auth
244244 """
245245 from .device_flow import interactive_device_login
246246
0 commit comments