# Login

> Log in with Unity Hub or a service account.

Log in with Unity Hub or a service account. Service account credentials are stored locally.

> **Note:**
>
> This is a base command specific to the CLI that allows you to make authenticated calls to our apis. It is not related to the Authentication Unity Service.

## Interactive usage

By default, calling this command prompts you to choose a login method: `Unity Hub` or `Service Account`.
Choosing `Service Account` prompts you to enter your service account `key-id` and `secret-key`.

```text
ugs login
Choose a login method: Service Account
Enter your key-id: <your-key-id>
Enter your secret-key: <your-secret-key>
```

## Unity Hub

Log in with the account signed in to Unity Hub. Unity Hub must be running and signed in.

```text
ugs login --unity-hub
```

`--unity-hub` can't be combined with the service account options.
To use Unity Hub authentication for a single call without logging in, set `UGS_CLI_USE_HUB_AUTH` to `true`.

## Automated usage

You can automate login by using both the `--service-key-id` option and the `--secret-key-stdin` option.
The `--service-key-id` option expects your service account `key-id` as argument.
The `--secret-key-stdin` option expects your `secret-key` in the standard input.

```text
ugs login --service-key-id "your-key-id" --secret-key-stdin < "secret-key-file"
```

Where `"your-key-id"` is your service account `key-id`, and `"secret-key-file"` is the path to a file containing
your service account `secret key`.

## Options

|            | Alias              | Description                                                                    |
| ---------- | ------------------ | ------------------------------------------------------------------------------ |
| key-id     | --service-key-id   | The key-id of your service account. Must be used with "--secret-key-stdin".    |
| secret-key | --secret-key-stdin | The secret-key of your service account. Must be used with  "--service-key-id". |
| unity-hub  | --unity-hub        | Log in with Unity Hub.                                                         |
| help       | -?, -h, --help     | Display help and usage information.                                            |
| quiet      | -q, --quiet        | Reduce logging to a minimum.                                                   |
| json       | -j, --json         | Use JSON as the output format.                                                 |

## Environment Variables

### Logging in with Environment Variables

To log in manually use the `ugs login` command.

To log in with system environment variables, set `UGS_CLI_SERVICE_KEY_ID` and `UGS_CLI_SERVICE_SECRET_KEY` to your
system's environment variables.

Authenticated calls use the first available credential, in this order:

1. `UGS_CLI_AUTH_TOKEN` (a bearer token)
2. `UGS_CLI_USE_HUB_AUTH` (Unity Hub)
3. The credential saved by `ugs login`
4. `UGS_CLI_SERVICE_KEY_ID` and `UGS_CLI_SERVICE_SECRET_KEY`
