chipflow.auth¶
ChipFlow authentication helper module.
Handles authentication for ChipFlow API with multiple fallback methods: 1. Environment variable CHIPFLOW_API_KEY 2. GitHub CLI token authentication (if gh is available) 3. OAuth 2.0 Device Flow
Exceptions¶
Exception raised when authentication fails. |
Functions¶
Get path to credentials file. |
|
|
Save API key for a given origin in the credentials file. |
|
Load saved API key for the given origin, or None if not present. |
Check if GitHub CLI is installed and authenticated. |
|
Get GitHub token from gh CLI. |
|
|
Authenticate using GitHub CLI token. |
|
Authenticate using OAuth 2.0 Device Flow. |
|
Get API key using the following priority: |
|
Remove saved credentials. |
Module Contents¶
- exception chipflow.auth.AuthenticationError¶
Bases:
ExceptionException raised when authentication fails.
- chipflow.auth.get_credentials_file()¶
Get path to credentials file.
- chipflow.auth.save_api_key(api_key, origin=DEFAULT_API_ORIGIN)¶
Save API key for a given origin in the credentials file.
- chipflow.auth.load_saved_api_key(origin=DEFAULT_API_ORIGIN)¶
Load saved API key for the given origin, or None if not present.
- Parameters:
origin (str)
- chipflow.auth.is_gh_authenticated()¶
Check if GitHub CLI is installed and authenticated.
- chipflow.auth.get_gh_token()¶
Get GitHub token from gh CLI.
- chipflow.auth.authenticate_with_github_token(api_origin, interactive=True)¶
Authenticate using GitHub CLI token.
- chipflow.auth.authenticate_with_device_flow(api_origin, interactive=True)¶
Authenticate using OAuth 2.0 Device Flow.
- chipflow.auth.get_api_key(api_origin=None, interactive=True, force_login=False)¶
Get API key using the following priority: 1. CHIPFLOW_API_KEY environment variable 2. Saved credentials file (unless force_login is True) 3. GitHub CLI token authentication 4. Device flow authentication
- Parameters:
- Returns:
API key string
- Raises:
AuthenticationError – If all authentication methods fail
- chipflow.auth.logout(origin=None)¶
Remove saved credentials.
If origin is given, only that origin’s key is removed; the file is deleted when no origins remain. If origin is None, the entire credentials file is deleted (legacy behaviour, used by chipflow auth logout without args).
- Parameters:
origin (str | None)