# Authentication

> Authenticate UiPath CLI using interactive OAuth2, External App credentials, or environment-variable token flows.

UiPath CLI supports five authentication flows: a developer on a laptop, a CI/CD pipeline calling Orchestrator with an External Application, a CI/CD platform that can issue its own OIDC tokens instead of holding a long-lived secret, a container or ephemeral runner that already holds an access token, and a process running alongside a local UiPath Robot. The first three end at the same place — an authenticated session persisted to a credentials folder that every subsequent `uip` command reuses — but they differ in how they obtain the token and how the CLI refreshes it. The fourth bypasses on-disk state entirely. The fifth defers to the Robot's own identity over a local IPC channel.

## Pick a flow

| You are… | Use this | How |
|---|---|---|
| A developer on a laptop or workstation | **Interactive OAuth2** | `uip login` opens a browser, you sign in once, tokens are stored and refreshed automatically. |
| A CI/CD pipeline or server | **External Application (client credentials)** | Create an External App in UiPath, pass its ID and secret to `uip login --client-id … --client-secret …`. Tokens are stored and refreshed. |
| A CI/CD platform that can mint its own OIDC tokens (workload identity) | **Federated credentials** | `uip login --client-id <app-id> --client-assertion env.OIDC_TOKEN` — an OIDC JWT stands in for the client secret, so there's no long-lived secret to store or rotate. Requires `--client-id`; mutually exclusive with `--client-secret`. |
| A container, ephemeral runner, or any process that already holds a token | **Environment-variable auth** | Set `UIPATH_CLI_ENABLE_ENV_AUTH=true` and supply the token + organization/tenant via env vars. No file is written; no refresh. |
| A process running on a machine with a local UiPath Robot | **Robot credentials** | Set `UIPATH_CLI_ENFORCE_ROBOT_AUTH=true`. `uip` authenticates through the Robot's local IPC channel instead of any of the above. |

`uip logout` clears any on-disk credentials from the first three flows. The env-var flow has nothing to clear — unset the env vars. Robot credentials have nothing to clear either — the Robot owns the identity.

:::tip
`--profile <name>` is a global flag (see [Global options](./global-options.md)) that names a session so multiple logins — across any of the first three flows — can coexist side by side. Pass the same `--profile` on every command that should reuse a given named session; it's mutually exclusive with `--file`/`-f` on `uip login` and `uip logout`.
:::

## Flow 1 — Interactive OAuth2

Run `uip login` with no arguments:

```bash
uip login
```

`uip` opens your default browser on UiPath's sign-in page. After you authenticate, UiPath redirects back to a local callback that `uip` is listening on, and the CLI prompts you to pick a tenant. When the tenant is selected, the session is saved and you are done.

Useful flags:

```bash
uip login --tenant DefaultTenant                 # skip the tenant picker
uip login --organization my-org                  # skip the org picker for users in multiple orgs
uip login --interactive                          # explicitly show the tenant picker even if --tenant was set
uip login --authority https://example.com        # point at a non-default identity authority (Automation Suite, staging)
uip login --scope "OR.Folders OR.Jobs"           # restrict the session to specific scopes
uip login --file /path/to/creds                  # store credentials in a non-default folder
```

### Where credentials are stored

By default, the session is stored inside a `.uipath/` folder. `uip` looks for this folder in three places, in order:

1. Explicit folder — if you passed `--file <folder>`, the CLI uses that folder. Pass the folder, not a file path.
2. **Walk up from the current working directory** looking for `.uipath/` — so a project folder can carry its own session without touching the user's home.
3. `~/.uipath/` — the default fallback.

When no `.uipath/` exists anywhere on the walk-up chain, `uip login` creates one at `~/.uipath/`. Treat the folder's contents as opaque — they are managed by `uip login`, `uip login tenant set`, and `uip logout`.

### Manage tenants mid-session

The session stores a single active tenant at a time. Switch without re-running the full login flow:

```bash
uip login tenant list           # show all tenants available to your account
uip login tenant set MyTenant   # switch the active tenant
```

`uip login status` shows the current organization, tenant, and token expiration.

### Refresh is automatic

`uip` refreshes access tokens in the background when they are near expiry. You do not need to re-run `uip login` unless the refresh token itself expires or is revoked, or you change tenants/organizations.

### Headless interactive login (`--no-browser`)

`uip login` normally opens your system browser. In a headless environment — a CI driver that needs a real **user** identity (with a refresh token) rather than an External App, but has no display — pass `--no-browser` (or set `UIPATH_CLI_NO_BROWSER=true`):

```bash
uip login --no-browser --tenant DefaultTenant
```

This keeps the entire interactive flow (PKCE, state, local callback, token save) but does not launch a browser. Instead it prints the authorize URL to **stderr** as a stable marker line:

```
UIPATH_AUTH_URL https://cloud.uipath.com/identity_/connect/authorize?...
```

An external automation (for example, a Playwright script) reads that line, opens the URL in a browser it controls, completes sign-in, and the identity provider redirects to `uip`'s local callback as usual — completing the login the same way as if a human had clicked through.

