Docs/CLI authentication
#

CLI authentication

Sign in to the Cofactor CLI with cofactor login or signup, switch organizations with --org, invite teammates, create API keys for CI with COFACTOR_API_TOKEN, and troubleshoot with auth doctor. Covers --org, --env, --token and --api-url.

The CLI signs in two ways. cofactor login and cofactor signup save a session on your machine for your own terminal. An API key in COFACTOR_API_TOKEN serves CI runners, scripts and agents with no terminal.

Sign in from a browser

bash
cofactor login

This opens your browser so you can approve the session, then saves it. Sessions are kept per organization and per environment, side by side.

FlagWhat it does
--org <name|id>Organization to sign in to. Without it, a terminal asks you to choose when you belong to several.
--env <env>prod (default), dev or local.
--no-openPrints the sign-in URL and does not open a browser.

Sign in or sign up by email

bash
cofactor signup --email you@example.com --accept-terms --organization "Acme"
cofactor signup verify --code <8 digits>

The first command emails you an 8-digit code. The second finishes the sign-in and saves the session. Run signup again to get a new code.

FlagWhat it does
--email <email>Your email. verify remembers it from the first command.
--accept-termsAccepts the Terms and Privacy policy. Without it, a terminal asks y/N. A script must pass it.
--organization <name>Names the new organization (1 to 80 characters, required for a new account). On verify, it can also pick one of your existing organizations by id, slug or name.
--code <8 digits>On verify: the code from the email.

Accounts that require MFA use cofactor login.

Check who you are

bash
cofactor whoami

Prints the user, organization and API environment the CLI would use. It makes no network request.

Organizations

cofactor orgs lists the organizations you belong to. A * marks the active one.

CommandWhat it does
cofactor org use <name|id>Sets the active organization for commands that do not pass --org.
cofactor org membersLists the members of the current organization.
cofactor org invite <email> [--role member|admin]Invites a teammate. Admins only. The role defaults to member.
cofactor org invitesLists pending invitations.

To run one command as another organization you are signed in to, add --org <name|id>:

bash
cofactor test-suite run --suite "Smoke" --org "Acme"

You can also set COFACTOR_ORG as the default organization. If that organization has no saved session, the command fails and tells you to run cofactor login --org "<name>".

Use an API key in CI

For CI and scripts, an organization admin creates an API key and the job passes it in COFACTOR_API_TOKEN:

bash
export COFACTOR_API_TOKEN=<your-api-key>
cofactor test-suite run --suite "Smoke"

No login step is needed. For scopes, expiry and rotation, see API keys.

cofactor api-key manages keys. It is for organization admins.

CommandWhat it does
cofactor api-key create --name <name> --scope <scope> [--scope ...] [--expires-at <date>]Creates a key and prints its secret once. At least one --scope is required. A key without --expires-at never expires.
cofactor api-key listLists keys. Secrets are never shown again.
cofactor api-key revoke <id>Revokes a key. It stops working immediately.
cofactor api-key scopesLists the scopes a key can have.

A scope is resource:action, resource:* for every action on a resource, or * for full access. Give a CI key only what its job needs. With --json, create includes the secret, so keep that output out of logs.

bash
cofactor api-key create --name "CI test runs" --scope test-run:run --scope test-run:read

Environment variables and global flags

VariableWhat it does
COFACTOR_API_TOKENAPI key to use instead of a saved session.
COFACTOR_API_URLAPI URL. Default https://api.runcofactor.com.
COFACTOR_ORGDefault organization name or id, like --org.
COFACTOR_CONFIG_DIRDirectory for the saved sessions.

These flags work on commands that call the API. Put them after the command.

FlagWhat it does
--org <name|id>Run as one of your signed-in organizations.
--env <env>prod, dev or local. Picks the matching saved session and API host.
--token <key>API key for this command.
--api-url <url>API URL for this command.
--jsonJSON output, on commands that print data.

Which credential the CLI uses: --token first. With --org, COFACTOR_ORG or --env, the matching saved session. Otherwise COFACTOR_API_TOKEN, then your saved default session.

The CLI saves sessions in auth.json under ~/.config/canary-cli/ in your home directory. Treat that file like a password.

Fix sign-in problems

bash
cofactor auth doctor

The command checks your saved session or API key and calls three API endpoints. It reports whether TLS interception or a proxy block is the cause. It exits 1 when a call fails or no token is found.

Next steps