@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.cjs CHANGED
@@ -34,7 +34,7 @@ __export(index_exports, {
34
34
  MissingRequiredArgumentError: () => MissingRequiredArgumentError,
35
35
  MissingSessionError: () => MissingSessionError,
36
36
  MissingTransactionError: () => MissingTransactionError,
37
- OrganizationValidationError: () => import_auth0_auth_js3.OrganizationValidationError,
37
+ OrganizationValidationError: () => import_auth0_auth_js4.OrganizationValidationError,
38
38
  PasskeyChallengeError: () => import_auth0_auth_js3.PasskeyChallengeError,
39
39
  PasskeyGetTokenError: () => import_auth0_auth_js3.PasskeyGetTokenError,
40
40
  PasskeyRegisterError: () => import_auth0_auth_js3.PasskeyRegisterError,
@@ -250,7 +250,7 @@ function getTelemetryConfig(config) {
250
250
  return {
251
251
  enabled: true,
252
252
  name: config?.name ?? "@auth0/auth0-server-js",
253
- version: config?.version ?? "1.8.0"
253
+ version: config?.version ?? "1.9.0"
254
254
  };
255
255
  }
256
256
 
@@ -601,9 +601,16 @@ var ServerClient = class {
601
601
  }
602
602
  /**
603
603
  * Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
604
+ *
605
+ * When `organization` is provided (per-login option, client-level default, or via
606
+ * `authorizationParams.organization`), it is forwarded to `/authorize` and remembered so the
607
+ * returned ID token's organization claim can be validated in `completeInteractiveLogin`.
608
+ *
604
609
  * @param options Optional options used to configure the interactive login process.
605
610
  * @param storeOptions Optional options used to pass to the Transaction and State Store.
606
611
  *
612
+ * @throws {OrganizationValidationError} If the resolved `organization` is blank.
613
+ * @throws {InvalidConfigurationError} If `invitation` is provided without an `organization`.
607
614
  * @throws {BuildAuthorizationUrlError} If there was an issue when building the Authorization URL.
608
615
  *
609
616
  * @returns A promise resolving to a URL object, representing the URL to redirect the user-agent to to request authorization at Auth0.
@@ -614,6 +621,16 @@ var ServerClient = class {
614
621
  throw new MissingRequiredArgumentError("authorizationParams.redirect_uri");
615
622
  }
616
623
  const scope = ensureOpenIdScope(options?.authorizationParams?.scope ?? this.#options.authorizationParams?.scope);
624
+ const perLoginAuthParamsOrganization = typeof options?.authorizationParams?.organization === "string" ? options.authorizationParams.organization : void 0;
625
+ const clientAuthParamsOrganization = typeof this.#options.authorizationParams?.organization === "string" ? this.#options.authorizationParams.organization : void 0;
626
+ const resolvedOrganization = options?.organization ?? perLoginAuthParamsOrganization ?? this.#options.organization ?? clientAuthParamsOrganization;
627
+ if (resolvedOrganization !== void 0 && !resolvedOrganization.trim()) {
628
+ throw new import_auth0_auth_js.OrganizationValidationError("organization must not be blank");
629
+ }
630
+ const hasInvitation = !!(options?.invitation || options?.authorizationParams?.invitation);
631
+ if (hasInvitation && !resolvedOrganization) {
632
+ throw new InvalidConfigurationError("organization is required when invitation is provided.");
633
+ }
617
634
  const domain = await this.#resolveDomain(storeOptions);
618
635
  const authClient = this.#getAuthClient(domain);
619
636
  const { codeVerifier, authorizationUrl } = await authClient.buildAuthorizationUrl({
@@ -621,7 +638,9 @@ var ServerClient = class {
621
638
  authorizationParams: {
622
639
  ...options?.authorizationParams,
623
640
  redirect_uri: redirectUri,
624
- scope
641
+ scope,
642
+ ...resolvedOrganization ? { organization: resolvedOrganization } : {},
643
+ ...options?.invitation ? { invitation: options.invitation } : {}
625
644
  }
626
645
  });
627
646
  const transactionState = {
@@ -629,6 +648,9 @@ var ServerClient = class {
629
648
  codeVerifier,
630
649
  domain
631
650
  };
651
+ if (resolvedOrganization) {
652
+ transactionState.organization = resolvedOrganization;
653
+ }
632
654
  if (options?.appState) {
633
655
  transactionState.appState = options.appState;
634
656
  }
@@ -643,6 +665,7 @@ var ServerClient = class {
643
665
  *
644
666
  * @throws {MissingTransactionError} When no transaction was found.
645
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.
646
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.
647
670
  *
648
671
  * @returns A promise resolving to an object, containing the original appState (if present) and the authorizationDetails (when RAR was used).
@@ -656,7 +679,8 @@ var ServerClient = class {
656
679
  const authClient = this.#getAuthClient(domain);
657
680
  const tokenEndpointResponse = await authClient.getTokenByCode(url, {
658
681
  // TransactionData.codeVerifier is optional only to accommodate magic-link transactions.
659
- codeVerifier: transactionData.codeVerifier
682
+ codeVerifier: transactionData.codeVerifier,
683
+ organization: transactionData.organization
660
684
  });
661
685
  await this.#transactionStore.delete(this.#transactionStoreIdentifier, storeOptions);
662
686
  const existingStateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);