@auth0/auth0-server-js 1.8.0 → 1.9.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.
package/dist/index.d.cts CHANGED
@@ -26,6 +26,12 @@ interface ServerClientOptions<TStoreOptions = unknown> {
26
26
  clientAssertionSigningKey?: string | CryptoKey;
27
27
  clientAssertionSigningAlg?: string;
28
28
  authorizationParams?: AuthorizationParameters;
29
+ /**
30
+ * Default organization for all interactive login flows from this client.
31
+ * Can be an organization ID (e.g. `org_abc123`) or an organization name (e.g. `acme-corp`).
32
+ * A per-login value in {@link StartInteractiveLoginOptions} overrides this.
33
+ */
34
+ organization?: string;
29
35
  discoveryCache?: DiscoveryCacheOptions;
30
36
  transactionIdentifier?: string;
31
37
  stateIdentifier?: string;
@@ -57,12 +63,19 @@ interface UserClaims {
57
63
  email?: string;
58
64
  email_verified?: boolean;
59
65
  org_id?: string;
66
+ org_name?: string;
60
67
  [key: string]: unknown;
61
68
  }
62
69
  interface AuthorizationParameters {
63
70
  scope?: string;
64
71
  audience?: string;
65
72
  redirect_uri?: string;
73
+ /**
74
+ * The organization to log the user into. Prefer the first-class `organization`
75
+ * option on {@link StartInteractiveLoginOptions} / {@link ServerClientOptions};
76
+ * this is supported for backwards compatibility.
77
+ */
78
+ organization?: string;
66
79
  [key: string]: unknown;
67
80
  }
68
81
  interface TokenSet {
@@ -112,6 +125,11 @@ interface TransactionData {
112
125
  */
113
126
  codeVerifier?: string;
114
127
  domain?: string;
128
+ /**
129
+ * The organization requested at login, carried across the redirect so the
130
+ * returned ID token's organization claim can be validated at callback.
131
+ */
132
+ organization?: string;
115
133
  [key: string]: unknown;
116
134
  }
117
135
  interface AbstractDataStore<TData, TStoreOptions = unknown> {
@@ -146,6 +164,18 @@ interface StartInteractiveLoginOptions<TAppState = unknown> {
146
164
  pushedAuthorizationRequests?: boolean;
147
165
  appState?: TAppState;
148
166
  authorizationParams?: AuthorizationParameters;
167
+ /**
168
+ * The organization to log the user into. Overrides the client-level
169
+ * `organization` default. Can be an organization ID (`org_abc123`) or name
170
+ * (`acme-corp`). Also passable via `authorizationParams.organization`.
171
+ */
172
+ organization?: string;
173
+ /**
174
+ * The organization invitation ticket, when handling an invitation-acceptance flow.
175
+ * Requires `organization` to be set (per-login, client-level default, or via
176
+ * `authorizationParams`); providing `invitation` without an organization throws.
177
+ */
178
+ invitation?: string;
149
179
  }
150
180
  interface LoginBackchannelOptions {
151
181
  bindingMessage: string;
@@ -612,9 +642,16 @@ declare class ServerClient<TStoreOptions = unknown> {
612
642
  constructor(options: ServerClientOptions<TStoreOptions>);
613
643
  /**
614
644
  * Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
645
+ *
646
+ * When `organization` is provided (per-login option, client-level default, or via
647
+ * `authorizationParams.organization`), it is forwarded to `/authorize` and remembered so the
648
+ * returned ID token's organization claim can be validated in `completeInteractiveLogin`.
649
+ *
615
650
  * @param options Optional options used to configure the interactive login process.
616
651
  * @param storeOptions Optional options used to pass to the Transaction and State Store.
617
652
  *
653
+ * @throws {OrganizationValidationError} If the resolved `organization` is blank.
654
+ * @throws {InvalidConfigurationError} If `invitation` is provided without an `organization`.
618
655
  * @throws {BuildAuthorizationUrlError} If there was an issue when building the Authorization URL.
619
656
  *
620
657
  * @returns A promise resolving to a URL object, representing the URL to redirect the user-agent to to request authorization at Auth0.
@@ -628,6 +665,7 @@ declare class ServerClient<TStoreOptions = unknown> {
628
665
  *
629
666
  * @throws {MissingTransactionError} When no transaction was found.
630
667
  * @throws {TokenByCodeError} If there was an issue requesting the access token.
668
+ * @throws {OrganizationValidationError} When an organization was requested at login and the returned ID token's organization claim is missing or does not match; nothing is persisted.
631
669
  * @throws {SessionExpiredError} When the ID token's `session_expiry` is already in the past at login (the session is born expired); nothing is persisted.
632
670
  *
633
671
  * @returns A promise resolving to an object, containing the original appState (if present) and the authorizationDetails (when RAR was used).
package/dist/index.d.ts CHANGED
@@ -26,6 +26,12 @@ interface ServerClientOptions<TStoreOptions = unknown> {
26
26
  clientAssertionSigningKey?: string | CryptoKey;
27
27
  clientAssertionSigningAlg?: string;
28
28
  authorizationParams?: AuthorizationParameters;
29
+ /**
30
+ * Default organization for all interactive login flows from this client.
31
+ * Can be an organization ID (e.g. `org_abc123`) or an organization name (e.g. `acme-corp`).
32
+ * A per-login value in {@link StartInteractiveLoginOptions} overrides this.
33
+ */
34
+ organization?: string;
29
35
  discoveryCache?: DiscoveryCacheOptions;
30
36
  transactionIdentifier?: string;
31
37
  stateIdentifier?: string;
@@ -57,12 +63,19 @@ interface UserClaims {
57
63
  email?: string;
58
64
  email_verified?: boolean;
59
65
  org_id?: string;
66
+ org_name?: string;
60
67
  [key: string]: unknown;
61
68
  }
62
69
  interface AuthorizationParameters {
63
70
  scope?: string;
64
71
  audience?: string;
65
72
  redirect_uri?: string;
73
+ /**
74
+ * The organization to log the user into. Prefer the first-class `organization`
75
+ * option on {@link StartInteractiveLoginOptions} / {@link ServerClientOptions};
76
+ * this is supported for backwards compatibility.
77
+ */
78
+ organization?: string;
66
79
  [key: string]: unknown;
67
80
  }
68
81
  interface TokenSet {
@@ -112,6 +125,11 @@ interface TransactionData {
112
125
  */
113
126
  codeVerifier?: string;
114
127
  domain?: string;
128
+ /**
129
+ * The organization requested at login, carried across the redirect so the
130
+ * returned ID token's organization claim can be validated at callback.
131
+ */
132
+ organization?: string;
115
133
  [key: string]: unknown;
116
134
  }
117
135
  interface AbstractDataStore<TData, TStoreOptions = unknown> {
@@ -146,6 +164,18 @@ interface StartInteractiveLoginOptions<TAppState = unknown> {
146
164
  pushedAuthorizationRequests?: boolean;
147
165
  appState?: TAppState;
148
166
  authorizationParams?: AuthorizationParameters;
167
+ /**
168
+ * The organization to log the user into. Overrides the client-level
169
+ * `organization` default. Can be an organization ID (`org_abc123`) or name
170
+ * (`acme-corp`). Also passable via `authorizationParams.organization`.
171
+ */
172
+ organization?: string;
173
+ /**
174
+ * The organization invitation ticket, when handling an invitation-acceptance flow.
175
+ * Requires `organization` to be set (per-login, client-level default, or via
176
+ * `authorizationParams`); providing `invitation` without an organization throws.
177
+ */
178
+ invitation?: string;
149
179
  }
150
180
  interface LoginBackchannelOptions {
151
181
  bindingMessage: string;
@@ -612,9 +642,16 @@ declare class ServerClient<TStoreOptions = unknown> {
612
642
  constructor(options: ServerClientOptions<TStoreOptions>);
613
643
  /**
614
644
  * Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
645
+ *
646
+ * When `organization` is provided (per-login option, client-level default, or via
647
+ * `authorizationParams.organization`), it is forwarded to `/authorize` and remembered so the
648
+ * returned ID token's organization claim can be validated in `completeInteractiveLogin`.
649
+ *
615
650
  * @param options Optional options used to configure the interactive login process.
616
651
  * @param storeOptions Optional options used to pass to the Transaction and State Store.
617
652
  *
653
+ * @throws {OrganizationValidationError} If the resolved `organization` is blank.
654
+ * @throws {InvalidConfigurationError} If `invitation` is provided without an `organization`.
618
655
  * @throws {BuildAuthorizationUrlError} If there was an issue when building the Authorization URL.
619
656
  *
620
657
  * @returns A promise resolving to a URL object, representing the URL to redirect the user-agent to to request authorization at Auth0.
@@ -628,6 +665,7 @@ declare class ServerClient<TStoreOptions = unknown> {
628
665
  *
629
666
  * @throws {MissingTransactionError} When no transaction was found.
630
667
  * @throws {TokenByCodeError} If there was an issue requesting the access token.
668
+ * @throws {OrganizationValidationError} When an organization was requested at login and the returned ID token's organization claim is missing or does not match; nothing is persisted.
631
669
  * @throws {SessionExpiredError} When the ID token's `session_expiry` is already in the past at login (the session is born expired); nothing is persisted.
632
670
  *
633
671
  * @returns A promise resolving to an object, containing the original appState (if present) and the authorizationDetails (when RAR was used).
package/dist/index.js CHANGED
@@ -163,6 +163,7 @@ function updateStateDataForConnectionTokenSet(options, stateData, tokenEndpointR
163
163
  import {
164
164
  TokenForConnectionError,
165
165
  AuthClient,
166
+ OrganizationValidationError,
166
167
  PasswordlessStartError,
167
168
  PasswordlessVerifyError,
168
169
  TokenByRefreshTokenError
@@ -204,7 +205,7 @@ function getTelemetryConfig(config) {
204
205
  return {
205
206
  enabled: true,
206
207
  name: config?.name ?? "@auth0/auth0-server-js",
207
- version: config?.version ?? "1.8.0"
208
+ version: config?.version ?? "1.9.0"
208
209
  };
209
210
  }
210
211
 
@@ -555,9 +556,16 @@ var ServerClient = class {
555
556
  }
556
557
  /**
557
558
  * Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
559
+ *
560
+ * When `organization` is provided (per-login option, client-level default, or via
561
+ * `authorizationParams.organization`), it is forwarded to `/authorize` and remembered so the
562
+ * returned ID token's organization claim can be validated in `completeInteractiveLogin`.
563
+ *
558
564
  * @param options Optional options used to configure the interactive login process.
559
565
  * @param storeOptions Optional options used to pass to the Transaction and State Store.
560
566
  *
567
+ * @throws {OrganizationValidationError} If the resolved `organization` is blank.
568
+ * @throws {InvalidConfigurationError} If `invitation` is provided without an `organization`.
561
569
  * @throws {BuildAuthorizationUrlError} If there was an issue when building the Authorization URL.
562
570
  *
563
571
  * @returns A promise resolving to a URL object, representing the URL to redirect the user-agent to to request authorization at Auth0.
@@ -568,6 +576,16 @@ var ServerClient = class {
568
576
  throw new MissingRequiredArgumentError("authorizationParams.redirect_uri");
569
577
  }
570
578
  const scope = ensureOpenIdScope(options?.authorizationParams?.scope ?? this.#options.authorizationParams?.scope);
579
+ const perLoginAuthParamsOrganization = typeof options?.authorizationParams?.organization === "string" ? options.authorizationParams.organization : void 0;
580
+ const clientAuthParamsOrganization = typeof this.#options.authorizationParams?.organization === "string" ? this.#options.authorizationParams.organization : void 0;
581
+ const resolvedOrganization = options?.organization ?? perLoginAuthParamsOrganization ?? this.#options.organization ?? clientAuthParamsOrganization;
582
+ if (resolvedOrganization !== void 0 && !resolvedOrganization.trim()) {
583
+ throw new OrganizationValidationError("organization must not be blank");
584
+ }
585
+ const hasInvitation = !!(options?.invitation || options?.authorizationParams?.invitation);
586
+ if (hasInvitation && !resolvedOrganization) {
587
+ throw new InvalidConfigurationError("organization is required when invitation is provided.");
588
+ }
571
589
  const domain = await this.#resolveDomain(storeOptions);
572
590
  const authClient = this.#getAuthClient(domain);
573
591
  const { codeVerifier, authorizationUrl } = await authClient.buildAuthorizationUrl({
@@ -575,7 +593,9 @@ var ServerClient = class {
575
593
  authorizationParams: {
576
594
  ...options?.authorizationParams,
577
595
  redirect_uri: redirectUri,
578
- scope
596
+ scope,
597
+ ...resolvedOrganization ? { organization: resolvedOrganization } : {},
598
+ ...options?.invitation ? { invitation: options.invitation } : {}
579
599
  }
580
600
  });
581
601
  const transactionState = {
@@ -583,6 +603,9 @@ var ServerClient = class {
583
603
  codeVerifier,
584
604
  domain
585
605
  };
606
+ if (resolvedOrganization) {
607
+ transactionState.organization = resolvedOrganization;
608
+ }
586
609
  if (options?.appState) {
587
610
  transactionState.appState = options.appState;
588
611
  }
@@ -597,6 +620,7 @@ var ServerClient = class {
597
620
  *
598
621
  * @throws {MissingTransactionError} When no transaction was found.
599
622
  * @throws {TokenByCodeError} If there was an issue requesting the access token.
623
+ * @throws {OrganizationValidationError} When an organization was requested at login and the returned ID token's organization claim is missing or does not match; nothing is persisted.
600
624
  * @throws {SessionExpiredError} When the ID token's `session_expiry` is already in the past at login (the session is born expired); nothing is persisted.
601
625
  *
602
626
  * @returns A promise resolving to an object, containing the original appState (if present) and the authorizationDetails (when RAR was used).
@@ -610,7 +634,8 @@ var ServerClient = class {
610
634
  const authClient = this.#getAuthClient(domain);
611
635
  const tokenEndpointResponse = await authClient.getTokenByCode(url, {
612
636
  // TransactionData.codeVerifier is optional only to accommodate magic-link transactions.
613
- codeVerifier: transactionData.codeVerifier
637
+ codeVerifier: transactionData.codeVerifier,
638
+ organization: transactionData.organization
614
639
  });
615
640
  await this.#transactionStore.delete(this.#transactionStoreIdentifier, storeOptions);
616
641
  const existingStateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);
@@ -1381,7 +1406,7 @@ var AbstractTransactionStore = class extends AbstractStore {
1381
1406
  };
1382
1407
 
1383
1408
  // src/index.ts
1384
- import { TokenExchangeError, MissingClientAuthError } from "@auth0/auth0-auth-js";
1409
+ import { TokenExchangeError, MissingClientAuthError, OrganizationValidationError as OrganizationValidationError3 } from "@auth0/auth0-auth-js";
1385
1410
 
1386
1411
  // src/store/cookie-transaction-store.ts
1387
1412
  var CookieTransactionStore = class extends AbstractTransactionStore {
@@ -1591,7 +1616,7 @@ import {
1591
1616
  PasskeyRegisterError,
1592
1617
  PasskeyChallengeError,
1593
1618
  PasskeyGetTokenError,
1594
- OrganizationValidationError
1619
+ OrganizationValidationError as OrganizationValidationError2
1595
1620
  } from "@auth0/auth0-auth-js";
1596
1621
  export {
1597
1622
  AbstractStateStore,
@@ -1608,7 +1633,7 @@ export {
1608
1633
  MissingRequiredArgumentError,
1609
1634
  MissingSessionError,
1610
1635
  MissingTransactionError,
1611
- OrganizationValidationError,
1636
+ OrganizationValidationError3 as OrganizationValidationError,
1612
1637
  PasskeyChallengeError,
1613
1638
  PasskeyGetTokenError,
1614
1639
  PasskeyRegisterError,