auth top-level command — authenticate an agent, tool, or endpoint.
Three invocation shapes, in increasing specificity:
terok auth — interactive chained menu.
terok auth <provider> — host-wide auth for one provider.
terok auth <provider> --project name — project-scoped auth.
Where credentials land depends on the named project's
credentials_scope:
"shared" (default) writes to the host-wide bucket every project
sees, "project" carves out a private vault row and agent-config
mount tree keyed by the project name. Host-wide terok auth (no
--project) always writes to the shared bucket — there's no project
context to override it.
register(subparsers)
Register the auth top-level command.
Source code in src/terok/cli/commands/auth.py
| def register(subparsers: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
"""Register the ``auth`` top-level command."""
from terok.lib.api.agents import load_auth_providers
# Accept either an auth-entry name (codex) or the LLM provider it
# authenticates (openai → codex), since the two can be confusing.
auth_providers = load_auth_providers()
provider_of = _provider_of()
accepted = list(auth_providers) + list(provider_of.values())
entries = []
for name, p in auth_providers.items():
suffix = f" → {provider_of[name]}" if name in provider_of else ""
entries.append(f"{name} ({p.label}{suffix})")
providers_help = ", ".join(entries)
p_auth = subparsers.add_parser(
"auth",
help="Authenticate a provider. Use --project for project scope.",
description=(
f"Available providers: {providers_help}\n\n"
"Run without arguments to open an interactive provider menu. "
"``terok auth <provider>`` stores credentials in the shared host scope. "
"Use ``--project <name>`` to select a project. The vendor login uses the project image. "
"If ``credentials.scope`` is ``project``, Terok stores the token in the "
"project vault."
),
formatter_class=argparse.RawDescriptionHelpFormatter,
)
p_auth.add_argument(
"provider",
nargs="?",
default=None,
choices=accepted,
metavar="provider",
)
set_completer(
p_auth.add_argument(
"--project",
dest="project_flag",
default=None,
help="Scope authentication with the project's login image and project.yml credentials.scope",
),
_complete_project_names,
)
p_auth.add_argument(
"--device-auth",
dest="device_auth",
action="store_true",
help=(
"Force the headless device-code login (skip the method chooser) — "
"for remote/headless hosts with no local browser"
),
)
|
dispatch(args)
Handle terok auth. Returns True if handled.
Source code in src/terok/cli/commands/auth.py
| def dispatch(args: argparse.Namespace) -> bool:
"""Handle ``terok auth``. Returns True if handled."""
if args.cmd != "auth":
return False
project_name = args.project_flag
if args.provider is None:
_run_interactive(project_name, device_auth=args.device_auth)
else:
_run_one(args.provider, project_name, device_auth=args.device_auth)
return True
|