The printed URL is safe to appear in CI logs: it carries only public OAuth values (PKCE `code_challenge`, `state`, `client_id`, `redirect_uri`, `scope`) — no secret and no token. `--no-browser` has no effect on Flow 2 or Flow 3 (client-credentials and federated login never open a browser regardless) — a warning is logged if you pass it alongside `--client-secret` or `--client-assertion`.

## Flow 2 — External Application (client credentials)

Create an External Application in UiPath (Automation Cloud: **Admin → External Applications**) with:

- Application type: **Confidential**
- Grant type: **Client credentials**
- Scopes: the scopes your pipeline needs (for example, `OR.Folders`, `OR.Jobs`, `OR.Execution`, `OR.Assets`, `OR.Users`)

For the scopes `uip tm` commands need, see [Scopes for uip tm](./uip-test-manager-scopes.md).

Copy the generated **App ID** and **App Secret**, and store them in the pipeline's secret store (GitHub Actions secrets, Azure DevOps variable groups, Jenkins credentials, Vault, etc.).

Sign in from the pipeline:

```bash
uip login \
  --client-id env.UIPATH_CLIENT_ID \
  --client-secret env.UIPATH_CLIENT_SECRET \
  --tenant "$UIPATH_TENANT"
```

### The env.VAR_NAME prefix

`--client-id` and `--client-secret` accept either a literal value or the **special prefix `env.`** that resolves to an environment variable at runtime. `env.UIPATH_CLIENT_ID` means "read the value from the `UIPATH_CLIENT_ID` environment variable". This keeps secret values out of shell history and process listings — unlike `--client-secret "$UIPATH_CLIENT_SECRET"`, which expands on the command line.

Literal values still work:

```bash
uip login --client-id 3c7af0…-… --client-secret s3cr3t…   # works, but the secret is visible in history
```

:::warning
Do **not** set `UIPATH_CLIENT_ID` / `UIPATH_CLIENT_SECRET` as environment variables and expect `uip login` to pick them up automatically. Prior to UiPath CLI 1.0, `uip login --env` and implicit env-var reading were supported; they were removed. You must pass the flag explicitly, either with a literal value or with the `env.` prefix.
:::

### Scope overrides

If the External App has multiple scopes and you want a narrower session for a specific script, pass `--scope`:

```bash
uip login \
  --client-id env.UIPATH_CLIENT_ID \
  --client-secret env.UIPATH_CLIENT_SECRET \
  --tenant "$UIPATH_TENANT" \
  --scope "OR.Folders OR.Jobs"
```

## Flow 3 — Federated credentials (workload identity)

For CI/CD platforms that can mint their own OIDC token — no External App client secret to create, store, or rotate:

```bash
uip login \
  --client-id "$UIPATH_CLIENT_ID" \
  --client-assertion env.OIDC_TOKEN \
  --tenant "$UIPATH_TENANT"
```

`--client-assertion` takes an OIDC JWT in place of `--client-secret`, and — like `--client-id`/`--client-secret` — accepts the `env.` prefix to read the token from an environment variable at runtime (recommended: passing the raw JWT as a literal value prints a warning, since it would otherwise be visible in shell history and process listings).

Rules enforced by `uip login`:

- **Requires `--client-id`.** Federated login still identifies the External App by its client ID; only the secret is replaced.
- **Mutually exclusive with `--client-secret`.** Passing both fails with `--client-secret cannot be combined with --client-assertion.`
- **`--organization` is ignored** — the organization is fixed by the client ID, same as client-credentials login.
- **`--no-browser` has no effect** — like client-credentials login, no browser is opened for this flow regardless.

Once authenticated, the session behaves like an External App session: it's persisted, refreshed automatically, and cleared with `uip logout`.

## Flow 4 — Environment-variable auth (access token already in hand)

Some environments — containers built by another pipeline, scheduled jobs, test fixtures — already hold a valid UiPath access token and have no need for interactive sign-in or client-credentials exchange. Enable the env-var auth flow by setting:

```bash
export UIPATH_CLI_ENABLE_ENV_AUTH=true

export UIPATH_CLI_AUTH_TOKEN="$UIPATH_TOKEN"            # JWT access token
export UIPATH_CLI_ORGANIZATION_NAME=my-org
export UIPATH_CLI_ORGANIZATION_ID="$UIPATH_ORG_ID"
export UIPATH_CLI_TENANT_NAME=DefaultTenant
export UIPATH_CLI_TENANT_ID="$UIPATH_TENANT_ID"
```

With `UIPATH_CLI_ENABLE_ENV_AUTH=true`, every `uip` invocation authenticates from these variables and bypasses the `.uipath/` folder entirely. There is no `uip login` step and nothing is written to disk.

### Notes and limitations

