@auth0/auth0-server-js 1.11.0 → 1.12.1

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
@@ -425,11 +425,19 @@ interface LoginWithCustomTokenExchangeResult {
425
425
  * An explicit actor (the acting party) for a Session Transfer Token request.
426
426
  *
427
427
  * Supplying this overrides the default behaviour of sourcing the actor from the
428
- * current agent session's ID token.
428
+ * current agent session's ID token. The session is not read at all when this is
429
+ * given, so it also works where there is no logged-in agent.
429
430
  */
430
431
  interface SessionTransferActor {
431
432
  /**
432
433
  * The actor token — for the default flow this is the agent's ID token.
434
+ *
435
+ * When {@link SessionTransferActor.type} is the ID token URN (the default), Auth0
436
+ * validates this token and requires an unexpired, asymmetrically-signed Auth0 ID
437
+ * token: signed with `RS256` or `PS256` (`HS256` is rejected, as it uses a shared
438
+ * secret), carrying `sub`, `iss`, `exp` and `iat`, issued to the same client making
439
+ * the exchange, and belonging to a user who still exists and is not blocked. A token
440
+ * failing any of these fails the exchange with a `TokenExchangeError`.
433
441
  */
434
442
  token: string;
435
443
  /**
@@ -462,16 +470,30 @@ interface RequestSessionTransferTokenOptions {
462
470
  /**
463
471
  * An explicit actor to override the default (the agent session's ID token).
464
472
  *
465
- * Resolution order: this explicit `actor` wins; otherwise the agent session's ID
466
- * token is used (refreshed when expired); if neither is available the request fails
467
- * client-side with a `TokenExchangeError` whose code is `actor_unavailable`, before
468
- * any network call.
473
+ * Resolution order: this explicit `actor` wins, and the session is not read at all;
474
+ * otherwise the agent session's ID token is used (refreshed when expired); if neither
475
+ * is available the request fails client-side with a `TokenExchangeError` whose code is
476
+ * `actor_unavailable`, before any network call.
469
477
  */
470
478
  actor?: SessionTransferActor;
471
479
  /**
472
480
  * Space-separated list of OAuth 2.0 scopes to request for the session's tokens.
473
481
  */
474
482
  scope?: string;
483
+ /**
484
+ * The organization (ID or name) to mint the STT in the context of.
485
+ *
486
+ * Sending it here has the tenant validate the organization against the client's
487
+ * organization settings while minting, so an organization the client is not allowed
488
+ * to use fails at this call instead of the STT being issued without it.
489
+ *
490
+ * This is a separate parameter from {@link BuildSessionTransferRedirectOptions.organization},
491
+ * which is forwarded to the target's `/authorize` on the redirect. They are sent on
492
+ * different requests and neither implies the other. The one on the redirect is what
493
+ * org-scopes the session the target establishes, so setting only this one validates the
494
+ * organization without scoping that session.
495
+ */
496
+ organization?: string;
475
497
  /**
476
498
  * Additional custom parameters forwarded to the token endpoint (and thus to your
477
499
  * Action via `event.request.body`). Cannot override reserved OAuth parameters.
@@ -668,6 +690,12 @@ declare class ServerPasskeyClient<TStoreOptions = unknown> {
668
690
  *
669
691
  * This method does not create a session; no state is persisted.
670
692
  *
693
+ * On a confidential client this endpoint accepts `client_secret` as its only
694
+ * credential, so configure `clientSecret` on the `ServerClient`. It does not
695
+ * accept a private key JWT and is not served on the mTLS endpoint aliases, so a
696
+ * client configured with only `clientAssertionSigningKey` or only `useMtls` is
697
+ * rejected by Auth0. Public clients authenticate with `clientId` alone.
698
+ *
671
699
  * @param options User profile data and optional realm/organization.
672
700
  * @param storeOptions Optional options used to resolve the domain (resolver mode).
673
701
  *
@@ -686,6 +714,9 @@ declare class ServerPasskeyClient<TStoreOptions = unknown> {
686
714
  *
687
715
  * This method does not create a session; no state is persisted.
688
716
  *
717
+ * Client authentication works the same way as {@link ServerPasskeyClient.register}:
718
+ * on a confidential client, only a `clientSecret` is accepted here.
719
+ *
689
720
  * @param options Optional realm/organization configuration.
690
721
  * @param storeOptions Optional options used to resolve the domain (resolver mode).
691
722
  *
@@ -1104,16 +1135,24 @@ declare class ServerClient<TStoreOptions = unknown> {
1104
1135
  * on the result — it only appears on the target session's tokens once the STT is redeemed.
1105
1136
  *
1106
1137
  * An actor is mandatory for an STT (this is what makes it auditable impersonation). It is
1107
- * resolved in this order: an explicit `options.actor` wins; otherwise the current agent
1108
- * session's ID token is used, refreshed when it has expired; if neither is available the method
1109
- * throws before any network call.
1138
+ * resolved in this order: an explicit `options.actor` wins, in which case the session is not
1139
+ * read at all; otherwise the current agent session's ID token is used, refreshed when it has
1140
+ * expired; if neither is available the method throws before any network call. An explicit actor
1141
+ * token carrying the default ID token type must satisfy Auth0's own validation — see
1142
+ * {@link SessionTransferActor.token}.
1143
+ *
1144
+ * When `organization` is provided it is sent on the exchange, so the tenant validates it while
1145
+ * minting. This is a separate parameter from the `organization` passed to
1146
+ * {@link ServerClient.buildSessionTransferRedirect}, which is forwarded to the target's
1147
+ * `/authorize` on the redirect.
1110
1148
  *
1111
1149
  * @param options Options including the developer-supplied `subjectToken`/`subjectTokenType` and an optional explicit `actor`.
1112
1150
  * @param storeOptions Optional options used to read the agent session (for the actor) and resolve the request domain.
1113
1151
  *
1114
- * @throws {TokenExchangeError} With code `actor_unavailable` when no explicit actor is given and no usable session ID token can be resolved — no logged-in agent, a session that belongs to a different domain in resolver mode, or an expired ID token that cannot be refreshed (raised client-side, before any network call). With the default code when the exchange itself fails; a server-side `setactor_required` or `session_transfer_disabled` condition is surfaced via `cause.error` / `cause.error_description`.
1152
+ * @throws {TokenExchangeError} With code `actor_unavailable` when no explicit actor is given and no usable session ID token can be resolved — no logged-in agent, a session that belongs to a different domain in resolver mode, or an expired ID token that cannot be refreshed (raised client-side, before any network call). With the default code when the exchange itself fails; a server-side `setactor_required` or `session_transfer_disabled` condition is surfaced via `cause.error` / `cause.error_description`. An organization the tenant rejects also surfaces here.
1115
1153
  * @throws {MissingClientAuthError} When client credentials are not configured (STT requires a confidential client).
1116
1154
  * @throws {MissingRequiredArgumentError} When `subjectToken` or `subjectTokenType` is missing or blank (raised before any session read or network call).
1155
+ * @throws {OrganizationValidationError} When `organization` is provided but blank (raised before any session read or network call).
1117
1156
  *
1118
1157
  * @returns A promise resolving to a {@link SessionTransferTokenResult} containing the STT and its metadata.
1119
1158
  */
package/dist/index.d.ts CHANGED
@@ -425,11 +425,19 @@ interface LoginWithCustomTokenExchangeResult {
425
425
  * An explicit actor (the acting party) for a Session Transfer Token request.
426
426
  *
427
427
  * Supplying this overrides the default behaviour of sourcing the actor from the
428
- * current agent session's ID token.
428
+ * current agent session's ID token. The session is not read at all when this is
429
+ * given, so it also works where there is no logged-in agent.
429
430
  */
430
431
  interface SessionTransferActor {
431
432
  /**
432
433
  * The actor token — for the default flow this is the agent's ID token.
434
+ *
435
+ * When {@link SessionTransferActor.type} is the ID token URN (the default), Auth0
436
+ * validates this token and requires an unexpired, asymmetrically-signed Auth0 ID
437
+ * token: signed with `RS256` or `PS256` (`HS256` is rejected, as it uses a shared
438
+ * secret), carrying `sub`, `iss`, `exp` and `iat`, issued to the same client making
439
+ * the exchange, and belonging to a user who still exists and is not blocked. A token
440
+ * failing any of these fails the exchange with a `TokenExchangeError`.
433
441
  */
434
442
  token: string;
435
443
  /**
@@ -462,16 +470,30 @@ interface RequestSessionTransferTokenOptions {
462
470
  /**
463
471
  * An explicit actor to override the default (the agent session's ID token).
464
472
  *
465
- * Resolution order: this explicit `actor` wins; otherwise the agent session's ID
466
- * token is used (refreshed when expired); if neither is available the request fails
467
- * client-side with a `TokenExchangeError` whose code is `actor_unavailable`, before
468
- * any network call.
473
+ * Resolution order: this explicit `actor` wins, and the session is not read at all;
474
+ * otherwise the agent session's ID token is used (refreshed when expired); if neither
475
+ * is available the request fails client-side with a `TokenExchangeError` whose code is
476
+ * `actor_unavailable`, before any network call.
469
477
  */
470
478
  actor?: SessionTransferActor;
471
479
  /**
472
480
  * Space-separated list of OAuth 2.0 scopes to request for the session's tokens.
473
481
  */
474
482
  scope?: string;
483
+ /**
484
+ * The organization (ID or name) to mint the STT in the context of.
485
+ *
486
+ * Sending it here has the tenant validate the organization against the client's
487
+ * organization settings while minting, so an organization the client is not allowed
488
+ * to use fails at this call instead of the STT being issued without it.
489
+ *
490
+ * This is a separate parameter from {@link BuildSessionTransferRedirectOptions.organization},
491
+ * which is forwarded to the target's `/authorize` on the redirect. They are sent on
492
+ * different requests and neither implies the other. The one on the redirect is what
493
+ * org-scopes the session the target establishes, so setting only this one validates the
494
+ * organization without scoping that session.
495
+ */
496
+ organization?: string;
475
497
  /**
476
498
  * Additional custom parameters forwarded to the token endpoint (and thus to your
477
499
  * Action via `event.request.body`). Cannot override reserved OAuth parameters.
@@ -668,6 +690,12 @@ declare class ServerPasskeyClient<TStoreOptions = unknown> {
668
690
  *
669
691
  * This method does not create a session; no state is persisted.
670
692
  *
693
+ * On a confidential client this endpoint accepts `client_secret` as its only
694
+ * credential, so configure `clientSecret` on the `ServerClient`. It does not
695
+ * accept a private key JWT and is not served on the mTLS endpoint aliases, so a
696
+ * client configured with only `clientAssertionSigningKey` or only `useMtls` is
697
+ * rejected by Auth0. Public clients authenticate with `clientId` alone.
698
+ *
671
699
  * @param options User profile data and optional realm/organization.
672
700
  * @param storeOptions Optional options used to resolve the domain (resolver mode).
673
701
  *
@@ -686,6 +714,9 @@ declare class ServerPasskeyClient<TStoreOptions = unknown> {
686
714
  *
687
715
  * This method does not create a session; no state is persisted.
688
716
  *
717
+ * Client authentication works the same way as {@link ServerPasskeyClient.register}:
718
+ * on a confidential client, only a `clientSecret` is accepted here.
719
+ *
689
720
  * @param options Optional realm/organization configuration.
690
721
  * @param storeOptions Optional options used to resolve the domain (resolver mode).
691
722
  *
@@ -1104,16 +1135,24 @@ declare class ServerClient<TStoreOptions = unknown> {
1104
1135
  * on the result — it only appears on the target session's tokens once the STT is redeemed.
1105
1136
  *
1106
1137
  * An actor is mandatory for an STT (this is what makes it auditable impersonation). It is
1107
- * resolved in this order: an explicit `options.actor` wins; otherwise the current agent
1108
- * session's ID token is used, refreshed when it has expired; if neither is available the method
1109
- * throws before any network call.
1138
+ * resolved in this order: an explicit `options.actor` wins, in which case the session is not
1139
+ * read at all; otherwise the current agent session's ID token is used, refreshed when it has
1140
+ * expired; if neither is available the method throws before any network call. An explicit actor
1141
+ * token carrying the default ID token type must satisfy Auth0's own validation — see
1142
+ * {@link SessionTransferActor.token}.
1143
+ *
1144
+ * When `organization` is provided it is sent on the exchange, so the tenant validates it while
1145
+ * minting. This is a separate parameter from the `organization` passed to
1146
+ * {@link ServerClient.buildSessionTransferRedirect}, which is forwarded to the target's
1147
+ * `/authorize` on the redirect.
1110
1148
  *
1111
1149
  * @param options Options including the developer-supplied `subjectToken`/`subjectTokenType` and an optional explicit `actor`.
1112
1150
  * @param storeOptions Optional options used to read the agent session (for the actor) and resolve the request domain.
1113
1151
  *
1114
- * @throws {TokenExchangeError} With code `actor_unavailable` when no explicit actor is given and no usable session ID token can be resolved — no logged-in agent, a session that belongs to a different domain in resolver mode, or an expired ID token that cannot be refreshed (raised client-side, before any network call). With the default code when the exchange itself fails; a server-side `setactor_required` or `session_transfer_disabled` condition is surfaced via `cause.error` / `cause.error_description`.
1152
+ * @throws {TokenExchangeError} With code `actor_unavailable` when no explicit actor is given and no usable session ID token can be resolved — no logged-in agent, a session that belongs to a different domain in resolver mode, or an expired ID token that cannot be refreshed (raised client-side, before any network call). With the default code when the exchange itself fails; a server-side `setactor_required` or `session_transfer_disabled` condition is surfaced via `cause.error` / `cause.error_description`. An organization the tenant rejects also surfaces here.
1115
1153
  * @throws {MissingClientAuthError} When client credentials are not configured (STT requires a confidential client).
1116
1154
  * @throws {MissingRequiredArgumentError} When `subjectToken` or `subjectTokenType` is missing or blank (raised before any session read or network call).
1155
+ * @throws {OrganizationValidationError} When `organization` is provided but blank (raised before any session read or network call).
1117
1156
  *
1118
1157
  * @returns A promise resolving to a {@link SessionTransferTokenResult} containing the STT and its metadata.
1119
1158
  */
package/dist/index.js CHANGED
@@ -211,7 +211,7 @@ function getTelemetryConfig(config) {
211
211
  return {
212
212
  enabled: true,
213
213
  name: config?.name ?? "@auth0/auth0-server-js",
214
- version: config?.version ?? "1.11.0"
214
+ version: config?.version ?? "1.12.1"
215
215
  };
216
216
  }
217
217
 
@@ -317,6 +317,12 @@ var ServerPasskeyClient = class {
317
317
  *
318
318
  * This method does not create a session; no state is persisted.
319
319
  *
320
+ * On a confidential client this endpoint accepts `client_secret` as its only
321
+ * credential, so configure `clientSecret` on the `ServerClient`. It does not
322
+ * accept a private key JWT and is not served on the mTLS endpoint aliases, so a
323
+ * client configured with only `clientAssertionSigningKey` or only `useMtls` is
324
+ * rejected by Auth0. Public clients authenticate with `clientId` alone.
325
+ *
320
326
  * @param options User profile data and optional realm/organization.
321
327
  * @param storeOptions Optional options used to resolve the domain (resolver mode).
322
328
  *
@@ -339,6 +345,9 @@ var ServerPasskeyClient = class {
339
345
  *
340
346
  * This method does not create a session; no state is persisted.
341
347
  *
348
+ * Client authentication works the same way as {@link ServerPasskeyClient.register}:
349
+ * on a confidential client, only a `clientSecret` is accepted here.
350
+ *
342
351
  * @param options Optional realm/organization configuration.
343
352
  * @param storeOptions Optional options used to resolve the domain (resolver mode).
344
353
  *
@@ -1404,16 +1413,24 @@ var ServerClient = class {
1404
1413
  * on the result — it only appears on the target session's tokens once the STT is redeemed.
1405
1414
  *
1406
1415
  * An actor is mandatory for an STT (this is what makes it auditable impersonation). It is
1407
- * resolved in this order: an explicit `options.actor` wins; otherwise the current agent
1408
- * session's ID token is used, refreshed when it has expired; if neither is available the method
1409
- * throws before any network call.
1416
+ * resolved in this order: an explicit `options.actor` wins, in which case the session is not
1417
+ * read at all; otherwise the current agent session's ID token is used, refreshed when it has
1418
+ * expired; if neither is available the method throws before any network call. An explicit actor
1419
+ * token carrying the default ID token type must satisfy Auth0's own validation — see
1420
+ * {@link SessionTransferActor.token}.
1421
+ *
1422
+ * When `organization` is provided it is sent on the exchange, so the tenant validates it while
1423
+ * minting. This is a separate parameter from the `organization` passed to
1424
+ * {@link ServerClient.buildSessionTransferRedirect}, which is forwarded to the target's
1425
+ * `/authorize` on the redirect.
1410
1426
  *
1411
1427
  * @param options Options including the developer-supplied `subjectToken`/`subjectTokenType` and an optional explicit `actor`.
1412
1428
  * @param storeOptions Optional options used to read the agent session (for the actor) and resolve the request domain.
1413
1429
  *
1414
- * @throws {TokenExchangeError} With code `actor_unavailable` when no explicit actor is given and no usable session ID token can be resolved — no logged-in agent, a session that belongs to a different domain in resolver mode, or an expired ID token that cannot be refreshed (raised client-side, before any network call). With the default code when the exchange itself fails; a server-side `setactor_required` or `session_transfer_disabled` condition is surfaced via `cause.error` / `cause.error_description`.
1430
+ * @throws {TokenExchangeError} With code `actor_unavailable` when no explicit actor is given and no usable session ID token can be resolved — no logged-in agent, a session that belongs to a different domain in resolver mode, or an expired ID token that cannot be refreshed (raised client-side, before any network call). With the default code when the exchange itself fails; a server-side `setactor_required` or `session_transfer_disabled` condition is surfaced via `cause.error` / `cause.error_description`. An organization the tenant rejects also surfaces here.
1415
1431
  * @throws {MissingClientAuthError} When client credentials are not configured (STT requires a confidential client).
1416
1432
  * @throws {MissingRequiredArgumentError} When `subjectToken` or `subjectTokenType` is missing or blank (raised before any session read or network call).
1433
+ * @throws {OrganizationValidationError} When `organization` is provided but blank (raised before any session read or network call).
1417
1434
  *
1418
1435
  * @returns A promise resolving to a {@link SessionTransferTokenResult} containing the STT and its metadata.
1419
1436
  */
@@ -1424,6 +1441,9 @@ var ServerClient = class {
1424
1441
  if (!options.subjectTokenType || !options.subjectTokenType.trim()) {
1425
1442
  throw new MissingRequiredArgumentError("subjectTokenType");
1426
1443
  }
1444
+ if (options.organization !== void 0 && !options.organization.trim()) {
1445
+ throw new OrganizationValidationError("organization must not be blank");
1446
+ }
1427
1447
  const domain = await this.#resolveDomain(storeOptions);
1428
1448
  const actor = await this.#resolveSessionTransferActor(options.actor, domain, storeOptions);
1429
1449
  const authClient = this.#getAuthClient(domain);
@@ -1434,6 +1454,11 @@ var ServerClient = class {
1434
1454
  scope: options.scope,
1435
1455
  actorToken: actor.token,
1436
1456
  actorTokenType: actor.type,
1457
+ // Forwarded so the tenant validates the organization against the client's organization
1458
+ // settings while minting, rather than the STT being issued without it. Separate from the
1459
+ // `organization` on `buildSessionTransferRedirect`, which goes to the target's
1460
+ // `/authorize`; neither implies the other.
1461
+ organization: options.organization,
1437
1462
  extra: options.extra
1438
1463
  });
1439
1464
  return {