@bymax-one/nest-auth 1.5.2 → 1.5.3
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/CHANGELOG.md +134 -1
- package/README.md +209 -1112
- package/dist/nextjs/index.cjs +30 -9
- package/dist/nextjs/index.d.cts +58 -6
- package/dist/nextjs/index.d.ts +58 -6
- package/dist/nextjs/index.mjs +30 -9
- package/dist/server/index.cjs +482 -207
- package/dist/server/index.d.cts +617 -471
- package/dist/server/index.d.ts +617 -471
- package/dist/server/index.mjs +471 -208
- package/package.json +1 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -3323,6 +3323,13 @@ interface OAuthProviderPlugin {
|
|
|
3323
3323
|
* Must be lowercase and URL-safe (e.g. `'google'`, `'github'`).
|
|
3324
3324
|
*/
|
|
3325
3325
|
name: string;
|
|
3326
|
+
/**
|
|
3327
|
+
* The longest the library waits for {@link exchangeCode} and {@link fetchProfile} together during
|
|
3328
|
+
* the callback, in milliseconds. A whole number from 1 to 120000; any other value, or none, is
|
|
3329
|
+
* 10000. When it passes the callback is answered `OAUTH_FAILED` and the plugin's pending request
|
|
3330
|
+
* is abandoned, not cancelled, so a plugin should bound its own requests as well.
|
|
3331
|
+
*/
|
|
3332
|
+
timeoutMs?: number;
|
|
3326
3333
|
/**
|
|
3327
3334
|
* Constructs the provider's OAuth 2.0 authorization URL.
|
|
3328
3335
|
*
|
|
@@ -7508,121 +7515,480 @@ declare class WsWorkspaceGuard implements CanActivate {
|
|
|
7508
7515
|
}
|
|
7509
7516
|
|
|
7510
7517
|
/**
|
|
7511
|
-
* @fileoverview
|
|
7518
|
+
* @fileoverview `@CurrentWorkspace()`: the workspace and role `WorkspaceGuard` resolved for the
|
|
7519
|
+
* request.
|
|
7512
7520
|
*
|
|
7513
|
-
*
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7521
|
+
* @layer Decorator
|
|
7522
|
+
*/
|
|
7523
|
+
/** The access `WorkspaceGuard` resolved for a request. */
|
|
7524
|
+
interface CurrentWorkspaceContext {
|
|
7525
|
+
/** The tenant, taken from the verified token. */
|
|
7526
|
+
tenantId: string;
|
|
7527
|
+
/** The workspace the request named, checked against the caller's active membership. */
|
|
7528
|
+
workspaceId: string;
|
|
7529
|
+
/** The caller. */
|
|
7530
|
+
userId: string;
|
|
7531
|
+
/** The caller's role in that workspace. */
|
|
7532
|
+
role: string;
|
|
7533
|
+
}
|
|
7534
|
+
/** A request after `WorkspaceGuard` ran. */
|
|
7535
|
+
interface WorkspaceRequest {
|
|
7536
|
+
workspace?: CurrentWorkspaceContext;
|
|
7537
|
+
}
|
|
7538
|
+
/**
|
|
7539
|
+
* Injects the workspace access the guard resolved.
|
|
7518
7540
|
*
|
|
7519
|
-
* A
|
|
7520
|
-
*
|
|
7521
|
-
*
|
|
7522
|
-
|
|
7541
|
+
* A service takes its workspace from here and never from a DTO or a query: the guard is the only
|
|
7542
|
+
* place that checked the caller may act in it. Throws when the route runs without
|
|
7543
|
+
* `WorkspaceGuard`, since an id read from anywhere else would be unchecked.
|
|
7544
|
+
*/
|
|
7545
|
+
declare const CurrentWorkspace: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
7546
|
+
|
|
7547
|
+
/**
|
|
7548
|
+
* @fileoverview The request a `tenantIdResolver` sees when the caller arrived by WebSocket upgrade.
|
|
7549
|
+
*
|
|
7550
|
+
* @layer Utility
|
|
7551
|
+
*/
|
|
7552
|
+
|
|
7553
|
+
/**
|
|
7554
|
+
* The fields {@link handshakeRequest} reads. A Socket.IO `handshake` fits, and so does an Express
|
|
7555
|
+
* request.
|
|
7556
|
+
*/
|
|
7557
|
+
interface HandshakeLike {
|
|
7558
|
+
headers: Record<string, string | string[] | undefined>;
|
|
7559
|
+
url?: string;
|
|
7560
|
+
/**
|
|
7561
|
+
* The TCP peer, as the transport reported it, never a header. Read only to decide whether
|
|
7562
|
+
* `X-Forwarded-Host` may be believed; absent or empty means it may not.
|
|
7563
|
+
*/
|
|
7564
|
+
remoteAddress?: string;
|
|
7565
|
+
}
|
|
7566
|
+
|
|
7567
|
+
/**
|
|
7568
|
+
* @fileoverview The whole identity chain for an access token, in one call.
|
|
7523
7569
|
*
|
|
7524
7570
|
* @layer Service
|
|
7525
7571
|
*/
|
|
7526
7572
|
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7573
|
+
/**
|
|
7574
|
+
* Which identity plane a caller expects a token to belong to.
|
|
7575
|
+
*
|
|
7576
|
+
* Always supplied by the caller and never inferred from the token's own `type` claim: inferring
|
|
7577
|
+
* would make the plane attacker-chosen, so a platform token would open a dashboard stream simply
|
|
7578
|
+
* by saying it is one.
|
|
7579
|
+
*/
|
|
7580
|
+
type AuthPlane = 'dashboard' | 'platform';
|
|
7581
|
+
/**
|
|
7582
|
+
* The outcome of a successful verification, discriminated by the plane so a caller can narrow to
|
|
7583
|
+
* the payload it actually got.
|
|
7584
|
+
*
|
|
7585
|
+
* `plane` is the same value the caller asked for — it is on the result because a consumer keying
|
|
7586
|
+
* live connections needs to record it, and because a tenant cannot answer the question: a platform
|
|
7587
|
+
* token carries no tenant claim at all.
|
|
7588
|
+
*/
|
|
7589
|
+
type VerifiedAccessToken = {
|
|
7590
|
+
readonly plane: 'dashboard';
|
|
7591
|
+
readonly payload: DashboardJwtPayload;
|
|
7592
|
+
} | {
|
|
7593
|
+
readonly plane: 'platform';
|
|
7594
|
+
readonly payload: PlatformJwtPayload;
|
|
7595
|
+
};
|
|
7596
|
+
/**
|
|
7597
|
+
* The workspace a verification also admits the caller to.
|
|
7598
|
+
*
|
|
7599
|
+
* Judged exactly as `WorkspaceGuard` judges a route: the same access resolution, the same cache, the
|
|
7600
|
+
* same refusals in the same order, so a stream and a route can never disagree about a member.
|
|
7601
|
+
*/
|
|
7602
|
+
interface WorkspaceCheck {
|
|
7603
|
+
/** The workspace the caller names, from the message and never from the token or the URL. */
|
|
7604
|
+
readonly workspaceId: string;
|
|
7605
|
+
/** The roles that admit the caller; `ANY_WORKSPACE_MEMBER` admits every active member. */
|
|
7606
|
+
readonly roles: WorkspaceRoleList;
|
|
7534
7607
|
/**
|
|
7535
|
-
*
|
|
7608
|
+
* Admit the owner of a workspace pending deletion, for a read-only stream. Everyone else is still
|
|
7609
|
+
* answered `workspace_not_found`.
|
|
7536
7610
|
*
|
|
7537
|
-
*
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7611
|
+
* @defaultValue false
|
|
7612
|
+
*/
|
|
7613
|
+
readonly allowPending?: boolean;
|
|
7614
|
+
}
|
|
7615
|
+
/** A dashboard verification that also admitted the caller to a workspace. */
|
|
7616
|
+
interface VerifiedWorkspaceAccessToken {
|
|
7617
|
+
readonly plane: 'dashboard';
|
|
7618
|
+
readonly payload: DashboardJwtPayload;
|
|
7619
|
+
/** The caller's membership of the workspace they were admitted to. */
|
|
7620
|
+
readonly workspace: CurrentWorkspaceContext;
|
|
7621
|
+
}
|
|
7622
|
+
/**
|
|
7623
|
+
* What a verification checks beyond the signature.
|
|
7624
|
+
*
|
|
7625
|
+
* Both flags default to `true`. They exist to be turned OFF deliberately, by a caller that has
|
|
7626
|
+
* already established the same fact by another route — never as a way to make a reconnect cheaper.
|
|
7627
|
+
*/
|
|
7628
|
+
interface VerifyAccessTokenOptions {
|
|
7629
|
+
/** The plane the caller expects. Required; see {@link AuthPlane}. */
|
|
7630
|
+
readonly plane: AuthPlane;
|
|
7631
|
+
/**
|
|
7632
|
+
* Refuse a token whose account has MFA enabled but which was not itself issued after a
|
|
7633
|
+
* successful challenge — the rule {@link MfaRequiredGuard} applies to an HTTP route.
|
|
7542
7634
|
*
|
|
7543
|
-
*
|
|
7544
|
-
*
|
|
7545
|
-
*
|
|
7546
|
-
* therefore the smaller of {@link WS_TICKET_TTL_SECONDS} and the token's remaining seconds less
|
|
7547
|
-
* a one-second margin, and a token with none left mints nothing.
|
|
7635
|
+
* It matters most on a reconnect: a refresh carries `mfaVerified` forward only from a session
|
|
7636
|
+
* that completed the challenge, so a token that is otherwise entirely valid can still represent
|
|
7637
|
+
* a session that never did. The token's `type` does not imply it.
|
|
7548
7638
|
*
|
|
7549
|
-
* @
|
|
7550
|
-
* @returns The raw ticket and how long it is valid for, in seconds.
|
|
7551
|
-
* @throws {@link AuthException} `auth.token_invalid` when the token has no life left.
|
|
7639
|
+
* @defaultValue true
|
|
7552
7640
|
*/
|
|
7553
|
-
|
|
7554
|
-
ticket: string;
|
|
7555
|
-
expiresIn: number;
|
|
7556
|
-
}>;
|
|
7641
|
+
readonly requireMfa?: boolean;
|
|
7557
7642
|
/**
|
|
7558
|
-
*
|
|
7643
|
+
* Re-resolve the account's lifecycle status instead of trusting the snapshot the token carries,
|
|
7644
|
+
* refusing a blocked, deleted or — on the dashboard plane, where verification gates API
|
|
7645
|
+
* access — unverified account.
|
|
7559
7646
|
*
|
|
7560
|
-
*
|
|
7561
|
-
*
|
|
7562
|
-
* guard's, unchanged.
|
|
7647
|
+
* The only check that can answer differently between two calls: a suspension lands between two
|
|
7648
|
+
* reconnects, and nothing in the token would say so.
|
|
7563
7649
|
*
|
|
7564
|
-
*
|
|
7565
|
-
*
|
|
7566
|
-
*
|
|
7650
|
+
* **Its freshness on the dashboard plane is bounded by `userStatusCacheTtlSeconds`, not by how
|
|
7651
|
+
* often you call.** That plane reads the `us:`/`uev:` cache, so a stream re-verifying every five
|
|
7652
|
+
* seconds still serves a banned account until the entry expires (default 60 s) — a tighter
|
|
7653
|
+
* cadence does not shorten that. What does is
|
|
7654
|
+
* {@link AccountStatusService.invalidate}: call it wherever you change an account's status, and
|
|
7655
|
+
* read what that method does **not** promise — a request already resolving when you invalidate
|
|
7656
|
+
* can write the old value back, so the window narrows to one repository read rather than to
|
|
7657
|
+
* zero. Failing that, lower the TTL. The platform plane is uncached and therefore genuinely
|
|
7658
|
+
* current, at the cost of a repository read per call.
|
|
7659
|
+
*
|
|
7660
|
+
* @defaultValue true
|
|
7567
7661
|
*/
|
|
7568
|
-
|
|
7662
|
+
readonly checkStatus?: boolean;
|
|
7569
7663
|
/**
|
|
7570
|
-
* The
|
|
7571
|
-
*
|
|
7664
|
+
* The request the credential arrived on — a Socket.IO `handshake`, an Express request, or any
|
|
7665
|
+
* object with `headers` and `url` — so `enforceTenantBinding` can be applied.
|
|
7572
7666
|
*
|
|
7573
|
-
*
|
|
7574
|
-
*
|
|
7575
|
-
*
|
|
7576
|
-
*
|
|
7577
|
-
*
|
|
7667
|
+
* The binding needs the request the host's `tenantIdResolver` reads, which a token alone does
|
|
7668
|
+
* not carry. With `enforceTenantBinding` on and a request passed, the resolver runs on the
|
|
7669
|
+
* dashboard plane exactly as it does in `WsJwtGuard`: it receives an object with only `headers`
|
|
7670
|
+
* (lowercased), `url` and `hostname` — no `cookies`, `ip` or `ips` — and a resolver that throws
|
|
7671
|
+
* on that, or answers another tenant, refuses the token with `TOKEN_INVALID`. The platform plane
|
|
7672
|
+
* has no tenant and ignores it.
|
|
7578
7673
|
*
|
|
7579
|
-
*
|
|
7580
|
-
*
|
|
7581
|
-
*
|
|
7674
|
+
* `hostname` is the `Host` header with the port cut. When the host configured `isTrustedProxy`,
|
|
7675
|
+
* pass the TCP peer as `request.remoteAddress` (never a header value): if the predicate trusts
|
|
7676
|
+
* it, the first element of a single `X-Forwarded-Host` is used instead, as Express does over
|
|
7677
|
+
* HTTP. Without a peer the `Host` header stands.
|
|
7678
|
+
*
|
|
7679
|
+
* **Omit it and the binding is not applied for that call.** With `enforceTenantBinding` on,
|
|
7680
|
+
* that is logged once per service instance, because a caller that never passes it has a
|
|
7681
|
+
* binding the HTTP guards enforce and this surface does not.
|
|
7582
7682
|
*/
|
|
7583
|
-
|
|
7683
|
+
readonly request?: HandshakeLike;
|
|
7584
7684
|
/**
|
|
7585
|
-
*
|
|
7685
|
+
* Also admit the caller to one workspace, resolved through the access cache the routes use, and
|
|
7686
|
+
* return their membership as `workspace`. A refusal is the guard's own: `workspace_not_found`
|
|
7687
|
+
* for a caller who is not an active member (and for every non-owner of a workspace pending
|
|
7688
|
+
* deletion, identically), `workspace_pending_deletion` for its owner, `insufficient_workspace_role`
|
|
7689
|
+
* for a role no accepted one covers, and `auth.validation` naming `workspaceId` for an id that is
|
|
7690
|
+
* blank, over-long or holds a control character, ahead of any lookup.
|
|
7586
7691
|
*
|
|
7587
|
-
*
|
|
7588
|
-
*
|
|
7589
|
-
*
|
|
7590
|
-
*
|
|
7591
|
-
*
|
|
7592
|
-
* caller.
|
|
7692
|
+
* Dashboard plane only: on the platform plane it is a `TypeError`, because a platform token has no
|
|
7693
|
+
* workspace. On a deployment without `workspaces.enabled` it is refused with `auth.validation`
|
|
7694
|
+
* naming `workspaceId`, the same refusal a bad id gets, so a host that takes the id from a client
|
|
7695
|
+
* never has to check the feature first. A stream calls it at subscribe time and again on its
|
|
7696
|
+
* cadence or per message; a refusal means disconnect.
|
|
7593
7697
|
*/
|
|
7594
|
-
|
|
7698
|
+
readonly workspace?: WorkspaceCheck;
|
|
7595
7699
|
}
|
|
7596
|
-
|
|
7597
7700
|
/**
|
|
7598
|
-
*
|
|
7701
|
+
* Performs, in one call, every identity check a guarded HTTP route performs before a handler runs.
|
|
7599
7702
|
*
|
|
7600
|
-
*
|
|
7601
|
-
* of the
|
|
7602
|
-
*
|
|
7703
|
+
* A long-lived transport — a WebSocket, an SSE stream, a message consumer — has no guard in front
|
|
7704
|
+
* of it, so it has to establish the same facts itself, on a cadence, for as long as the connection
|
|
7705
|
+
* lives. Assembling that from the parts is where it goes wrong: {@link AuthRevocationService}
|
|
7706
|
+
* answers two channels and nothing else, and a bridge that calls it alone has verified a signature
|
|
7707
|
+
* and consulted a blacklist while checking neither the token's type, nor its `exp`, nor whether the
|
|
7708
|
+
* account behind it still exists.
|
|
7603
7709
|
*
|
|
7604
|
-
*
|
|
7605
|
-
* **Two credential channels, and only two** — the handshake
|
|
7606
|
-
* `Authorization: Bearer <token>` header, or a single-use ticket in the upgrade
|
|
7607
|
-
* query string.
|
|
7710
|
+
* What one call establishes, in the order the refusals fire:
|
|
7608
7711
|
*
|
|
7609
|
-
*
|
|
7610
|
-
*
|
|
7611
|
-
*
|
|
7612
|
-
*
|
|
7613
|
-
*
|
|
7614
|
-
*
|
|
7712
|
+
* 1. **Signature**, under the pinned algorithm and any secret retired by a rotation, plus the
|
|
7713
|
+
* configured `issuer` and `audience` — all of `verifyWithRotation`.
|
|
7714
|
+
* 2. **Expiry.** `exp` is enforced by the same verification. It is worth naming separately because
|
|
7715
|
+
* {@link AuthRevocationService.isAccessTokenRevoked} never reads it: a revocation check answers
|
|
7716
|
+
* "was this withdrawn", not "is this still current".
|
|
7717
|
+
* 3. **Claim shape** — `jti` a UUID v4, `sub` and (on the dashboard plane) `tenantId` bounded
|
|
7718
|
+
* non-empty strings. These become Redis keys downstream; a malformed one builds a key nobody
|
|
7719
|
+
* intended.
|
|
7720
|
+
* 4. **Token type**, matched against the plane the caller named. Without it an `mfa_challenge`
|
|
7721
|
+
* token — signed with the same secret, holding half a credential — reads as a valid session.
|
|
7722
|
+
* 5. **Revocation**, both channels: the per-token blacklist a logout writes and the per-user epoch
|
|
7723
|
+
* a password reset or an administrative revoke-all advances.
|
|
7724
|
+
* 6. **Account status**, unless the caller opted out. See
|
|
7725
|
+
* {@link VerifyAccessTokenOptions.checkStatus}.
|
|
7726
|
+
* 7. **MFA policy**, unless the caller opted out. See {@link VerifyAccessTokenOptions.requireMfa}.
|
|
7727
|
+
* Its claim-shape refusal (`mfaEnabled` missing or not a boolean, answered `TOKEN_INVALID`)
|
|
7728
|
+
* belongs to the token checks and fires before step 6; only the `MFA_REQUIRED` decision follows it.
|
|
7615
7729
|
*
|
|
7616
|
-
*
|
|
7730
|
+
* **Account status precedes the MFA policy.** A blocked account is refused with its own code even
|
|
7731
|
+
* while a challenge is pending, which is the answer a route guarded by `UserStatusGuard` ahead of
|
|
7732
|
+
* `MfaRequiredGuard` gives; a pending challenge is something the caller can act on only when the
|
|
7733
|
+
* account is usable, and the definitive refusal is the one it must see first.
|
|
7734
|
+
*
|
|
7735
|
+
* **What it still does not do, and cannot.** Route authorization is the consumer's — this answers
|
|
7736
|
+
* who the caller is, and with {@link VerifyAccessTokenOptions.workspace} which workspace they belong
|
|
7737
|
+
* to and in what role, never what they may do beyond that, so a `@Roles()` equivalent stays yours to
|
|
7738
|
+
* apply on every message a stream carries, not only at the handshake. Tenant binding
|
|
7739
|
+
* (`enforceTenantBinding`) needs the request the resolver reads, which a token does not carry:
|
|
7740
|
+
* pass the handshake as {@link VerifyAccessTokenOptions.request}, or the binding is not applied. And nothing here holds a subscription: it answers at the moment it is called, so a stream
|
|
7741
|
+
* that calls it once at connect is authorized for the lifetime of the token, not of the session.
|
|
7742
|
+
* Call it again on a cadence, and treat a rejection as a disconnect.
|
|
7743
|
+
*
|
|
7744
|
+
* @example
|
|
7745
|
+
* ```ts
|
|
7746
|
+
* const { plane, payload } = await this.verifier.verifyAccessToken(token, { plane: 'dashboard' })
|
|
7747
|
+
* registry.add(socket, { plane, userId: payload.sub, tenantId: payload.tenantId })
|
|
7748
|
+
* ```
|
|
7749
|
+
*
|
|
7750
|
+
* @layer Service
|
|
7751
|
+
*/
|
|
7752
|
+
declare class AuthTokenVerifierService {
|
|
7753
|
+
private readonly jwtService;
|
|
7754
|
+
private readonly options;
|
|
7755
|
+
private readonly revocation;
|
|
7756
|
+
private readonly accountStatus;
|
|
7757
|
+
private readonly workspaceAccess;
|
|
7758
|
+
private readonly deniedEvents;
|
|
7759
|
+
private readonly logger;
|
|
7760
|
+
/** Whether the "binding not applied" warning has been logged by this instance. */
|
|
7761
|
+
private warnedUnbound;
|
|
7762
|
+
/**
|
|
7763
|
+
* @param jwtService - The Nest JWT service, configured with the current signing secret.
|
|
7764
|
+
* @param options - Resolved module options, for the algorithm, the binding claims and the
|
|
7765
|
+
* secrets retired by a rotation.
|
|
7766
|
+
* @param revocation - The two revocation channels, shared with the mounted guards.
|
|
7767
|
+
* @param accountStatus - The account lifecycle gate, shared with {@link UserStatusGuard}.
|
|
7768
|
+
*/
|
|
7769
|
+
constructor(jwtService: JwtService, options: ResolvedOptions, revocation: AuthRevocationService, accountStatus: AccountStatusService, workspaceAccess?: WorkspaceAccessService | null, deniedEvents?: WorkspaceDeniedEventsService | null);
|
|
7770
|
+
/**
|
|
7771
|
+
* Verifies an access token and returns its payload, or throws.
|
|
7772
|
+
*
|
|
7773
|
+
* Every refusal is an {@link AuthException}, and each mirrors the code the equivalent guard
|
|
7774
|
+
* already answers, so a consumer moving a surface onto this service keeps branching on what it
|
|
7775
|
+
* branched on before.
|
|
7776
|
+
*
|
|
7777
|
+
* Most token-shaped failures answer `TOKEN_INVALID` without naming which check refused: telling
|
|
7778
|
+
* "valid but revoked" apart from "never valid" is an oracle for no benefit. Three name
|
|
7779
|
+
* themselves, because a legitimate client acts on each differently — `MFA_REQUIRED` means
|
|
7780
|
+
* complete the challenge, the `ACCOUNT_*` codes mean the account itself is refused, and
|
|
7781
|
+
* `PLATFORM_AUTH_REQUIRED` means a token for the other context was presented. That last one is
|
|
7782
|
+
* the platform plane only, and it is what {@link JwtPlatformGuard} answers there; the dashboard
|
|
7783
|
+
* plane collapses a wrong type into `TOKEN_INVALID`, as {@link JwtAuthGuard} does.
|
|
7784
|
+
*
|
|
7785
|
+
* @param token - The compact JWT, exactly as presented. Never a decoded payload: a caller that
|
|
7786
|
+
* already decoded it has skipped the signature, which is the check everything else rests on.
|
|
7787
|
+
* @param options - The plane, and which of the two optional checks to run.
|
|
7788
|
+
* @returns The verified payload, tagged with the plane it was checked against.
|
|
7789
|
+
* @throws {@link AuthException} with `TOKEN_INVALID` when the signature, expiry, claim shape,
|
|
7790
|
+
* dashboard token type or revocation state refuses the token; `PLATFORM_AUTH_REQUIRED` when a
|
|
7791
|
+
* non-platform token is presented on the platform plane; the matching `ACCOUNT_*` /
|
|
7792
|
+
* `EMAIL_NOT_VERIFIED` code when the account is no longer usable, whether or not a challenge is
|
|
7793
|
+
* pending; or `MFA_REQUIRED` when the account is usable, has MFA enabled and this token
|
|
7794
|
+
* predates its challenge.
|
|
7795
|
+
* @throws {@link AuthException} with `auth.validation` naming `workspaceId`, only after the token is
|
|
7796
|
+
* verified, when `options.workspace` carries a malformed id or workspaces are not enabled.
|
|
7797
|
+
* @throws {TypeError} When `options.plane` is neither `'dashboard'` nor `'platform'` — a caller
|
|
7798
|
+
* error rather than an authentication outcome, so it is deliberately not an `AuthException`.
|
|
7799
|
+
*/
|
|
7800
|
+
verifyAccessToken(token: string, options: VerifyAccessTokenOptions & {
|
|
7801
|
+
plane: 'dashboard';
|
|
7802
|
+
workspace: WorkspaceCheck;
|
|
7803
|
+
}): Promise<VerifiedWorkspaceAccessToken>;
|
|
7804
|
+
verifyAccessToken(token: string, options: VerifyAccessTokenOptions): Promise<VerifiedAccessToken>;
|
|
7805
|
+
/**
|
|
7806
|
+
* The dashboard arm: the full chain plus the tenant claim and the tenant-scoped status gate.
|
|
7807
|
+
*
|
|
7808
|
+
* @param token - The compact JWT.
|
|
7809
|
+
* @param requireMfa - Whether to apply the MFA policy.
|
|
7810
|
+
* @param checkStatus - Whether to consult the account's current status.
|
|
7811
|
+
* @param request - The request the token arrived on, for `enforceTenantBinding`.
|
|
7812
|
+
* @returns The verified dashboard payload.
|
|
7813
|
+
* @throws {@link AuthException} as {@link verifyAccessToken} documents.
|
|
7814
|
+
*/
|
|
7815
|
+
private verifyDashboard;
|
|
7816
|
+
/**
|
|
7817
|
+
* The function that admits a caller to a workspace. On a plane with no workspaces that is a
|
|
7818
|
+
* `TypeError` raised at once, a programmer's error. On a deployment that has not enabled them the
|
|
7819
|
+
* function is returned and refuses with the `auth.validation` error naming `workspaceId` when it is
|
|
7820
|
+
* called, which is after the token has been verified: the id came from a client, and an anonymous
|
|
7821
|
+
* caller must get `TOKEN_INVALID`, not a description of the deployment.
|
|
7822
|
+
*
|
|
7823
|
+
* Otherwise the returned function admits the caller as `WorkspaceGuard` would a route, with
|
|
7824
|
+
* `auth.validation` for a malformed id and then the guard's refusals.
|
|
7825
|
+
*/
|
|
7826
|
+
private workspaceResolver;
|
|
7827
|
+
/**
|
|
7828
|
+
* Applies `enforceTenantBinding` when a request was passed, and says so once when it could not.
|
|
7829
|
+
*
|
|
7830
|
+
* @param tenantId - The tenant the token was issued for.
|
|
7831
|
+
* @param request - The request the token arrived on, when the caller supplied one.
|
|
7832
|
+
* @throws {@link AuthException} with `TOKEN_INVALID` as {@link assertTenantBinding} documents.
|
|
7833
|
+
*/
|
|
7834
|
+
private assertBound;
|
|
7835
|
+
/**
|
|
7836
|
+
* The platform arm. No tenant claim exists to assert or to scope by — a platform administrator
|
|
7837
|
+
* is cross-tenant, which is also why the revocation read is told which epoch namespace to use.
|
|
7838
|
+
*
|
|
7839
|
+
* @param token - The compact JWT.
|
|
7840
|
+
* @param requireMfa - Whether to apply the MFA policy.
|
|
7841
|
+
* @param checkStatus - Whether to consult the administrator's current status.
|
|
7842
|
+
* @returns The verified platform payload.
|
|
7843
|
+
* @throws {@link AuthException} as {@link verifyAccessToken} documents.
|
|
7844
|
+
*/
|
|
7845
|
+
private verifyPlatform;
|
|
7846
|
+
/**
|
|
7847
|
+
* Verifies signature, algorithm, binding claims and expiry, collapsing every failure to one
|
|
7848
|
+
* opaque refusal.
|
|
7849
|
+
*
|
|
7850
|
+
* @typeParam T - The payload shape the caller's plane expects.
|
|
7851
|
+
* @param token - The compact JWT.
|
|
7852
|
+
* @returns The decoded payload, cast to `T`. The claims are asserted by the caller.
|
|
7853
|
+
* @throws {@link AuthException} with `TOKEN_INVALID` when no configured secret accepts it.
|
|
7854
|
+
*/
|
|
7855
|
+
private verifySignature;
|
|
7856
|
+
/**
|
|
7857
|
+
* Refuses a token whose `mfaEnabled` claim is missing or not a boolean.
|
|
7858
|
+
*
|
|
7859
|
+
* The `typeof` arm is not defensive noise: the payload is cast from a token, so a signed token
|
|
7860
|
+
* that simply omits `mfaEnabled` would otherwise compare `undefined === true`, read as "MFA is
|
|
7861
|
+
* off" and pass a gate it was never shown to. It is a claim-shape refusal, so it runs with the
|
|
7862
|
+
* other token checks and ahead of the account lookup.
|
|
7863
|
+
*
|
|
7864
|
+
* @param payload - The verified payload, either plane.
|
|
7865
|
+
* @throws {@link AuthException} with `TOKEN_INVALID` when the claim is missing or not a boolean.
|
|
7866
|
+
*/
|
|
7867
|
+
private assertMfaClaimShape;
|
|
7868
|
+
/**
|
|
7869
|
+
* Applies the MFA policy to a payload whose claim shape was already checked.
|
|
7870
|
+
*
|
|
7871
|
+
* @param payload - The verified payload, either plane.
|
|
7872
|
+
* @throws {@link AuthException} with `MFA_REQUIRED` when MFA is enabled and this token predates
|
|
7873
|
+
* the challenge.
|
|
7874
|
+
*/
|
|
7875
|
+
private assertMfaVerified;
|
|
7876
|
+
}
|
|
7877
|
+
|
|
7878
|
+
/**
|
|
7879
|
+
* @fileoverview Single-use WebSocket upgrade tickets.
|
|
7880
|
+
*
|
|
7881
|
+
* The browser `WebSocket` API cannot set handshake headers, so a browser client has no way to
|
|
7882
|
+
* present `Authorization: Bearer <token>` at the upgrade. The usual workaround — the access
|
|
7883
|
+
* token in the query string — writes a long-lived credential into access logs, browser history
|
|
7884
|
+
* and proxy caches. {@link WsJwtGuard} refuses it for exactly that reason, which left browser
|
|
7885
|
+
* clients with no supported path at all.
|
|
7886
|
+
*
|
|
7887
|
+
* A ticket is the other answer: opaque, single-use, ~30 seconds, and worth nothing once
|
|
7888
|
+
* redeemed. It is minted only from a session that is already authenticated, in good standing
|
|
7889
|
+
* and MFA-satisfied, so the ticket can never carry more authority than the session that asked
|
|
7890
|
+
* for it.
|
|
7891
|
+
*
|
|
7892
|
+
* @layer Service
|
|
7893
|
+
*/
|
|
7894
|
+
|
|
7895
|
+
declare class WsTicketService {
|
|
7896
|
+
private readonly redis;
|
|
7897
|
+
private readonly options;
|
|
7898
|
+
private readonly userRepo;
|
|
7899
|
+
private readonly revocation;
|
|
7900
|
+
private readonly logger;
|
|
7901
|
+
constructor(redis: AuthRedisService, options: ResolvedOptions, userRepo: IUserRepository, revocation: AuthRevocationService);
|
|
7902
|
+
/**
|
|
7903
|
+
* Mints a ticket from an already-verified access-token payload.
|
|
7904
|
+
*
|
|
7905
|
+
* The caller is responsible for having run the authentication, status and MFA guards — the
|
|
7906
|
+
* payload reaching here is what those guards admitted. Nothing from the token itself is
|
|
7907
|
+
* copied into the ticket beyond the identity it proved and the two keys its revocation is read
|
|
7908
|
+
* by (`jti`, `epoch`): no expiry, no signature, nothing that could be replayed against the REST
|
|
7909
|
+
* surface.
|
|
7910
|
+
*
|
|
7911
|
+
* A ticket expires no later than the access token that minted it. A logout blacklists the
|
|
7912
|
+
* token's `jti` only for the token's remaining life, so a ticket given longer than that would
|
|
7913
|
+
* outlive the entry that refuses it and redeem after its session ended. The lifetime is
|
|
7914
|
+
* therefore the smaller of {@link WS_TICKET_TTL_SECONDS} and the token's remaining seconds less
|
|
7915
|
+
* a one-second margin, and a token with none left mints nothing.
|
|
7916
|
+
*
|
|
7917
|
+
* @param payload - The verified dashboard access-token payload.
|
|
7918
|
+
* @returns The raw ticket and how long it is valid for, in seconds.
|
|
7919
|
+
* @throws {@link AuthException} `auth.token_invalid` when the token has no life left.
|
|
7920
|
+
*/
|
|
7921
|
+
issue(payload: DashboardJwtPayload): Promise<{
|
|
7922
|
+
ticket: string;
|
|
7923
|
+
expiresIn: number;
|
|
7924
|
+
}>;
|
|
7925
|
+
/**
|
|
7926
|
+
* Refuses a token whose session has not satisfied the second factor it is enrolled in.
|
|
7927
|
+
*
|
|
7928
|
+
* Applied here rather than through `MfaRequiredGuard`: that guard is only registered when MFA is
|
|
7929
|
+
* configured, and this endpoint has to work on deployments without it. The rule itself is the
|
|
7930
|
+
* guard's, unchanged.
|
|
7931
|
+
*
|
|
7932
|
+
* @param payload - The verified access-token payload.
|
|
7933
|
+
* @throws {@link AuthException} `auth.token_invalid` for a malformed `mfaEnabled`, and
|
|
7934
|
+
* `auth.mfa_required` for an enrolled session that has not cleared its challenge.
|
|
7935
|
+
*/
|
|
7936
|
+
private assertSecondFactor;
|
|
7937
|
+
/**
|
|
7938
|
+
* The seconds a ticket minted now may live: the smaller of {@link WS_TICKET_TTL_SECONDS} and what
|
|
7939
|
+
* the access token has left.
|
|
7940
|
+
*
|
|
7941
|
+
* Kept short of the token's expiry on purpose. `ceil` on the clock leaves between 0 and 1 second
|
|
7942
|
+
* of slack, and one further second is held back, so the ticket still ends no later than the
|
|
7943
|
+
* token when the write reaches Redis up to a second after this reading, at every sub-second
|
|
7944
|
+
* offset. An absent or non-numeric `exp` is NaN here and fails the comparison, which refuses
|
|
7945
|
+
* rather than mints.
|
|
7946
|
+
*
|
|
7947
|
+
* @param payload - The verified access-token payload the ticket is minted from.
|
|
7948
|
+
* @returns A positive whole number of seconds.
|
|
7949
|
+
* @throws {@link AuthException} `auth.token_invalid` when the token has no life left.
|
|
7950
|
+
*/
|
|
7951
|
+
private lifetimeFor;
|
|
7952
|
+
/**
|
|
7953
|
+
* Redeems a ticket at the handshake, consuming it.
|
|
7954
|
+
*
|
|
7955
|
+
* @param ticket - The raw ticket from the upgrade request.
|
|
7956
|
+
* @returns The identity the socket is authorized as.
|
|
7957
|
+
* @throws {@link AuthException} `auth.token_invalid` when the ticket is unknown, expired,
|
|
7958
|
+
* already redeemed, or minted by a session that has since been revoked — a logout or a bulk
|
|
7959
|
+
* revocation between the mint and the upgrade. These are deliberately indistinguishable to the
|
|
7960
|
+
* caller.
|
|
7961
|
+
*/
|
|
7962
|
+
redeem(ticket: string): Promise<WsTicketSnapshot>;
|
|
7963
|
+
}
|
|
7964
|
+
|
|
7965
|
+
/**
|
|
7966
|
+
* WebSocket authentication guard — the WS twin of {@link JwtAuthGuard}.
|
|
7967
|
+
*
|
|
7968
|
+
* Validates dashboard JWTs carried in the `Authorization` header of the Socket.IO/ws
|
|
7969
|
+
* handshake through {@link AuthTokenVerifierService}, the chain a request is held to:
|
|
7970
|
+
* signature, claim shapes, token type, revocation, tenant binding, the account's current
|
|
7971
|
+
* status and the MFA policy. The status and MFA gates are on by default; `@SkipMfa()` on
|
|
7972
|
+
* a handler or class lifts the MFA one only.
|
|
7973
|
+
*
|
|
7974
|
+
* @remarks
|
|
7975
|
+
* **Two credential channels, and only two** — the handshake
|
|
7976
|
+
* `Authorization: Bearer <token>` header, or a single-use ticket in the upgrade
|
|
7977
|
+
* query string.
|
|
7978
|
+
*
|
|
7979
|
+
* An access **token** in the query string stays unsupported, and for the original
|
|
7980
|
+
* reason: it is trivially captured in access logs, browser history and proxy
|
|
7981
|
+
* caches, which makes it equivalent to sending the credential in plaintext. But
|
|
7982
|
+
* the browser `WebSocket` API cannot set handshake headers, so header-only left
|
|
7983
|
+
* browser clients with no supported path at all — and a library that offers none
|
|
7984
|
+
* gets the query-string token anyway, written by the consumer.
|
|
7985
|
+
*
|
|
7986
|
+
* A ticket is the answer to that: minted by `POST {prefix}/ws-ticket` from a
|
|
7617
7987
|
* session that is already authenticated, in good standing and MFA-satisfied;
|
|
7618
7988
|
* opaque; ~30 seconds; and consumed by the first redemption, so a captured
|
|
7619
7989
|
* upgrade URL is worthless by the time it reaches a log. rust-auth authenticates
|
|
7620
7990
|
* its upgrades the same way.
|
|
7621
7991
|
*
|
|
7622
|
-
* **Algorithm pinning** — `algorithms: [this.options.jwt.algorithm]` is forwarded
|
|
7623
|
-
* to `JwtService.verify()` to prevent algorithm-confusion attacks (CVE-2015-9235).
|
|
7624
|
-
* An attacker cannot substitute `alg: none` or swap to an asymmetric algorithm.
|
|
7625
|
-
*
|
|
7626
7992
|
* **Soft peer-dependency on `@nestjs/websockets`** — this guard does not import
|
|
7627
7993
|
* `@nestjs/websockets` at module load time (which would create a hard dependency
|
|
7628
7994
|
* breaking consumers that never use WebSockets). Instead, a dynamic `import()`
|
|
@@ -7644,11 +8010,11 @@ declare class WsTicketService {
|
|
|
7644
8010
|
* @layer Guard
|
|
7645
8011
|
*/
|
|
7646
8012
|
declare class WsJwtGuard implements CanActivate, OnModuleInit {
|
|
7647
|
-
private readonly
|
|
7648
|
-
private readonly revocation;
|
|
8013
|
+
private readonly verifier;
|
|
7649
8014
|
private readonly wsTickets;
|
|
7650
8015
|
private readonly options;
|
|
7651
|
-
|
|
8016
|
+
private readonly reflector;
|
|
8017
|
+
constructor(verifier: AuthTokenVerifierService, wsTickets: WsTicketService, options: ResolvedOptions, reflector: Reflector);
|
|
7652
8018
|
/**
|
|
7653
8019
|
* Verifies that `@nestjs/websockets` is installed and throws a descriptive
|
|
7654
8020
|
* error at application startup if the package is absent.
|
|
@@ -10474,35 +10840,18 @@ declare class MfaFlowLockoutService {
|
|
|
10474
10840
|
private readonly bruteForce;
|
|
10475
10841
|
constructor(options: ResolvedOptions, bruteForce: BruteForceService);
|
|
10476
10842
|
/**
|
|
10477
|
-
* The
|
|
10478
|
-
*
|
|
10479
|
-
*
|
|
10480
|
-
*
|
|
10481
|
-
*
|
|
10482
|
-
* old pod counts a failure under `{flow}:{plane}:{userId}` while a new pod counts it under
|
|
10483
|
-
* `{flow}:{userSubject}`, and either alone leaves a hole: a lockout an old pod filled would not
|
|
10484
|
-
* stop a new pod, and a success on one would not clear the other. So every read consults both
|
|
10485
|
-
* and every write touches both, and the two move as one; the plane-only arm can be dropped once
|
|
10486
|
-
* no pod writes it. On the platform plane the two ids are identical, so the plane-only arm is
|
|
10487
|
-
* skipped: operating it would be the same key a second time, double-counting a failure and
|
|
10488
|
-
* locking a platform admin out at half the threshold. `{flow}` (`challenge` / `disable` /
|
|
10489
|
-
* `reauth`) keeps the three counters isolated from each other.
|
|
10490
|
-
*/
|
|
10491
|
-
private counterIds;
|
|
10492
|
-
/**
|
|
10493
|
-
* Locked out when EITHER the legacy or the tenant-scoped counter has reached the threshold, so
|
|
10494
|
-
* neither a lockout an old pod recorded nor one a new pod recorded can be bypassed mid-migration.
|
|
10843
|
+
* The brute-force identifier for one MFA flow: the flow and the account's length-prefixed subject,
|
|
10844
|
+
* which carries the tenant on the dashboard plane. Two tenants' user `1` therefore count under
|
|
10845
|
+
* different identifiers, so one tenant's failures can neither lock the other's account out nor be
|
|
10846
|
+
* cleared by it. `{flow}` (`challenge` / `disable` / `reauth`) keeps the three counters isolated
|
|
10847
|
+
* from each other.
|
|
10495
10848
|
*/
|
|
10849
|
+
private counterId;
|
|
10850
|
+
/** Whether the account's counter for this flow has reached the lockout threshold. */
|
|
10496
10851
|
isLockedOut(flow: MfaFlow, context: MfaFlowPlane, userId: string, tenantId: string | undefined): Promise<boolean>;
|
|
10497
|
-
/**
|
|
10498
|
-
* Records the failure under both counters so the budget an attacker spends is seen by old and
|
|
10499
|
-
* new code alike — but under the scoped id ONCE when the two coincide (platform plane).
|
|
10500
|
-
*/
|
|
10852
|
+
/** Records a failed attempt against the account's counter for this flow. */
|
|
10501
10853
|
recordFailure(flow: MfaFlow, context: MfaFlowPlane, userId: string, tenantId: string | undefined): Promise<void>;
|
|
10502
|
-
/**
|
|
10503
|
-
* Clears both counters on success — resetting only one would leave the other to lock a
|
|
10504
|
-
* legitimately authenticated user out on the next attempt — collapsing to one when they coincide.
|
|
10505
|
-
*/
|
|
10854
|
+
/** Clears the account's counter for this flow, on a success. */
|
|
10506
10855
|
reset(flow: MfaFlow, context: MfaFlowPlane, userId: string, tenantId: string | undefined): Promise<void>;
|
|
10507
10856
|
}
|
|
10508
10857
|
|
|
@@ -10640,10 +10989,6 @@ declare class MfaRecordService {
|
|
|
10640
10989
|
* both the subject and the code value prevents code disclosure in Redis and cross-user,
|
|
10641
10990
|
* cross-tenant and cross-plane replay alike.
|
|
10642
10991
|
*
|
|
10643
|
-
* A second marker under the plane-only preimage `{context}:{userId}:{code}` is written and
|
|
10644
|
-
* required alongside it; see the call site for why both must be fresh while pods of two
|
|
10645
|
-
* versions are live.
|
|
10646
|
-
*
|
|
10647
10992
|
* @returns `true` if the code is valid and has not been replayed, `false` otherwise.
|
|
10648
10993
|
*/
|
|
10649
10994
|
verifyTotpWithAntiReplay(context: 'dashboard' | 'platform', userId: string, secretBase32: string, code: string, window: number, tenantId: string | undefined): Promise<boolean>;
|
|
@@ -11918,360 +12263,6 @@ declare class PlatformAuthService {
|
|
|
11918
12263
|
revokeAllPlatformSessions(userId: string): Promise<void>;
|
|
11919
12264
|
}
|
|
11920
12265
|
|
|
11921
|
-
/**
|
|
11922
|
-
* @fileoverview `@CurrentWorkspace()`: the workspace and role `WorkspaceGuard` resolved for the
|
|
11923
|
-
* request.
|
|
11924
|
-
*
|
|
11925
|
-
* @layer Decorator
|
|
11926
|
-
*/
|
|
11927
|
-
/** The access `WorkspaceGuard` resolved for a request. */
|
|
11928
|
-
interface CurrentWorkspaceContext {
|
|
11929
|
-
/** The tenant, taken from the verified token. */
|
|
11930
|
-
tenantId: string;
|
|
11931
|
-
/** The workspace the request named, checked against the caller's active membership. */
|
|
11932
|
-
workspaceId: string;
|
|
11933
|
-
/** The caller. */
|
|
11934
|
-
userId: string;
|
|
11935
|
-
/** The caller's role in that workspace. */
|
|
11936
|
-
role: string;
|
|
11937
|
-
}
|
|
11938
|
-
/** A request after `WorkspaceGuard` ran. */
|
|
11939
|
-
interface WorkspaceRequest {
|
|
11940
|
-
workspace?: CurrentWorkspaceContext;
|
|
11941
|
-
}
|
|
11942
|
-
/**
|
|
11943
|
-
* Injects the workspace access the guard resolved.
|
|
11944
|
-
*
|
|
11945
|
-
* A service takes its workspace from here and never from a DTO or a query: the guard is the only
|
|
11946
|
-
* place that checked the caller may act in it. Throws when the route runs without
|
|
11947
|
-
* `WorkspaceGuard`, since an id read from anywhere else would be unchecked.
|
|
11948
|
-
*/
|
|
11949
|
-
declare const CurrentWorkspace: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
11950
|
-
|
|
11951
|
-
/**
|
|
11952
|
-
* @fileoverview The request a `tenantIdResolver` sees when the caller arrived by WebSocket upgrade.
|
|
11953
|
-
*
|
|
11954
|
-
* @layer Utility
|
|
11955
|
-
*/
|
|
11956
|
-
|
|
11957
|
-
/**
|
|
11958
|
-
* The fields {@link handshakeRequest} reads. A Socket.IO `handshake` fits, and so does an Express
|
|
11959
|
-
* request.
|
|
11960
|
-
*/
|
|
11961
|
-
interface HandshakeLike {
|
|
11962
|
-
headers: Record<string, string | string[] | undefined>;
|
|
11963
|
-
url?: string;
|
|
11964
|
-
/**
|
|
11965
|
-
* The TCP peer, as the transport reported it, never a header. Read only to decide whether
|
|
11966
|
-
* `X-Forwarded-Host` may be believed; absent or empty means it may not.
|
|
11967
|
-
*/
|
|
11968
|
-
remoteAddress?: string;
|
|
11969
|
-
}
|
|
11970
|
-
|
|
11971
|
-
/**
|
|
11972
|
-
* @fileoverview The whole identity chain for an access token, in one call.
|
|
11973
|
-
*
|
|
11974
|
-
* @layer Service
|
|
11975
|
-
*/
|
|
11976
|
-
|
|
11977
|
-
/**
|
|
11978
|
-
* Which identity plane a caller expects a token to belong to.
|
|
11979
|
-
*
|
|
11980
|
-
* Always supplied by the caller and never inferred from the token's own `type` claim: inferring
|
|
11981
|
-
* would make the plane attacker-chosen, so a platform token would open a dashboard stream simply
|
|
11982
|
-
* by saying it is one.
|
|
11983
|
-
*/
|
|
11984
|
-
type AuthPlane = 'dashboard' | 'platform';
|
|
11985
|
-
/**
|
|
11986
|
-
* The outcome of a successful verification, discriminated by the plane so a caller can narrow to
|
|
11987
|
-
* the payload it actually got.
|
|
11988
|
-
*
|
|
11989
|
-
* `plane` is the same value the caller asked for — it is on the result because a consumer keying
|
|
11990
|
-
* live connections needs to record it, and because a tenant cannot answer the question: a platform
|
|
11991
|
-
* token carries no tenant claim at all.
|
|
11992
|
-
*/
|
|
11993
|
-
type VerifiedAccessToken = {
|
|
11994
|
-
readonly plane: 'dashboard';
|
|
11995
|
-
readonly payload: DashboardJwtPayload;
|
|
11996
|
-
} | {
|
|
11997
|
-
readonly plane: 'platform';
|
|
11998
|
-
readonly payload: PlatformJwtPayload;
|
|
11999
|
-
};
|
|
12000
|
-
/**
|
|
12001
|
-
* The workspace a verification also admits the caller to.
|
|
12002
|
-
*
|
|
12003
|
-
* Judged exactly as `WorkspaceGuard` judges a route: the same access resolution, the same cache, the
|
|
12004
|
-
* same refusals in the same order, so a stream and a route can never disagree about a member.
|
|
12005
|
-
*/
|
|
12006
|
-
interface WorkspaceCheck {
|
|
12007
|
-
/** The workspace the caller names, from the message and never from the token or the URL. */
|
|
12008
|
-
readonly workspaceId: string;
|
|
12009
|
-
/** The roles that admit the caller; `ANY_WORKSPACE_MEMBER` admits every active member. */
|
|
12010
|
-
readonly roles: WorkspaceRoleList;
|
|
12011
|
-
/**
|
|
12012
|
-
* Admit the owner of a workspace pending deletion, for a read-only stream. Everyone else is still
|
|
12013
|
-
* answered `workspace_not_found`.
|
|
12014
|
-
*
|
|
12015
|
-
* @defaultValue false
|
|
12016
|
-
*/
|
|
12017
|
-
readonly allowPending?: boolean;
|
|
12018
|
-
}
|
|
12019
|
-
/** A dashboard verification that also admitted the caller to a workspace. */
|
|
12020
|
-
interface VerifiedWorkspaceAccessToken {
|
|
12021
|
-
readonly plane: 'dashboard';
|
|
12022
|
-
readonly payload: DashboardJwtPayload;
|
|
12023
|
-
/** The caller's membership of the workspace they were admitted to. */
|
|
12024
|
-
readonly workspace: CurrentWorkspaceContext;
|
|
12025
|
-
}
|
|
12026
|
-
/**
|
|
12027
|
-
* What a verification checks beyond the signature.
|
|
12028
|
-
*
|
|
12029
|
-
* Both flags default to `true`. They exist to be turned OFF deliberately, by a caller that has
|
|
12030
|
-
* already established the same fact by another route — never as a way to make a reconnect cheaper.
|
|
12031
|
-
*/
|
|
12032
|
-
interface VerifyAccessTokenOptions {
|
|
12033
|
-
/** The plane the caller expects. Required; see {@link AuthPlane}. */
|
|
12034
|
-
readonly plane: AuthPlane;
|
|
12035
|
-
/**
|
|
12036
|
-
* Refuse a token whose account has MFA enabled but which was not itself issued after a
|
|
12037
|
-
* successful challenge — the rule {@link MfaRequiredGuard} applies to an HTTP route.
|
|
12038
|
-
*
|
|
12039
|
-
* It matters most on a reconnect: a refresh carries `mfaVerified` forward only from a session
|
|
12040
|
-
* that completed the challenge, so a token that is otherwise entirely valid can still represent
|
|
12041
|
-
* a session that never did. The token's `type` does not imply it.
|
|
12042
|
-
*
|
|
12043
|
-
* @defaultValue true
|
|
12044
|
-
*/
|
|
12045
|
-
readonly requireMfa?: boolean;
|
|
12046
|
-
/**
|
|
12047
|
-
* Re-resolve the account's lifecycle status instead of trusting the snapshot the token carries,
|
|
12048
|
-
* refusing a blocked, deleted or — on the dashboard plane, where verification gates API
|
|
12049
|
-
* access — unverified account.
|
|
12050
|
-
*
|
|
12051
|
-
* The only check that can answer differently between two calls: a suspension lands between two
|
|
12052
|
-
* reconnects, and nothing in the token would say so.
|
|
12053
|
-
*
|
|
12054
|
-
* **Its freshness on the dashboard plane is bounded by `userStatusCacheTtlSeconds`, not by how
|
|
12055
|
-
* often you call.** That plane reads the `us:`/`uev:` cache, so a stream re-verifying every five
|
|
12056
|
-
* seconds still serves a banned account until the entry expires (default 60 s) — a tighter
|
|
12057
|
-
* cadence does not shorten that. What does is
|
|
12058
|
-
* {@link AccountStatusService.invalidate}: call it wherever you change an account's status, and
|
|
12059
|
-
* read what that method does **not** promise — a request already resolving when you invalidate
|
|
12060
|
-
* can write the old value back, so the window narrows to one repository read rather than to
|
|
12061
|
-
* zero. Failing that, lower the TTL. The platform plane is uncached and therefore genuinely
|
|
12062
|
-
* current, at the cost of a repository read per call.
|
|
12063
|
-
*
|
|
12064
|
-
* @defaultValue true
|
|
12065
|
-
*/
|
|
12066
|
-
readonly checkStatus?: boolean;
|
|
12067
|
-
/**
|
|
12068
|
-
* The request the credential arrived on — a Socket.IO `handshake`, an Express request, or any
|
|
12069
|
-
* object with `headers` and `url` — so `enforceTenantBinding` can be applied.
|
|
12070
|
-
*
|
|
12071
|
-
* The binding needs the request the host's `tenantIdResolver` reads, which a token alone does
|
|
12072
|
-
* not carry. With `enforceTenantBinding` on and a request passed, the resolver runs on the
|
|
12073
|
-
* dashboard plane exactly as it does in `WsJwtGuard`: it receives an object with only `headers`
|
|
12074
|
-
* (lowercased), `url` and `hostname` — no `cookies`, `ip` or `ips` — and a resolver that throws
|
|
12075
|
-
* on that, or answers another tenant, refuses the token with `TOKEN_INVALID`. The platform plane
|
|
12076
|
-
* has no tenant and ignores it.
|
|
12077
|
-
*
|
|
12078
|
-
* `hostname` is the `Host` header with the port cut. When the host configured `isTrustedProxy`,
|
|
12079
|
-
* pass the TCP peer as `request.remoteAddress` (never a header value): if the predicate trusts
|
|
12080
|
-
* it, the first element of a single `X-Forwarded-Host` is used instead, as Express does over
|
|
12081
|
-
* HTTP. Without a peer the `Host` header stands.
|
|
12082
|
-
*
|
|
12083
|
-
* **Omit it and the binding is not applied for that call.** With `enforceTenantBinding` on,
|
|
12084
|
-
* that is logged once per service instance, because a caller that never passes it has a
|
|
12085
|
-
* binding the HTTP guards enforce and this surface does not.
|
|
12086
|
-
*/
|
|
12087
|
-
readonly request?: HandshakeLike;
|
|
12088
|
-
/**
|
|
12089
|
-
* Also admit the caller to one workspace, resolved through the access cache the routes use, and
|
|
12090
|
-
* return their membership as `workspace`. A refusal is the guard's own: `workspace_not_found`
|
|
12091
|
-
* for a caller who is not an active member (and for every non-owner of a workspace pending
|
|
12092
|
-
* deletion, identically), `workspace_pending_deletion` for its owner, `insufficient_workspace_role`
|
|
12093
|
-
* for a role no accepted one covers, and `auth.validation` naming `workspaceId` for an id that is
|
|
12094
|
-
* blank, over-long or holds a control character, ahead of any lookup.
|
|
12095
|
-
*
|
|
12096
|
-
* Dashboard plane only, and only with `workspaces.enabled`: anything else is a `TypeError`,
|
|
12097
|
-
* because a platform token has no workspace and the feature is absent otherwise. A stream calls
|
|
12098
|
-
* it at subscribe time and again on its cadence or per message; a refusal means disconnect.
|
|
12099
|
-
*/
|
|
12100
|
-
readonly workspace?: WorkspaceCheck;
|
|
12101
|
-
}
|
|
12102
|
-
/**
|
|
12103
|
-
* Performs, in one call, every identity check a guarded HTTP route performs before a handler runs.
|
|
12104
|
-
*
|
|
12105
|
-
* A long-lived transport — a WebSocket, an SSE stream, a message consumer — has no guard in front
|
|
12106
|
-
* of it, so it has to establish the same facts itself, on a cadence, for as long as the connection
|
|
12107
|
-
* lives. Assembling that from the parts is where it goes wrong: {@link AuthRevocationService}
|
|
12108
|
-
* answers two channels and nothing else, and a bridge that calls it alone has verified a signature
|
|
12109
|
-
* and consulted a blacklist while checking neither the token's type, nor its `exp`, nor whether the
|
|
12110
|
-
* account behind it still exists.
|
|
12111
|
-
*
|
|
12112
|
-
* What one call establishes, in the order the refusals fire:
|
|
12113
|
-
*
|
|
12114
|
-
* 1. **Signature**, under the pinned algorithm and any secret retired by a rotation, plus the
|
|
12115
|
-
* configured `issuer` and `audience` — all of `verifyWithRotation`.
|
|
12116
|
-
* 2. **Expiry.** `exp` is enforced by the same verification. It is worth naming separately because
|
|
12117
|
-
* {@link AuthRevocationService.isAccessTokenRevoked} never reads it: a revocation check answers
|
|
12118
|
-
* "was this withdrawn", not "is this still current".
|
|
12119
|
-
* 3. **Claim shape** — `jti` a UUID v4, `sub` and (on the dashboard plane) `tenantId` bounded
|
|
12120
|
-
* non-empty strings. These become Redis keys downstream; a malformed one builds a key nobody
|
|
12121
|
-
* intended.
|
|
12122
|
-
* 4. **Token type**, matched against the plane the caller named. Without it an `mfa_challenge`
|
|
12123
|
-
* token — signed with the same secret, holding half a credential — reads as a valid session.
|
|
12124
|
-
* 5. **Revocation**, both channels: the per-token blacklist a logout writes and the per-user epoch
|
|
12125
|
-
* a password reset or an administrative revoke-all advances.
|
|
12126
|
-
* 6. **Account status**, unless the caller opted out. See
|
|
12127
|
-
* {@link VerifyAccessTokenOptions.checkStatus}.
|
|
12128
|
-
* 7. **MFA policy**, unless the caller opted out. See {@link VerifyAccessTokenOptions.requireMfa}.
|
|
12129
|
-
* Its claim-shape refusal (`mfaEnabled` missing or not a boolean, answered `TOKEN_INVALID`)
|
|
12130
|
-
* belongs to the token checks and fires before step 6; only the `MFA_REQUIRED` decision follows it.
|
|
12131
|
-
*
|
|
12132
|
-
* **Account status precedes the MFA policy.** A blocked account is refused with its own code even
|
|
12133
|
-
* while a challenge is pending, which is the answer a route guarded by `UserStatusGuard` ahead of
|
|
12134
|
-
* `MfaRequiredGuard` gives; a pending challenge is something the caller can act on only when the
|
|
12135
|
-
* account is usable, and the definitive refusal is the one it must see first.
|
|
12136
|
-
*
|
|
12137
|
-
* **What it still does not do, and cannot.** Route authorization is the consumer's — this answers
|
|
12138
|
-
* who the caller is, and with {@link VerifyAccessTokenOptions.workspace} which workspace they belong
|
|
12139
|
-
* to and in what role, never what they may do beyond that, so a `@Roles()` equivalent stays yours to
|
|
12140
|
-
* apply on every message a stream carries, not only at the handshake. Tenant binding
|
|
12141
|
-
* (`enforceTenantBinding`) needs the request the resolver reads, which a token does not carry:
|
|
12142
|
-
* pass the handshake as {@link VerifyAccessTokenOptions.request}, or the binding is not applied. And nothing here holds a subscription: it answers at the moment it is called, so a stream
|
|
12143
|
-
* that calls it once at connect is authorized for the lifetime of the token, not of the session.
|
|
12144
|
-
* Call it again on a cadence, and treat a rejection as a disconnect.
|
|
12145
|
-
*
|
|
12146
|
-
* @example
|
|
12147
|
-
* ```ts
|
|
12148
|
-
* const { plane, payload } = await this.verifier.verifyAccessToken(token, { plane: 'dashboard' })
|
|
12149
|
-
* registry.add(socket, { plane, userId: payload.sub, tenantId: payload.tenantId })
|
|
12150
|
-
* ```
|
|
12151
|
-
*
|
|
12152
|
-
* @layer Service
|
|
12153
|
-
*/
|
|
12154
|
-
declare class AuthTokenVerifierService {
|
|
12155
|
-
private readonly jwtService;
|
|
12156
|
-
private readonly options;
|
|
12157
|
-
private readonly revocation;
|
|
12158
|
-
private readonly accountStatus;
|
|
12159
|
-
private readonly workspaceAccess;
|
|
12160
|
-
private readonly deniedEvents;
|
|
12161
|
-
private readonly logger;
|
|
12162
|
-
/** Whether the "binding not applied" warning has been logged by this instance. */
|
|
12163
|
-
private warnedUnbound;
|
|
12164
|
-
/**
|
|
12165
|
-
* @param jwtService - The Nest JWT service, configured with the current signing secret.
|
|
12166
|
-
* @param options - Resolved module options, for the algorithm, the binding claims and the
|
|
12167
|
-
* secrets retired by a rotation.
|
|
12168
|
-
* @param revocation - The two revocation channels, shared with the mounted guards.
|
|
12169
|
-
* @param accountStatus - The account lifecycle gate, shared with {@link UserStatusGuard}.
|
|
12170
|
-
*/
|
|
12171
|
-
constructor(jwtService: JwtService, options: ResolvedOptions, revocation: AuthRevocationService, accountStatus: AccountStatusService, workspaceAccess?: WorkspaceAccessService | null, deniedEvents?: WorkspaceDeniedEventsService | null);
|
|
12172
|
-
/**
|
|
12173
|
-
* Verifies an access token and returns its payload, or throws.
|
|
12174
|
-
*
|
|
12175
|
-
* Every refusal is an {@link AuthException}, and each mirrors the code the equivalent guard
|
|
12176
|
-
* already answers, so a consumer moving a surface onto this service keeps branching on what it
|
|
12177
|
-
* branched on before.
|
|
12178
|
-
*
|
|
12179
|
-
* Most token-shaped failures answer `TOKEN_INVALID` without naming which check refused: telling
|
|
12180
|
-
* "valid but revoked" apart from "never valid" is an oracle for no benefit. Three name
|
|
12181
|
-
* themselves, because a legitimate client acts on each differently — `MFA_REQUIRED` means
|
|
12182
|
-
* complete the challenge, the `ACCOUNT_*` codes mean the account itself is refused, and
|
|
12183
|
-
* `PLATFORM_AUTH_REQUIRED` means a token for the other context was presented. That last one is
|
|
12184
|
-
* the platform plane only, and it is what {@link JwtPlatformGuard} answers there; the dashboard
|
|
12185
|
-
* plane collapses a wrong type into `TOKEN_INVALID`, as {@link JwtAuthGuard} does.
|
|
12186
|
-
*
|
|
12187
|
-
* @param token - The compact JWT, exactly as presented. Never a decoded payload: a caller that
|
|
12188
|
-
* already decoded it has skipped the signature, which is the check everything else rests on.
|
|
12189
|
-
* @param options - The plane, and which of the two optional checks to run.
|
|
12190
|
-
* @returns The verified payload, tagged with the plane it was checked against.
|
|
12191
|
-
* @throws {@link AuthException} with `TOKEN_INVALID` when the signature, expiry, claim shape,
|
|
12192
|
-
* dashboard token type or revocation state refuses the token; `PLATFORM_AUTH_REQUIRED` when a
|
|
12193
|
-
* non-platform token is presented on the platform plane; the matching `ACCOUNT_*` /
|
|
12194
|
-
* `EMAIL_NOT_VERIFIED` code when the account is no longer usable, whether or not a challenge is
|
|
12195
|
-
* pending; or `MFA_REQUIRED` when the account is usable, has MFA enabled and this token
|
|
12196
|
-
* predates its challenge.
|
|
12197
|
-
* @throws {TypeError} When `options.plane` is neither `'dashboard'` nor `'platform'` — a caller
|
|
12198
|
-
* error rather than an authentication outcome, so it is deliberately not an `AuthException`.
|
|
12199
|
-
*/
|
|
12200
|
-
verifyAccessToken(token: string, options: VerifyAccessTokenOptions & {
|
|
12201
|
-
plane: 'dashboard';
|
|
12202
|
-
workspace: WorkspaceCheck;
|
|
12203
|
-
}): Promise<VerifiedWorkspaceAccessToken>;
|
|
12204
|
-
verifyAccessToken(token: string, options: VerifyAccessTokenOptions): Promise<VerifiedAccessToken>;
|
|
12205
|
-
/**
|
|
12206
|
-
* The dashboard arm: the full chain plus the tenant claim and the tenant-scoped status gate.
|
|
12207
|
-
*
|
|
12208
|
-
* @param token - The compact JWT.
|
|
12209
|
-
* @param requireMfa - Whether to apply the MFA policy.
|
|
12210
|
-
* @param checkStatus - Whether to consult the account's current status.
|
|
12211
|
-
* @param request - The request the token arrived on, for `enforceTenantBinding`.
|
|
12212
|
-
* @returns The verified dashboard payload.
|
|
12213
|
-
* @throws {@link AuthException} as {@link verifyAccessToken} documents.
|
|
12214
|
-
*/
|
|
12215
|
-
private verifyDashboard;
|
|
12216
|
-
/**
|
|
12217
|
-
* The function that admits a caller to a workspace, or a `TypeError` when none can: on a plane
|
|
12218
|
-
* with no workspaces, or on a deployment that has not enabled them. A programmer's error.
|
|
12219
|
-
*
|
|
12220
|
-
* The returned function admits the caller as `WorkspaceGuard` would a route, with `auth.validation`
|
|
12221
|
-
* for a malformed id and then the guard's refusals.
|
|
12222
|
-
*/
|
|
12223
|
-
private workspaceResolver;
|
|
12224
|
-
/**
|
|
12225
|
-
* Applies `enforceTenantBinding` when a request was passed, and says so once when it could not.
|
|
12226
|
-
*
|
|
12227
|
-
* @param tenantId - The tenant the token was issued for.
|
|
12228
|
-
* @param request - The request the token arrived on, when the caller supplied one.
|
|
12229
|
-
* @throws {@link AuthException} with `TOKEN_INVALID` as {@link assertTenantBinding} documents.
|
|
12230
|
-
*/
|
|
12231
|
-
private assertBound;
|
|
12232
|
-
/**
|
|
12233
|
-
* The platform arm. No tenant claim exists to assert or to scope by — a platform administrator
|
|
12234
|
-
* is cross-tenant, which is also why the revocation read is told which epoch namespace to use.
|
|
12235
|
-
*
|
|
12236
|
-
* @param token - The compact JWT.
|
|
12237
|
-
* @param requireMfa - Whether to apply the MFA policy.
|
|
12238
|
-
* @param checkStatus - Whether to consult the administrator's current status.
|
|
12239
|
-
* @returns The verified platform payload.
|
|
12240
|
-
* @throws {@link AuthException} as {@link verifyAccessToken} documents.
|
|
12241
|
-
*/
|
|
12242
|
-
private verifyPlatform;
|
|
12243
|
-
/**
|
|
12244
|
-
* Verifies signature, algorithm, binding claims and expiry, collapsing every failure to one
|
|
12245
|
-
* opaque refusal.
|
|
12246
|
-
*
|
|
12247
|
-
* @typeParam T - The payload shape the caller's plane expects.
|
|
12248
|
-
* @param token - The compact JWT.
|
|
12249
|
-
* @returns The decoded payload, cast to `T`. The claims are asserted by the caller.
|
|
12250
|
-
* @throws {@link AuthException} with `TOKEN_INVALID` when no configured secret accepts it.
|
|
12251
|
-
*/
|
|
12252
|
-
private verifySignature;
|
|
12253
|
-
/**
|
|
12254
|
-
* Refuses a token whose `mfaEnabled` claim is missing or not a boolean.
|
|
12255
|
-
*
|
|
12256
|
-
* The `typeof` arm is not defensive noise: the payload is cast from a token, so a signed token
|
|
12257
|
-
* that simply omits `mfaEnabled` would otherwise compare `undefined === true`, read as "MFA is
|
|
12258
|
-
* off" and pass a gate it was never shown to. It is a claim-shape refusal, so it runs with the
|
|
12259
|
-
* other token checks and ahead of the account lookup.
|
|
12260
|
-
*
|
|
12261
|
-
* @param payload - The verified payload, either plane.
|
|
12262
|
-
* @throws {@link AuthException} with `TOKEN_INVALID` when the claim is missing or not a boolean.
|
|
12263
|
-
*/
|
|
12264
|
-
private assertMfaClaimShape;
|
|
12265
|
-
/**
|
|
12266
|
-
* Applies the MFA policy to a payload whose claim shape was already checked.
|
|
12267
|
-
*
|
|
12268
|
-
* @param payload - The verified payload, either plane.
|
|
12269
|
-
* @throws {@link AuthException} with `MFA_REQUIRED` when MFA is enabled and this token predates
|
|
12270
|
-
* the challenge.
|
|
12271
|
-
*/
|
|
12272
|
-
private assertMfaVerified;
|
|
12273
|
-
}
|
|
12274
|
-
|
|
12275
12266
|
/**
|
|
12276
12267
|
* @fileoverview The membership side of the workspace lifecycle: listings, role changes, removal,
|
|
12277
12268
|
* leaving and ownership transfer.
|
|
@@ -13071,7 +13062,8 @@ declare class OAuthService {
|
|
|
13071
13062
|
* @param code - The authorization code.
|
|
13072
13063
|
* @param codeVerifier - The PKCE verifier stored with the state.
|
|
13073
13064
|
* @returns The normalized profile.
|
|
13074
|
-
* @throws `AuthException(OAUTH_FAILED)` when the exchange or the fetch fails
|
|
13065
|
+
* @throws `AuthException(OAUTH_FAILED)` when the exchange or the fetch fails, or the plugin's
|
|
13066
|
+
* deadline passes first.
|
|
13075
13067
|
*/
|
|
13076
13068
|
private fetchProfile;
|
|
13077
13069
|
/**
|
|
@@ -13950,6 +13942,160 @@ declare function decodeWorkspaceScopedName(name: string): {
|
|
|
13950
13942
|
parts: string[];
|
|
13951
13943
|
};
|
|
13952
13944
|
|
|
13945
|
+
/**
|
|
13946
|
+
* @fileoverview The keyset cursor codec of the workspace lists: the key a cursor is bound to, the
|
|
13947
|
+
* position of a row in a list's order, and the opaque cursor that carries both between pages.
|
|
13948
|
+
*
|
|
13949
|
+
* A repository serving `listForUser`, `listForWorkspace` or `listSoleOwned` pages by a keyset, and
|
|
13950
|
+
* the port requires one rule of every cursor it reads: a malformed cursor, or one issued for another
|
|
13951
|
+
* query, restarts from the first page and never widens the scope. That rule lives here once, so an
|
|
13952
|
+
* adapter does not write its own.
|
|
13953
|
+
*
|
|
13954
|
+
* @layer Utility
|
|
13955
|
+
*/
|
|
13956
|
+
/**
|
|
13957
|
+
* The longest cursor, in characters.
|
|
13958
|
+
*
|
|
13959
|
+
* Sized for the longest cursor a listing can issue from the ids the library admits: a tenant, a
|
|
13960
|
+
* member and a row id of up to {@link WORKSPACE_CURSOR_PART_MAX_LENGTH} code points each, whatever
|
|
13961
|
+
* non-control characters they hold (JSON escapes a quote twice, which is the costliest of them), and
|
|
13962
|
+
* an owner role of up to {@link WORKSPACE_OWNER_ROLE_MAX_LENGTH} code points: 2306 characters at
|
|
13963
|
+
* most. A tenant and a member a host builds from control characters or unpaired surrogates, which
|
|
13964
|
+
* JSON escapes at six or seven bytes each, still fit: the longest such cursor is 3330 characters.
|
|
13965
|
+
* The HTTP page query and the decoder both use this value, so a cursor the library issues is
|
|
13966
|
+
* always one it accepts.
|
|
13967
|
+
*/
|
|
13968
|
+
declare const WORKSPACE_CURSOR_MAX_LENGTH = 4096;
|
|
13969
|
+
/**
|
|
13970
|
+
* The longest id, tenant or key part a cursor is sized for, in code points: the unit every request
|
|
13971
|
+
* bound of the library counts in, so an emoji is one.
|
|
13972
|
+
*/
|
|
13973
|
+
declare const WORKSPACE_CURSOR_PART_MAX_LENGTH = 128;
|
|
13974
|
+
/**
|
|
13975
|
+
* The longest owner role name, in code points; the role is part of the key of `listSoleOwned`.
|
|
13976
|
+
*
|
|
13977
|
+
* The bound is what keeps that cursor under {@link WORKSPACE_CURSOR_MAX_LENGTH} whatever characters the
|
|
13978
|
+
* role holds. It needs no charset: the costliest role, 32 quote characters or 32 emoji, gives 2306
|
|
13979
|
+
* characters beside a tenant, a member and a row id of 128 well-formed code points.
|
|
13980
|
+
*/
|
|
13981
|
+
declare const WORKSPACE_OWNER_ROLE_MAX_LENGTH = 32;
|
|
13982
|
+
/**
|
|
13983
|
+
* Whether a name may be the owner role: 1 to {@link WORKSPACE_OWNER_ROLE_MAX_LENGTH} code points of
|
|
13984
|
+
* well-formed text with no control character, the rule an id follows. The role is part of the key a
|
|
13985
|
+
* `listSoleOwned` cursor is bound to, so its length is what keeps that cursor within
|
|
13986
|
+
* {@link WORKSPACE_CURSOR_MAX_LENGTH}; its characters are free.
|
|
13987
|
+
*
|
|
13988
|
+
* @param role - The name.
|
|
13989
|
+
* @returns `true` when the name is acceptable.
|
|
13990
|
+
*/
|
|
13991
|
+
declare function isWorkspaceOwnerRole(role: string): boolean;
|
|
13992
|
+
/**
|
|
13993
|
+
* The key of a value scoped by tenant and further parts, and the key a cursor is bound to.
|
|
13994
|
+
*
|
|
13995
|
+
* It is `JSON.stringify` of the parts, byte for byte, so `('a:b', 'c')` and `('a', 'b:c')` stay two
|
|
13996
|
+
* keys whatever characters a part holds, and the key is also fit for anything else that must be
|
|
13997
|
+
* unambiguous: a lock name, a map key. A cursor is valid "for the same tenant and member" only as
|
|
13998
|
+
* far as the key it is bound to tells two scopes apart.
|
|
13999
|
+
*
|
|
14000
|
+
* @param parts - The query's name, then the parts that scope it, the tenant first.
|
|
14001
|
+
* @returns The unambiguous key.
|
|
14002
|
+
*/
|
|
14003
|
+
declare function workspaceQueryKey(...parts: readonly string[]): string;
|
|
14004
|
+
/**
|
|
14005
|
+
* A row's position in a keyset order: its creation instant, then its id. The instant is an ISO
|
|
14006
|
+
* string of exactly 24 characters, so comparing the joined string orders by instant first and by id
|
|
14007
|
+
* among rows created in the same millisecond.
|
|
14008
|
+
*
|
|
14009
|
+
* @param at - The row's creation instant.
|
|
14010
|
+
* @param id - The id that breaks ties.
|
|
14011
|
+
* @returns The position.
|
|
14012
|
+
* @throws {RangeError} For an invalid date.
|
|
14013
|
+
*/
|
|
14014
|
+
declare function workspacePositionOf(at: Date, id: string): string;
|
|
14015
|
+
/**
|
|
14016
|
+
* Splits a position back into its instant and its id, for a store that compares them as a pair.
|
|
14017
|
+
*
|
|
14018
|
+
* @param position - A position from {@link decodeWorkspaceCursor}.
|
|
14019
|
+
* @returns The instant and the id, or `undefined` when the first 24 characters are not an instant
|
|
14020
|
+
* in the canonical ISO form.
|
|
14021
|
+
*/
|
|
14022
|
+
declare function readWorkspacePosition(position: string): {
|
|
14023
|
+
at: Date;
|
|
14024
|
+
id: string;
|
|
14025
|
+
} | undefined;
|
|
14026
|
+
/**
|
|
14027
|
+
* The opaque cursor for a keyset page: the query it belongs to and the position of the last row
|
|
14028
|
+
* returned, as base64url of the JSON of the pair.
|
|
14029
|
+
*
|
|
14030
|
+
* @param query - The key the cursor is valid for, from {@link workspaceQueryKey}.
|
|
14031
|
+
* @param position - The last row's position, from {@link workspacePositionOf}.
|
|
14032
|
+
* @returns The cursor.
|
|
14033
|
+
* @throws {RangeError} For a position the decoder would read as none, an empty one or one with an
|
|
14034
|
+
* unpaired surrogate, and when the cursor would be longer than {@link WORKSPACE_CURSOR_MAX_LENGTH},
|
|
14035
|
+
* which only an id, tenant or key part over {@link WORKSPACE_CURSOR_PART_MAX_LENGTH} code points
|
|
14036
|
+
* can cause: the message names the part. It fails loudly because a cursor the page query would
|
|
14037
|
+
* refuse makes the next page unreachable.
|
|
14038
|
+
*/
|
|
14039
|
+
declare function encodeWorkspaceCursor(query: string, position: string): string;
|
|
14040
|
+
/**
|
|
14041
|
+
* Reads a cursor back for one query. Anything that is not exactly what {@link encodeWorkspaceCursor}
|
|
14042
|
+
* writes for this query reads as none, so the page restarts from the first one and never widens the
|
|
14043
|
+
* scope: a value that is not a string, one over {@link WORKSPACE_CURSOR_MAX_LENGTH}, another spelling
|
|
14044
|
+
* of the same pair (base64url, JSON whitespace or escapes, a byte order mark, bytes that are not
|
|
14045
|
+
* UTF-8), anything but a pair of two strings, a pair issued for another query, and a position that
|
|
14046
|
+
* is not an instant followed by an id of 1 to {@link WORKSPACE_CURSOR_PART_MAX_LENGTH} code points
|
|
14047
|
+
* with no control character and no unpaired surrogate.
|
|
14048
|
+
*
|
|
14049
|
+
* The cursor is a bookmark, not a signature: a well-formed position another instant names reads as
|
|
14050
|
+
* given, and moves within the same scope and nowhere else, because the scope comes from the query
|
|
14051
|
+
* the store builds and never from the cursor. The cursor is also readable by the client, so the
|
|
14052
|
+
* key holds only what the caller already knows (their own tenant, member and workspace), never a
|
|
14053
|
+
* value that must stay on the server. It never throws.
|
|
14054
|
+
*
|
|
14055
|
+
* @param cursor - The cursor the caller sent, of any type a request can carry.
|
|
14056
|
+
* @param query - The key of the query being paged, from {@link workspaceQueryKey}.
|
|
14057
|
+
* @returns The position to resume after, or `undefined` for the first page.
|
|
14058
|
+
*/
|
|
14059
|
+
declare function decodeWorkspaceCursor(cursor: unknown, query: string): string | undefined;
|
|
14060
|
+
|
|
14061
|
+
/**
|
|
14062
|
+
* @fileoverview Reads the workspace a request names, from the route or the host's resolver.
|
|
14063
|
+
*
|
|
14064
|
+
* @layer Utility
|
|
14065
|
+
*/
|
|
14066
|
+
|
|
14067
|
+
/**
|
|
14068
|
+
* The longest workspace id, in code points: the bound every request path applies, an emoji counting
|
|
14069
|
+
* once.
|
|
14070
|
+
*/
|
|
14071
|
+
declare const WORKSPACE_ID_MAX_LENGTH = 128;
|
|
14072
|
+
/**
|
|
14073
|
+
* Requires a candidate workspace id to be a bounded string without control characters, and refuses
|
|
14074
|
+
* one that is not with `auth.validation` naming the field `workspaceId`, the answer a handshake or a
|
|
14075
|
+
* route gives. A host that takes the id from a client calls it before using the id.
|
|
14076
|
+
*
|
|
14077
|
+
* The rule is the one the cursor codec holds an id to (1 to {@link WORKSPACE_ID_MAX_LENGTH} code points
|
|
14078
|
+
* with no control character) except that it does not refuse an unpaired surrogate.
|
|
14079
|
+
*
|
|
14080
|
+
* @param value - What a source returned.
|
|
14081
|
+
* @returns The id.
|
|
14082
|
+
* @throws {AuthException} `auth.validation` when it is not.
|
|
14083
|
+
*/
|
|
14084
|
+
declare function assertWorkspaceId(value: unknown): string;
|
|
14085
|
+
|
|
14086
|
+
/**
|
|
14087
|
+
* @fileoverview The strength bar every module secret must clear: long enough and varied enough that
|
|
14088
|
+
* it was generated, not typed.
|
|
14089
|
+
*
|
|
14090
|
+
* @layer Config
|
|
14091
|
+
*/
|
|
14092
|
+
/**
|
|
14093
|
+
* The shortest a secret may be, in characters, for every secret option: `jwt.secret`, each retired
|
|
14094
|
+
* signing secret, `identifierKey` and `apiKeys.pepper`. A host's own configuration check reads it
|
|
14095
|
+
* here instead of keeping a copy that could drift from the one startup enforces.
|
|
14096
|
+
*/
|
|
14097
|
+
declare const AUTH_SECRET_MIN_LENGTH = 32;
|
|
14098
|
+
|
|
13953
14099
|
/**
|
|
13954
14100
|
* @fileoverview Stamps the context a queued job carries.
|
|
13955
14101
|
*
|
|
@@ -14388,5 +14534,5 @@ declare class WorkspaceInvitationService {
|
|
|
14388
14534
|
private activeWorkspace;
|
|
14389
14535
|
}
|
|
14390
14536
|
|
|
14391
|
-
export { ALLOW_PENDING_WORKSPACE_KEY, ANY_WORKSPACE_MEMBER, API_KEY_MAX_LABEL_LENGTH, API_KEY_MAX_OVERLAP_SECONDS, AUTH_EMAIL_KINDS, AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_SECURITY_SCHEMES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AccountStatusService, AllowAllBreachChecker, AllowPendingWorkspace, ApiKeyGuard, ApiKeyScopes, ApiKeyService, AuthException, AuthExceptionFilter, AuthRateLimit, AuthRateLimitGuard, AuthRevocationService, AuthService, AuthTokenVerifierService, Authenticated, BYMAX_AUTH_API_KEY_CLOCK, BYMAX_AUTH_API_KEY_REPOSITORY, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_MEMBERSHIP_REPOSITORY, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, BYMAX_AUTH_WORKSPACE_REPOSITORY, BruteForceService, BymaxAuthModule, ChangePasswordDto, CommonPasswordChecker, CreateInvitationDto, CurrentApiKey, CurrentUser, CurrentWorkspace, CurrentWsWorkspace, DefaultAuthEmailProvider, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, IS_PUBLIC_KEY, InvitationService, JwtAuthGuard, JwtPlatformGuard, LoginDto, MembershipBumpFailedError, MembershipService, MfaChallengeDto, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, PlatformAuthService, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, ReauthenticationService, RegisterDto, RequestEncoding, RequestEncodingGuard, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, Roles, RolesGuard, SKIP_MFA_KEY, SelfOrAdminGuard, ServiceKey, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WORKSPACE_PERMISSION_KEY, WORKSPACE_ROLES_KEY, WS_TICKET_TTL_SECONDS, WorkspaceAccessService, WorkspaceActionsService, WorkspaceCallerService, WorkspaceGuard, WorkspaceInvitationService, WorkspacePermission, WorkspaceRoles, WorkspaceService, WsAuthExceptionFilter, WsJwtGuard, WsTicketService, WsWorkspaceGuard, authDocumentSecurity, createAuthValidationPipe, decodeWorkspaceScopedName, decrypt, describeChannelStatus, describeError, encrypt, generateSecureToken, hasRole, hmacSha256, redactSecrets, reduceToBaseWord, sanitizeHeaders, sha256, sleep, stampJobContext, timingSafeCompare, workspaceScopedName };
|
|
14537
|
+
export { ALLOW_PENDING_WORKSPACE_KEY, ANY_WORKSPACE_MEMBER, API_KEY_MAX_LABEL_LENGTH, API_KEY_MAX_OVERLAP_SECONDS, AUTH_EMAIL_KINDS, AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_SECRET_MIN_LENGTH, AUTH_SECURITY_SCHEMES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AccountStatusService, AllowAllBreachChecker, AllowPendingWorkspace, ApiKeyGuard, ApiKeyScopes, ApiKeyService, AuthException, AuthExceptionFilter, AuthRateLimit, AuthRateLimitGuard, AuthRevocationService, AuthService, AuthTokenVerifierService, Authenticated, BYMAX_AUTH_API_KEY_CLOCK, BYMAX_AUTH_API_KEY_REPOSITORY, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_MEMBERSHIP_REPOSITORY, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, BYMAX_AUTH_WORKSPACE_REPOSITORY, BruteForceService, BymaxAuthModule, ChangePasswordDto, CommonPasswordChecker, CreateInvitationDto, CurrentApiKey, CurrentUser, CurrentWorkspace, CurrentWsWorkspace, DefaultAuthEmailProvider, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, IS_PUBLIC_KEY, InvitationService, JwtAuthGuard, JwtPlatformGuard, LoginDto, MembershipBumpFailedError, MembershipService, MfaChallengeDto, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, PlatformAuthService, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, ReauthenticationService, RegisterDto, RequestEncoding, RequestEncodingGuard, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, Roles, RolesGuard, SKIP_MFA_KEY, SelfOrAdminGuard, ServiceKey, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WORKSPACE_CURSOR_MAX_LENGTH, WORKSPACE_CURSOR_PART_MAX_LENGTH, WORKSPACE_ID_MAX_LENGTH, WORKSPACE_OWNER_ROLE_MAX_LENGTH, WORKSPACE_PERMISSION_KEY, WORKSPACE_ROLES_KEY, WS_TICKET_TTL_SECONDS, WorkspaceAccessService, WorkspaceActionsService, WorkspaceCallerService, WorkspaceGuard, WorkspaceInvitationService, WorkspacePermission, WorkspaceRoles, WorkspaceService, WsAuthExceptionFilter, WsJwtGuard, WsTicketService, WsWorkspaceGuard, assertWorkspaceId, authDocumentSecurity, createAuthValidationPipe, decodeWorkspaceCursor, decodeWorkspaceScopedName, decrypt, describeChannelStatus, describeError, encodeWorkspaceCursor, encrypt, generateSecureToken, hasRole, hmacSha256, isWorkspaceOwnerRole, readWorkspacePosition, redactSecrets, reduceToBaseWord, sanitizeHeaders, sha256, sleep, stampJobContext, timingSafeCompare, workspacePositionOf, workspaceQueryKey, workspaceScopedName };
|
|
14392
14538
|
export type { AcceptedInvitation, AcceptedSignup, AccountRemovalAudit, ActingMember, ApiKeyAccessEvent, ApiKeyClock, ApiKeyDenyReason, ApiKeyPrincipal, AuthApiKey, AuthApiKeySummary, AuthDocumentSecurityParams, AuthEmailCatalogue, AuthEmailContext, AuthEmailKind, AuthEmailMessage, AuthEmailSink, AuthErrorCode, AuthFieldError, AuthGuardFamily, AuthMembership, AuthModuleAsyncOptions, AuthPlane, AuthPlatformUser, AuthRateLimitWindow, AuthResult, AuthUser, AuthWorkspace, AuthenticatedRequest, BearerAuthResponse, BeforeRegisterResult, BeforeWorkspaceCreateResult, BootstrapInvitationRecord, BothAuthResponse, BymaxAuthModuleOptions, BymaxAuthRateLimitOptions, ChangeMembershipRoleParams, ClientIpSource, CookieAuthResponse, CountOwnedParams, CreateMembershipParams, CreateMembershipResult, CreateSessionParams, CreateUserData, CreateWithOAuthData, CreateWorkspaceResult, CreateWorkspaceWithOwnerParams, CurrentWorkspaceContext, DashboardJwtPayload, DefaultAuthEmailProviderOptions, DeliveryErrorPolicy, DeliveryErrorPolicyMap, FinalizeResult, FindUserByEmailParams, FindUserByOAuthIdParams, GuardedWriteResult, HookContext, IApiKeyRepository, IAuthHooks, IEmailProvider, IMembershipRepository, IPasswordBreachChecker, IPlatformUserRepository, IUserRepository, IWorkspaceRepository, InviteData, IssueApiKeyInput, IssuedApiKey, LastActiveWorkspaceRef, LinkOAuthParams, ListMembershipsForUserParams, ListMembershipsForWorkspaceParams, ListSessionsParams, ListSoleOwnedParams, LiveSessionParams, MemberChangeResult, MemberInvitationRecord, MembershipPage, MembershipRef, MembershipStatus, MembershipWithWorkspace, MfaChallengeResult, MfaSetupResult, MfaTempPayload, MyWorkspaces, OAuthLoginResult, OAuthMfaChallengeResult, OAuthProfile, OAuthProviderPlugin, OpenApiSecurityRequirement, PlatformAuthResult, PlatformAuthenticatedRequest, PlatformBearerAuthResponse, PlatformJwtPayload, RegistrationMode, RemoveAllMembershipsParams, RemoveAllMembershipsResult, RemoveMembershipParams, RemovedMembership, RenameWorkspaceParams, RenameWorkspaceResult, RequestEncodingPolicy, ResolvedOptions, ResolvedWorkspaceMember, RevocableTokenPayload, RevokeAllExceptCurrentParams, RevokeAllSessionsParams, RevokeSessionParams, RotateApiKeyInput, RotatedTokenResult, SafeAuthPlatformUser, SafeAuthUser, ScheduledDeletion, SessionAlertInfo, SessionInfo, SetLastActiveWorkspaceParams, SignupRequest, StoredWorkspaceInvitation, TenantResolverRequest, TenantScopedUserRef, TransferOwnershipParams, TransferOwnershipResult, UpdateEmailParams, UpdateEmailVerifiedParams, UpdateMfaData, UpdateMfaParams, UpdatePasswordParams, UpdatePlatformMfaData, UpdateStatusParams, UpdateWorkspaceStatusParams, UpdateWorkspaceStatusResult, VerifiedAccessToken, VerifiedWorkspaceAccessToken, VerifyAccessTokenOptions, WorkspaceAccess, WorkspaceAccessView, WorkspaceAction, WorkspaceActor, WorkspaceAuditEvent, WorkspaceCheck, WorkspaceInvitationPreview, WorkspaceInvitationView, WorkspaceInviteData, WorkspaceJobContext, WorkspaceOptions, WorkspacePermissionOptions, WorkspaceRef, WorkspaceRequest, WorkspaceRoleList, WorkspaceStatus, WsTicketSnapshot };
|