> ## Documentation Index
> Fetch the complete documentation index at: https://docs.controlplane.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Authenticate with the Control Plane CLI using interactive login or token-based flows.

The CLI supports multiple authentication methods for different environments and use cases.

## Interactive login

The default authentication method opens your browser to sign in with a confirmation code.

```bash theme={null}
cpln login
```

This command:

1. Prints a six-digit confirmation code and opens the login page in your browser
2. Waits while you sign in and enter the code
3. Creates a `default` profile with your credentials

```text theme={null}
First, copy your confirmation code: 960619

Opening your browser to log in. Browser didn't open? Use the URL below:

  https://auth.cpln.io/cli-login?id=A1b2C3d4E5f6G7h8I9j0KlMnOpQrStUvWxYz

Waiting for login to complete... (code expires in ~10 minutes)
```

> [!TIP]
>
> After successful authentication, the CLI is ready to use with your default profile.

## Unattended authentication

For automation where no person is available to complete a sign-in (CI/CD pipelines, scripts, long-lived containers), use a service account token.

**1. Create a service account**

> [tab] Console
>
> 1. Click **Service Accounts** in the left menu and click **New** (or use the **Create** dropdown in the upper right corner)
> 2. Enter a unique name and optional description
> 3. Click **Next (Tags)**, add any optional tags, then click **Create**

> [tab] CLI
>
> ```bash theme={null}
> cpln serviceaccount create --name pipeline-automation --description "CI/CD automation"
> ```

See the [Create a Service Account](https://docs.controlplane.com/guides/create-service-account.md) guide for details.

**2. Generate a key**

> [tab] Console
>
> 1. Open the service account you created
> 2. Click the **Keys** link
> 3. Enter a key description and click **Add**
> 4. Copy and download the generated key securely

> [tab] CLI
>
> ```bash theme={null}
> cpln serviceaccount add-key pipeline-automation --description github-workflow
> ```
>
> Save the returned key securely.

**3. Authenticate with the token**

Use the token directly or create a profile:

> [tab] Create a profile (recommended)
>
> ```bash theme={null}
> cpln profile create <profile-name> --token <your-token> --org <org-name> --gvc <gvc-name>
> ```
>
> > [!NOTE]
> >
> > When using `--token`, always include `--gvc` if your commands require a default GVC context.
>
> Set as default (optional):
>
> ```bash theme={null}
> cpln profile set-default <profile-name>
> ```

> [tab] Use token directly
>
> Pass the token with each command:
>
> ```bash theme={null}
> cpln gvc get --token <your-token> --org <org-name>
> ```

> [tab] Use environment variable
>
> Set the `CPLN_TOKEN` environment variable:
>
> ```bash theme={null}
> export CPLN_TOKEN=<your-token>
> cpln gvc get --org <org-name>
> ```

> [!NOTE]
>
> For detailed service account token setup, see the [Browser-less CLI Login](https://docs.controlplane.com/guides/browser-less-cli-login.md) guide.

## Token management

### View your current token

Display the token for a profile:

```bash theme={null}
cpln profile token <profile-name>
```

### Override token for a single command

Use a different token without changing your profile:

```bash theme={null}
cpln gvc get <gvc-name> --token <your-token>
```

### Token precedence

The CLI uses tokens in this order:

1. `--token` flag (highest priority)
2. `CPLN_TOKEN` environment variable
3. Profile token (default)

## Authentication for CI/CD

For automated environments:

1. Create a service account with appropriate permissions
2. Generate a key and store it securely (e.g., `CPLN_TOKEN` in secrets manager)
3. Create a profile in your CI/CD pipeline

```bash theme={null}
cpln profile update ci --org <org-name> --default
```

See [CI/CD usage](https://docs.controlplane.com/cli-reference/ci-cd-development/ci-cd.md) for complete automation setup.

## Troubleshooting

> [accordion] Login session expired or timed out
>
> The confirmation code is valid for about 10 minutes. If it expires before you finish signing in, the CLI stops waiting and reports that the session expired. Run `cpln login` again to get a fresh URL and code.

> [accordion] No browser available on the machine running the CLI
>
> The browser does not have to run on the same machine as the CLI. Copy the printed URL to a browser on any device, sign in, and enter the confirmation code — the waiting CLI picks up the credentials automatically.
>
> If no person is available to complete a sign-in at all, such as in a CI/CD pipeline, use a service account token instead.

> [accordion] Authentication failed or 403 Forbidden error
>
> A 403 error typically means one of the following:
>
> * **Wrong org**: You're trying to access an org you don't have access to, or there's a typo in the org name. Verify with `cpln profile get`.
> * **Missing token**: No token is provided. Ensure `CPLN_TOKEN` is set or you're using a profile with a valid token.
> * **Insufficient permissions**: Your token doesn't have the required permissions. Generate a new key or re-login to refresh your token:
>   ```bash theme={null}
>   cpln login
>   ```
>   Or for service accounts:
>   ```bash theme={null}
>   cpln serviceaccount add-key <name> --description <key-description>
>   ```

> [!NOTE]
>
> For more troubleshooting help, see the [Troubleshooting](https://docs.controlplane.com/cli-reference/using-cli/troubleshooting.md) page.

## Next steps

> [card] [Profiles](https://docs.controlplane.com/cli-reference/get-started/profiles.md)
>
> Manage multiple authentication contexts

> [card] [CI/CD Setup](https://docs.controlplane.com/cli-reference/ci-cd-development/ci-cd.md)
>
> Automate with service accounts
