@uipath/auth 1.1.0 → 1.196.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ import { type GetLoginStatusOptions, type LoginStatus } from "./loginStatus";
2
+ export interface AuthContext {
3
+ baseUrl: string;
4
+ accessToken: string;
5
+ organizationId?: string;
6
+ organizationName?: string;
7
+ tenantId?: string;
8
+ tenantName?: string;
9
+ }
10
+ export interface GetAuthContextOptions {
11
+ tenant?: string;
12
+ ensureTokenValidityMinutes?: number;
13
+ requireOrganizationId?: boolean;
14
+ requireOrganizationName?: boolean;
15
+ requireTenantId?: boolean;
16
+ requireTenantName?: boolean;
17
+ /**
18
+ * Resolve credentials from this exact `.uipath/.auth` path instead of the
19
+ * default cwd→ancestors→home walk-up. Lets an in-process host (e.g. the VS
20
+ * Code extension) pin auth to a specific file — the same `envFilePath`
21
+ * {@link getLoginStatusAsync} already accepts — so concurrent operations
22
+ * against different credential files don't cross-contaminate.
23
+ */
24
+ envFilePath?: string;
25
+ }
26
+ export declare const getAuthContext: (options?: GetAuthContextOptions) => Promise<AuthContext>;
27
+ export interface AuthEnvResult {
28
+ /** UiPath credential env vars to merge into a subprocess env. Empty when not logged in. */
29
+ authEnv: Record<string, string>;
30
+ /** The login status used to build {@link authEnv}, or undefined when it could not be read. */
31
+ loginStatus?: LoginStatus;
32
+ }
33
+ /**
34
+ * Build UiPath credential env vars from the live `uip login` status, for
35
+ * injecting into a spawned process. The token is refreshed so the child gets
36
+ * a valid bearer token, not a stale one off disk. Never throws: returns an
37
+ * empty `authEnv` when there is no usable login.
38
+ */
39
+ export declare const getAuthEnv: (options?: GetLoginStatusOptions) => Promise<AuthEnvResult>;
@@ -0,0 +1,5 @@
1
+ type CatchErrorResult<T> = [undefined, T] | [Error, undefined];
2
+ export declare function catchError<T>(fnOrPromise: Promise<T>): Promise<CatchErrorResult<T>>;
3
+ export declare function catchError<T>(fnOrPromise: () => Promise<T>): Promise<CatchErrorResult<T>>;
4
+ export declare function catchError<T>(fnOrPromise: () => T): CatchErrorResult<T>;
5
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { BaseCredentials } from "./types";
2
+ interface ClientCredentialsLoginProps {
3
+ clientId: string;
4
+ clientSecret: string;
5
+ scope?: string[];
6
+ authority?: string;
7
+ }
8
+ export declare const clientCredentialsLogin: ({ clientId, clientSecret, scope, authority, }: ClientCredentialsLoginProps) => Promise<BaseCredentials>;
9
+ export {};
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Auth-relevant slice of the on-disk CLI config. Auth itself does no
3
+ * filesystem I/O — the CLI loads `.uipath/config.json`, picks the `auth`
4
+ * section, and pushes it here via {@link setAuthFileConfig}. Tools that
5
+ * bundle their own copy of `@uipath/auth` see the same value because the
6
+ * slot is keyed by `Symbol.for()` on `globalThis`.
7
+ */
8
+ export interface AuthFileConfig {
9
+ clientId?: string;
10
+ clientSecret?: string;
11
+ authority?: string;
12
+ scopes?: string[];
13
+ }
14
+ /**
15
+ * Push the resolved `auth.*` block of the on-disk config into auth.
16
+ * Called by the CLI host once at startup; safe to call repeatedly.
17
+ */
18
+ export declare const setAuthFileConfig: (cfg: AuthFileConfig | undefined) => void;
19
+ /**
20
+ * Error thrown when an invalid base URL is provided
21
+ */
22
+ export declare class InvalidBaseUrlError extends Error {
23
+ readonly url: string;
24
+ readonly reason: string;
25
+ constructor(url: string, reason: string);
26
+ }
27
+ /**
28
+ * Default OAuth scopes requested during authentication.
29
+ *
30
+ * Identity is expected to expand the issued token to every scope granted
31
+ * to the CLI client (the "assistant pattern"), so the CLI only asks for
32
+ * the OIDC base set. Adding product-specific scopes here re-introduces
33
+ * per-deployment configuration coupling on Automation Suite, where each
34
+ * scope must be granted to the client in the Identity database.
35
+ */
36
+ export declare const DEFAULT_SCOPES: string[];
37
+ interface EndpointsConfig {
38
+ clientId: string;
39
+ clientSecret?: string;
40
+ baseUrl: string;
41
+ authorizationEndpoint: string;
42
+ tokenEndpoint: string;
43
+ /**
44
+ * Effective scope list: caller-provided scope wins; file-config
45
+ * `auth.scopes` is the secondary fallback; {@link DEFAULT_SCOPES} the
46
+ * tertiary. Pre-resolved here so callers can trust a single source of
47
+ * truth instead of re-implementing the precedence at every call site.
48
+ */
49
+ scopes: string[];
50
+ }
51
+ interface ResolveConfigProps {
52
+ customAuthority?: string;
53
+ customClientId?: string;
54
+ customClientSecret?: string;
55
+ customScopes?: string[];
56
+ }
57
+ /**
58
+ * Normalize and validate a UiPath base URL.
59
+ *
60
+ * Applies the same rules used by the interactive login flow so every
61
+ * source of baseUrl (user config, env var, JWT `iss` claim) produces
62
+ * a canonical `https://<host>` string:
63
+ * • strips a trailing `/identity_` or `/identity_/` (users paste the
64
+ * full identity endpoint and we need just the authority);
65
+ * • strips trailing slashes;
66
+ * • validates the result as a parseable `https://` URL;
67
+ * • strips any path segments — organization is carried separately.
68
+ *
69
+ * Throws {@link InvalidBaseUrlError} on any failure.
70
+ */
71
+ export declare const normalizeAndValidateBaseUrl: (rawUrl: string) => string;
72
+ export declare const resolveConfigAsync: ({ customAuthority, customClientId, customClientSecret, customScopes, }?: ResolveConfigProps) => Promise<EndpointsConfig>;
73
+ export {};
@@ -0,0 +1,10 @@
1
+ /** Home directory for UiPath CLI auth data: ~/.uipath/ */
2
+ export declare const UIPATH_HOME_DIR = ".uipath";
3
+ /** Auth credentials filename within the UiPath home directory. */
4
+ export declare const AUTH_FILENAME = ".auth";
5
+ /** Default UiPath cloud base URL. */
6
+ export declare const DEFAULT_BASE_URL = "https://cloud.uipath.com";
7
+ /** Auth callback server timeout (5 minutes). */
8
+ export declare const DEFAULT_AUTH_TIMEOUT_MS: number;
9
+ /** Localhost OIDC redirect URI. */
10
+ export declare const DEFAULT_REDIRECT_URI = "http://localhost:8104/oidc/login";
@@ -0,0 +1,75 @@
1
+ import type { LoginStatus } from "./loginStatus";
2
+ /**
3
+ * Environment variable that opts the CLI into sourcing authentication
4
+ * data from env vars instead of the `.uipath/.auth` file. Must be set
5
+ * to the literal string `"true"`.
6
+ */
7
+ export declare const ENV_AUTH_ENABLE_VAR = "UIPATH_CLI_ENABLE_ENV_AUTH";
8
+ /**
9
+ * Environment variable that opts the CLI into Robot-IPC-only authentication.
10
+ * Must be set to the literal string `"true"`. When set:
11
+ * - `~/.uipath/.auth` is **not consulted** (file lookup is skipped entirely;
12
+ * a stale or expired file cannot block the Robot path).
13
+ * - `UIPATH_CLI_ENABLE_ENV_AUTH=true` set in parallel raises
14
+ * {@link EnvAuthConfigError} ("mutually exclusive flags") rather than
15
+ * being silently overridden — the two opt-ins contradict each other and
16
+ * the user must resolve the conflict.
17
+ * - The Robot fallback runs first and is required to succeed.
18
+ * - If the Robot is not running / not signed in, the CLI returns
19
+ * `loginStatus: "Not logged in"` with a hint pointing at this env var
20
+ * and the Assistant — no fallback to file or env-auth.
21
+ * Intended as a per-process opt-in (set on the spawned `uip` child only)
22
+ * for consumers like Studio Desktop that authenticate through the local
23
+ * Robot. See GH issue #2131.
24
+ */
25
+ export declare const ENFORCE_ROBOT_AUTH_VAR = "UIPATH_CLI_ENFORCE_ROBOT_AUTH";
26
+ /**
27
+ * Names of the env vars consumed when {@link ENV_AUTH_ENABLE_VAR} is
28
+ * enabled. The server URL (`baseUrl`) is not listed here — it is
29
+ * derived from the JWT's `iss` claim, which is the authoritative
30
+ * source for the authority that minted the token.
31
+ *
32
+ * NOTE: insertion order of these keys is the public ordering of the
33
+ * `Vars` array surfaced by `uip login which`. Reordering changes CLI
34
+ * output that programmatic consumers may parse positionally.
35
+ */
36
+ export declare const ENV_AUTH_VARS: {
37
+ readonly token: "UIPATH_CLI_AUTH_TOKEN";
38
+ readonly organizationName: "UIPATH_CLI_ORGANIZATION_NAME";
39
+ readonly organizationId: "UIPATH_CLI_ORGANIZATION_ID";
40
+ readonly tenantName: "UIPATH_CLI_TENANT_NAME";
41
+ readonly tenantId: "UIPATH_CLI_TENANT_ID";
42
+ };
43
+ /**
44
+ * Error thrown when env-var auth is enabled but the configuration is
45
+ * incomplete or invalid. Surfaces the specific variable at fault so
46
+ * the user can correct the CI setup without guessing.
47
+ */
48
+ export declare class EnvAuthConfigError extends Error {
49
+ constructor(message: string);
50
+ }
51
+ /**
52
+ * Whether env-var auth is active. Checked at the top of
53
+ * {@link getLoginStatusWithDeps} so that when the gate is off the
54
+ * existing file-based flow is entirely unaffected.
55
+ */
56
+ export declare const isEnvAuthEnabled: () => boolean;
57
+ /**
58
+ * Whether Robot-only enforcement is active. See {@link ENFORCE_ROBOT_AUTH_VAR}.
59
+ */
60
+ export declare const isRobotAuthEnforced: () => boolean;
61
+ /**
62
+ * Build a {@link LoginStatus} from environment variables, bypassing
63
+ * disk I/O and token refresh entirely.
64
+ *
65
+ * The access token is treated as opaque — whoever populated the env
66
+ * var is responsible for its freshness. If the token carries a JWT
67
+ * `exp` that has already passed, the status is reported as `Expired`
68
+ * (mirroring the file-based flow), but no refresh is attempted: there
69
+ * is no refresh token in the env-var contract and the CLI has no way
70
+ * to update a secret it did not mint.
71
+ *
72
+ * baseUrl is derived from the token's `iss` claim so the env-var set
73
+ * can stay aligned with the GH #1034 spec (five vars, no URL).
74
+ */
75
+ export declare const readAuthFromEnv: () => LoginStatus;
@@ -0,0 +1,7 @@
1
+ interface GetBaseHtmlProps {
2
+ title: string;
3
+ message: string;
4
+ type: "success" | "error";
5
+ }
6
+ export declare const getBaseHtml: ({ title, message, type }: GetBaseHtmlProps) => string;
7
+ export {};
@@ -0,0 +1,10 @@
1
+ export * from "./authContext";
2
+ export * from "./clientCredentials";
3
+ export { type AuthFileConfig, InvalidBaseUrlError, setAuthFileConfig, } from "./config";
4
+ export * from "./loginStatus";
5
+ export * from "./logout";
6
+ export { fetchTenantsAndOrganizations, type Tenant, type TenantsAndOrganizations, } from "./tenantSelection";
7
+ export * from "./tokenRefresh";
8
+ export type { BaseCredentials } from "./types";
9
+ export { DEFAULT_AUTH_FILENAME, DEFAULT_ENV_FILENAME, type EnvFileErrorCode, type EnvFileLocation, type EnvFileSource, type EnvFileUnusable, type EnvFileUnusableReason, loadEnvFileAsync, resolveEnvFileLocationAsync, resolveEnvFilePathAsync, saveEnvFileAsync, } from "./utils/envFile";
10
+ export { isBrowser, isNode } from "./utils/platform";