auth
auth
¶
Authentication workflows for AI coding agents.
Provides a data-driven registry of auth providers (AUTH_PROVIDERS) and a
single entry point authenticate(project_id, provider) that runs the
appropriate flow inside a temporary L2 CLI container.
The shared helper _run_auth_container handles the common lifecycle:
check podman, load project, ensure host dir, cleanup old container, run.
AUTH_PROVIDERS = {}
module-attribute
¶
All known auth providers (agents + tools), keyed by name. Loaded from resources/agents/*.yaml.
AuthProvider(name, label, host_dir_name, container_mount, command, banner_hint, extra_run_args=tuple(), modes=('api_key',), api_key_hint='')
dataclass
¶
Describes how to authenticate one tool/agent.
name
instance-attribute
¶
Short key used in CLI and TUI dispatch (e.g. "codex").
label
instance-attribute
¶
Human-readable display name (e.g. "Codex").
host_dir_name
instance-attribute
¶
Directory name under mounts_dir() (e.g. "_codex-config").
container_mount
instance-attribute
¶
Mount point inside the container (e.g. "/home/dev/.codex").
command
instance-attribute
¶
Command to execute inside the container (OAuth mode only).
banner_hint
instance-attribute
¶
Provider-specific help text shown before the container runs.
extra_run_args = field(default_factory=tuple)
class-attribute
instance-attribute
¶
Additional podman run arguments (e.g. port forwarding).
modes = ('api_key',)
class-attribute
instance-attribute
¶
Supported auth modes: "oauth" (container), "api_key" (fast path).
api_key_hint = ''
class-attribute
instance-attribute
¶
Hint shown when prompting for an API key (URL to get one).
supports_oauth
property
¶
Whether this provider supports OAuth (container-based) auth.
supports_api_key
property
¶
Whether this provider supports direct API key entry.
AuthKeyConfig(label, key_url, env_var, config_path, printf_template, tool_name)
dataclass
¶
Describes how to prompt for and store an API key.
label
instance-attribute
¶
Human name shown in the prompt (e.g. "Claude").
key_url
instance-attribute
¶
URL where the user can obtain the key.
env_var
instance-attribute
¶
Name shown in the read -p prompt (e.g. "ANTHROPIC_API_KEY").
config_path
instance-attribute
¶
Destination inside the container (e.g. "~/.claude/config.json").
printf_template
instance-attribute
¶
printf format string (e.g. '{"api_key": "%s"}').
tool_name
instance-attribute
¶
Name shown in the success message (e.g. "claude").
store_api_key(provider, api_key, credential_set='default')
¶
Store an API key directly in the credential DB (no container needed).
This is the non-interactive fast path for automated workflows and CI.
The key is stored as {"type": "api_key", "key": "<value>"}.
Source code in src/terok_agent/auth.py
authenticate(project_id, provider, *, mounts_dir, image)
¶
Run the auth flow for provider against project_id.
Dispatches based on the provider's modes field:
- api_key only: prompt for key, store directly (no container)
- oauth only: launch container with vendor CLI
- both: ask user to choose, then dispatch accordingly
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
str
|
Project identifier (for container naming). |
required |
provider
|
str
|
Auth provider name (e.g. |
required |
mounts_dir
|
Path
|
Base directory for shared config bind-mounts. |
required |
image
|
str
|
Container image to use for the auth container. |
required |
Raises SystemExit if the provider name is unknown.