- **Opaque token.** The caller is responsible for the token's freshness. There is no refresh flow. When the token expires, `uip login status` reports `Expired` and commands fail until the variable is rotated.
- **Server URL is derived from a JWT.** When `UIPATH_CLI_AUTH_TOKEN` holds a JWT access token, its `iss` claim is authoritative — you do not set `UIPATH_URL`. This prevents mis-routing when a pipeline sets `UIPATH_URL` inconsistently with the token. This does **not** hold for a Personal Access Token — see below.
- **The gate matters.** If `UIPATH_CLI_ENABLE_ENV_AUTH` is unset or set to anything other than the literal string `true`, the file-based flow is used. Misspelling the gate silently falls back — check with `uip login status`.
- **Missing values fail explicitly.** If any required variable is empty, `uip` returns a clear error naming the offending variable, not a generic "not authenticated".
- **Saved logins are not used.** While `UIPATH_CLI_ENABLE_ENV_AUTH=true`, every command signs in with the `UIPATH_CLI_*` variables. A command run with `--profile <name>`, and `uip login` itself, print a warning to stderr that the profile or the new login is not used. Unset `UIPATH_CLI_ENABLE_ENV_AUTH` to use a saved login.

Example GitHub Actions step using env-var auth:

```yaml
- name: Run uip against Orchestrator
  env:
    UIPATH_CLI_ENABLE_ENV_AUTH: "true"
    UIPATH_CLI_AUTH_TOKEN: ${{ secrets.UIPATH_TOKEN }}
    UIPATH_CLI_ORGANIZATION_NAME: contoso
    UIPATH_CLI_ORGANIZATION_ID: ${{ secrets.UIPATH_ORG_ID }}
    UIPATH_CLI_TENANT_NAME: Default
    UIPATH_CLI_TENANT_ID: ${{ secrets.UIPATH_TENANT_ID }}
  run: uip or folders list --output json
```

### Using a Personal Access Token instead of a JWT

`UIPATH_CLI_AUTH_TOKEN` also accepts a UiPath Personal Access Token (PAT — an opaque "reference token"), minted with `uip admin pat create` and managed with `uip admin pat list/revoke/regenerate`. A PAT is not a JWT, so it carries no `iss` claim — which changes one rule from above:

- **`UIPATH_URL` becomes required.** Since the CLI cannot derive a server URL from an opaque token, set `UIPATH_URL` (e.g. `https://cloud.uipath.com`) explicitly. It's ignored when the token is a JWT, but required when it's a PAT.
- **No expiration is reported.** `uip login status` shows `Logged in` with no expiration date and no identity fields — the token is opaque, so the CLI has no way to know either. Commands fail with `401` once the PAT is revoked or expires, with no local warning beforehand — track the expiry date yourself.
- Every other variable in this flow (the gate, tenant/organization names and IDs) works the same as with a JWT.

## Flow 5 — Robot credentials (local UiPath Robot)

For processes running alongside a local UiPath Robot — Studio Desktop and other Robot-hosted contexts — authentication can defer entirely to the Robot's own identity over a local IPC channel, instead of any token the CLI manages itself:

```bash
export UIPATH_CLI_ENFORCE_ROBOT_AUTH=true
uip or folders list
```

With the gate set, `uip` talks to the Robot's IPC endpoint for both the access token and the resource base URL, bypassing the `.uipath/` credentials folder and the env-var flow entirely. `UIPATH_CLI_ENFORCE_ROBOT_AUTH` and `UIPATH_CLI_ENABLE_ENV_AUTH` are mutually exclusive — setting both is an error, not a silent override. There is no `uip login` step, no refresh to manage, and nothing for `uip logout` to clear.

## Signing out

```bash
uip logout                         # clear the default credentials folder
uip logout --file /path/to/creds   # clear a non-default credentials folder
```

`logout` clears the stored session inside `.uipath/`. On the env-var flow there is nothing to remove — unset the variables.

## Troubleshooting

### ❌ Not logged in

Either no `.uipath/` folder was found on the walk-up chain, or the stored session is unreadable. Run `uip login` (or set the env-var flow) and retry.

### Token expired

Interactive and External App sessions refresh automatically when near expiry. If you see `Expired`, the refresh token itself expired or was revoked — re-run `uip login`. For env-var auth, rotate `UIPATH_CLI_AUTH_TOKEN`.

### Multiple org members, wrong org picked

Pass `--organization <logical-name>` on `uip login` to bypass the org picker, or `uip login tenant list` after the fact to see what the session is actually bound to.

### Corporate proxy blocks the browser callback

The interactive flow opens a local callback port on `127.0.0.1`. Most proxies leave loopback alone, but some aggressive setups block it. Work around by using Flow 2 (External App), Flow 3 (federated credentials), or Flow 4 (env-var auth) — all three avoid the browser callback entirely.

## See also

- [Installing UiPath CLI](./installing-uipath-cli.md) — one-time setup before authentication.
- [Configuration](./configuration.md) — environment variables and flag precedence.
- [Sessions and credentials](./concepts-sessions.md) — on-disk layout of the credentials folder.
- [uip login reference](./uip-login.md), [uip logout reference](./uip-logout.md).
