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

# Authentication

> Sign in with your own account, or use an application or API key in scripts and CI

The CLI needs a credential to reach your organization. It supports three kinds, and uses the first one that is set:

| Order | Method | How to set it | Use it for |
| - | - | - | - |
| 1 | Application | `OCCTOO_CLIENT_ID` and `OCCTOO_CLIENT_SECRET` environment variables | CI, servers, scheduled jobs |
| 2 | API key | `OCCTOO_API_KEY` environment variable | Scripts and quick automation |
| 3 | Your own account | `occtoo auth login` | Working in a terminal |

If you set an application and an API key at the same time, the application wins. If you set `OCCTOO_CLIENT_ID` without `OCCTOO_CLIENT_SECRET`, the CLI stops with an error.

> [!WARNING]
>
> Secrets are never command-line flags, because flags end up in your shell history and in process lists. Pass them as environment variables.

## Sign in with your own account

```bash theme={null}
occtoo auth login
```

The CLI shows a code and opens your browser. Confirm the code in the browser and you are signed in. The CLI stores the session in your operating system keychain, such as Keychain on macOS or Credential Manager on Windows, and refreshes it when needed.

Check who you are signed in as:

```bash theme={null}
occtoo whoami
```

`whoami` shows your user, organization and roles, read from the access token.

To sign out and remove the stored session:

```bash theme={null}
occtoo auth logout
```

## Use an application in CI

An application is a client id and secret that a program signs in with. Create one in Studio or with [`occtoo applications create`](https://docs.occtoo.com/cli/commands/applications), and give it access to what the job needs.

Set both values as environment variables, for example as secrets in your CI system:

```bash theme={null}
export OCCTOO_CLIENT_ID="your-client-id"
export OCCTOO_CLIENT_SECRET="your-client-secret"
occtoo sources list --output json
```

The CLI gets an access token from `https://auth.occtoo.com` with the client credentials flow. You don't need to call `occtoo auth login`.

## Use an API key

```bash theme={null}
export OCCTOO_API_KEY="your-api-key"
occtoo sources list
```

The CLI sends the key with every request.

## Check your credentials

```bash theme={null}
occtoo auth status
```

`auth status` shows which credential the CLI uses and checks it against the API. Run it when a command fails with an authentication error.

## Command reference

| Command | What it does |
| - | - |
| `occtoo auth login` | Sign in through the browser and store the session in the keychain |
| `occtoo auth logout` | Remove the stored session |
| `occtoo auth status` | Show which credentials are in use and check them against the API |
| `occtoo whoami` | Show the user, organization and roles. Takes `--output json` |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.