Skip to main content

Authentication

The kdx CLI supports multiple authentication methods to connect to Kodexa environments.

Authentication Methods

The kdx login command provides browser-based OAuth authentication.

Flags

Examples

How It Works

  1. CLI opens your default browser to the Kodexa login page
  2. You authenticate with your credentials
  3. Browser redirects back to CLI with authentication token
  4. CLI saves the token to your profile

Device Code Flow

For environments without a browser (servers, containers, SSH sessions), use device-code authentication:

How It Works

  1. CLI displays a code and URL
  2. You visit the URL on any device and enter the code
  3. CLI polls for completion and saves the token

API Key Authentication

For automation and CI/CD, you can use API keys directly.

Creating an API Key

  1. Log in to your Kodexa environment
  2. Navigate to SettingsAPI Keys
  3. Click Create API Key
  4. Copy the generated key (shown only once)

Using API Keys

Option 1: Save to Profile

Option 2: Command Line Flag

Option 3: Environment Variables

Environment Variables

For containerized deployments and CI/CD, environment variables provide flexible authentication:

Example: GitHub Actions

Example: Docker

Profile Configuration

Profiles store authentication credentials locally for easy switching between environments.

Profile Location

Credentials are stored in ~/.kodexa/config.yaml:

Managing Profiles

Authentication Priority

When multiple authentication methods are configured, kdx uses this priority:
  1. --api-key command line flag
  2. --profile command line flag
  3. KODEXA_ACCESS_TOKEN environment variable
  4. Current profile in config file

Security Best Practices

API Key Security

  • Never commit API keys to version control
  • Use environment variables in CI/CD
  • Rotate keys periodically
  • Use minimal permissions for automation keys

Profile Security

  • Profile config is stored with user-only permissions (600)
  • Consider using credential helpers for sensitive environments
  • Use separate profiles for production vs development

Token Expiration

  • OAuth tokens may expire; re-run kdx login to refresh
  • API keys don’t expire unless revoked
  • Check token validity with kdx get projects (quick test)

Troubleshooting

Authentication Failed

Solutions:
  • Verify the URL is correct
  • Check if API key is valid and not revoked
  • Try kdx login to refresh OAuth token

Profile Not Found

Solutions:
  • List profiles with kdx config list-profiles
  • Create profile with kdx login or kdx config set-profile

Browser Doesn’t Open

Solutions:
  • Use --no-browser flag and open URL manually
  • Use --device flag for device-code flow
  • Check if xdg-open (Linux) or open (macOS) is available

Automatic Re-Authentication

When the CLI encounters a 401 Unauthorized response during any operation, it automatically prompts you to re-authenticate instead of failing with an error. This is useful when OAuth tokens expire during a long session.
The CLI will:
  1. Detect the 401 response
  2. Prompt you to re-authenticate (skipped during non-interactive/CI usage)
  3. Open the browser for OAuth login (or use device code flow if configured)
  4. Retry the original operation with the new token
Automatic re-authentication is skipped during startup plugin discovery to avoid interrupting CLI initialization.

Timeout During Login

Solutions:
  • Increase timeout with --timeout 300
  • Ensure you complete browser authentication before timeout
  • Check network connectivity to Kodexa server