# Sign in and profiles

Save a key once, keep one for each workspace, and switch between them.

## Sign in

`opensend login` opens the dashboard in your browser. You choose the workspace and whether the command line may do everything or only send, then allow it. A key is made for it, named after this computer, and saved as the profile `default`. The key is on the API keys page like any other, and revoking it signs the command line out.

```bash
opensend login
opensend login --no-browser
opensend login --with-token
```

- `--no-browser` prints the address instead of opening it. Open it in a browser on the same computer, because the answer comes back to it.
- `--with-token` takes a key you made yourself: it asks for it without showing it, or reads it from standard input.

In a script or a CI job, pipe the key in:

```bash
printf '%s' "$OPENSEND_API_KEY" | opensend login --with-token
```

## A server of your own

Give the address of its API with `--api-url`. The profile keeps it, so every command with that profile goes there.

```bash
opensend login --api-url https://mail.example.com
```

## Profiles

A profile is a key, the address of its API and the name of its workspace. `--profile` names the one `login` saves, and the one saved last is the one commands use.

```bash
opensend login --profile staging
opensend profile list
opensend profile use default
opensend domains list --profile staging
```

- `profile list` shows them all and marks the active one.
- `profile use` makes another one active.
- `--profile` on any command uses that profile for that command only.

## Which key a command uses

- The profile `--profile` names, when the command has it.
- `OPENSEND_API_KEY`, with `OPENSEND_API_URL` when it is set.
- The active profile.

So a CI job sets the two variables and never depends on what a machine has saved.

## Where it is kept

Profiles are saved in `~/.config/opensend/config.json`, or under `$XDG_CONFIG_HOME` when that is set. The file is replaced whole on each change, and only you can read it.

## Check it

```bash
opensend whoami
```

It prints the profile, where the key came from, the address of the API and the workspace the key belongs to.

## Sign out

```bash
opensend logout
opensend logout --profile staging
opensend logout --all
```

> Signing out forgets the key on this machine. The key itself keeps working until you revoke it on the API keys page.
