⚠️ Porta is in beta — APIs and features may change before v1.0
Skip to content

CLI Overview

The porta CLI is an admin tool for managing your Porta identity platform from the command line. It supports 15 top-level commands covering everything from initial bootstrap to day-to-day user management and declarative provisioning.

Installation

The CLI is included with Porta. In a development environment:

bash
# Run via yarn
yarn porta <command>

# Or via npx after building
npx porta <command>

In production, the CLI can be invoked directly if Porta is installed globally or via the bin entry:

bash
porta <command>

Global Options

Every command supports these global flags:

FlagDescription
--jsonOutput results as JSON instead of formatted tables
--verboseEnable verbose/debug logging
--forceSkip confirmation prompts
--dry-runShow what would happen without making changes
--database-urlOverride DATABASE_URL for direct-DB commands
--redis-urlOverride REDIS_URL for direct-DB commands

Command Reference

CommandModeDescription
porta initDirect DBBootstrap admin infrastructure
porta loginHTTPAuthenticate via OIDC (auto-detects Docker)
porta logoutHTTPClear stored credentials
porta whoamiHTTPDisplay current identity
porta healthBothCheck DB + Redis connectivity
porta migrateDirect DBRun database migrations
porta seedDirect DBLoad development seed data
porta keysHTTPManage signing keys
porta configHTTPManage system configuration
porta auditHTTPView and manage audit logs (list, cleanup)
porta orgHTTPManage organizations
porta appHTTPManage applications, modules, roles, permissions, claims
porta clientHTTPManage OIDC clients and secrets
porta userHTTPManage users, roles, claims, 2FA, GDPR export/purge
porta provisionHTTPDeclarative provisioning from YAML/JSON files

Dual-Mode Architecture

The CLI operates in two modes depending on the command:

Direct DB Mode

Commands like init, migrate, and seed connect directly to PostgreSQL and Redis. These are used for initial setup and infrastructure operations that must work before the HTTP server is running.

bash
# These connect directly to the database
porta init
porta migrate up
porta seed run

HTTP Mode

All other commands communicate with the Porta server via the Admin API. They require authentication (via porta login) and use Bearer token authorization. When running inside Docker or headless environments, porta login automatically uses a manual paste-URL mode — see porta login for details.

bash
# These use the Admin API
porta org list
porta user create --org-id <id> --email alice@example.com
porta client list

Output Formats

By default, the CLI displays results as formatted tables:

┌──────────────────────────────────────┬────────────┬──────────┐
│ ID                                   │ Name       │ Status   │
├──────────────────────────────────────┼────────────┼──────────┤
│ 550e8400-e29b-41d4-a716-44665544...  │ Acme Corp  │ active   │
│ 6ba7b810-9dad-11d1-80b4-00c04fd4...  │ Globex     │ active   │
└──────────────────────────────────────┴────────────┴──────────┘

Use --json for machine-readable output:

bash
porta org list --json
json
[
  { "id": "550e8400-...", "name": "Acme Corp", "status": "active" },
  { "id": "6ba7b810-...", "name": "Globex", "status": "active" }
]

Credential Storage

After porta login, credentials are stored at ~/.porta/credentials.json with 0600 file permissions (readable only by the current user). The CLI automatically refreshes expired access tokens using the stored refresh token.

Released under the MIT License.