@bymax-one/nest-auth 1.3.0 → 1.3.2
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 +129 -1
- package/README.md +43 -12
- package/dist/server/index.cjs +2286 -1265
- package/dist/server/index.d.cts +420 -35
- package/dist/server/index.d.ts +420 -35
- package/dist/server/index.mjs +2286 -1266
- package/dist/shared/index.d.cts +8 -0
- package/dist/shared/index.d.ts +8 -0
- package/package.json +2 -2
package/dist/server/index.d.ts
CHANGED
|
@@ -213,10 +213,18 @@ interface IUserRepository {
|
|
|
213
213
|
/**
|
|
214
214
|
* Updates the user's TOTP MFA configuration.
|
|
215
215
|
*
|
|
216
|
+
* The tenant is required for the same reason {@link findById} takes one: the library may not
|
|
217
|
+
* assume ids are unique across tenants, so a write keyed by id alone can land on another tenant's
|
|
218
|
+
* row — or on a row other than the one the MFA flow read a moment earlier, which would leave a
|
|
219
|
+
* spent recovery code in the account's list. An implementation MUST scope the update by both the
|
|
220
|
+
* id and the tenant, exactly as its read does.
|
|
221
|
+
*
|
|
216
222
|
* @param id - The user's unique identifier.
|
|
223
|
+
* @param tenantId - The tenant the account belongs to; the update MUST be scoped to it, as
|
|
224
|
+
* {@link findById} scopes its read. Never omitted for a dashboard account.
|
|
217
225
|
* @param data - New MFA state. See {@link UpdateMfaData}.
|
|
218
226
|
*/
|
|
219
|
-
updateMfa(id: string, data: UpdateMfaData): Promise<void>;
|
|
227
|
+
updateMfa(id: string, tenantId: string | undefined, data: UpdateMfaData): Promise<void>;
|
|
220
228
|
/**
|
|
221
229
|
* Records the current timestamp as the user's last successful login time.
|
|
222
230
|
*
|
|
@@ -1100,6 +1108,25 @@ interface BymaxAuthModuleOptions {
|
|
|
1100
1108
|
* ```
|
|
1101
1109
|
*/
|
|
1102
1110
|
tenantIdResolver?: (req: Request) => string | Promise<string>;
|
|
1111
|
+
/**
|
|
1112
|
+
* Whether the dashboard guard re-resolves the request's tenant and rejects a token whose
|
|
1113
|
+
* `tenantId` claim does not match it.
|
|
1114
|
+
*
|
|
1115
|
+
* The resolver runs on the credential flows — register, login, OTP, OAuth — where it decides
|
|
1116
|
+
* which tenant an account is scoped to. It does **not** run on every guarded request: a valid
|
|
1117
|
+
* token is trusted for the tenant baked into it. That is safe on its own, because a token minted
|
|
1118
|
+
* for tenant A never carries tenant B, so there is no cross-tenant escalation to be had. What it
|
|
1119
|
+
* does leave open is a token being *presented* under the wrong host — accepted, and operating as
|
|
1120
|
+
* its own tenant rather than the host's. For a deployment where the host is the tenant boundary
|
|
1121
|
+
* (subdomain-per-tenant behind an edge that refuses a `Host` it does not serve), turning this on
|
|
1122
|
+
* closes that gap: the guard calls {@link tenantIdResolver} and refuses a mismatch.
|
|
1123
|
+
*
|
|
1124
|
+
* Off by default, and requires a resolver to have any effect: with no resolver there is nothing
|
|
1125
|
+
* to compare against. Leave it off where a token is legitimately used across hosts (a single API
|
|
1126
|
+
* origin serving many tenants by claim), because there the resolved host tenant and the token
|
|
1127
|
+
* tenant are *meant* to differ.
|
|
1128
|
+
*/
|
|
1129
|
+
enforceTenantBinding?: boolean;
|
|
1103
1130
|
/**
|
|
1104
1131
|
* Granular control over which controllers are registered.
|
|
1105
1132
|
* Allows disabling endpoints that are not needed for a specific application.
|
|
@@ -2144,11 +2171,13 @@ interface IEmailProvider {
|
|
|
2144
2171
|
* The email should contain a time-limited URL with the token embedded as a
|
|
2145
2172
|
* query parameter (e.g. `/reset-password?token=...`).
|
|
2146
2173
|
*
|
|
2174
|
+
* @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
|
|
2175
|
+
* attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
|
|
2147
2176
|
* @param email - Recipient's email address.
|
|
2148
2177
|
* @param token - Signed, opaque reset token. Never log or expose this value.
|
|
2149
2178
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2150
2179
|
*/
|
|
2151
|
-
sendPasswordResetToken(email: string, token: string, locale?: string): Promise<void>;
|
|
2180
|
+
sendPasswordResetToken(tenantId: string, email: string, token: string, locale?: string): Promise<void>;
|
|
2152
2181
|
/**
|
|
2153
2182
|
* Sends a one-time password (OTP) code for password reset to the user.
|
|
2154
2183
|
*
|
|
@@ -2156,11 +2185,13 @@ interface IEmailProvider {
|
|
|
2156
2185
|
* The email should display the numeric/alphanumeric code clearly and state
|
|
2157
2186
|
* its expiry time.
|
|
2158
2187
|
*
|
|
2188
|
+
* @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
|
|
2189
|
+
* attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
|
|
2159
2190
|
* @param email - Recipient's email address.
|
|
2160
2191
|
* @param otp - Short-lived OTP code. Never log or expose this value.
|
|
2161
2192
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2162
2193
|
*/
|
|
2163
|
-
sendPasswordResetOtp(email: string, otp: string, locale?: string): Promise<void>;
|
|
2194
|
+
sendPasswordResetOtp(tenantId: string, email: string, otp: string, locale?: string): Promise<void>;
|
|
2164
2195
|
/**
|
|
2165
2196
|
* Sends an OTP code to verify the user's email address during registration or
|
|
2166
2197
|
* email-change flows.
|
|
@@ -2168,11 +2199,13 @@ interface IEmailProvider {
|
|
|
2168
2199
|
* Called immediately after account creation (when email verification is enabled)
|
|
2169
2200
|
* or when the user requests a new verification code.
|
|
2170
2201
|
*
|
|
2202
|
+
* @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
|
|
2203
|
+
* attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
|
|
2171
2204
|
* @param email - Recipient's email address to be verified.
|
|
2172
2205
|
* @param otp - Short-lived OTP code for verification. Never log or expose this value.
|
|
2173
2206
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2174
2207
|
*/
|
|
2175
|
-
sendEmailVerificationOtp(email: string, otp: string, locale?: string): Promise<void>;
|
|
2208
|
+
sendEmailVerificationOtp(tenantId: string, email: string, otp: string, locale?: string): Promise<void>;
|
|
2176
2209
|
/**
|
|
2177
2210
|
* Notifies the user that the password on their account has changed.
|
|
2178
2211
|
*
|
|
@@ -2188,10 +2221,12 @@ interface IEmailProvider {
|
|
|
2188
2221
|
* it when present and logs at debug when it is not, rather than failing a password change
|
|
2189
2222
|
* over a missing notification.
|
|
2190
2223
|
*
|
|
2224
|
+
* @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
|
|
2225
|
+
* attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
|
|
2191
2226
|
* @param email - Recipient's email address.
|
|
2192
2227
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2193
2228
|
*/
|
|
2194
|
-
sendPasswordChangedNotification?(email: string, locale?: string): Promise<void>;
|
|
2229
|
+
sendPasswordChangedNotification?(tenantId: string, email: string, locale?: string): Promise<void>;
|
|
2195
2230
|
/**
|
|
2196
2231
|
* Sends the address-change verification link to the **new** address.
|
|
2197
2232
|
*
|
|
@@ -2202,11 +2237,13 @@ interface IEmailProvider {
|
|
|
2202
2237
|
* Optional on the interface so an existing consumer keeps compiling, but the flow refuses
|
|
2203
2238
|
* to mint a token when it is absent rather than writing one nobody will ever receive.
|
|
2204
2239
|
*
|
|
2240
|
+
* @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
|
|
2241
|
+
* attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
|
|
2205
2242
|
* @param newEmail - The address being moved to.
|
|
2206
2243
|
* @param token - The raw single-use token. The provider builds the confirmation URL.
|
|
2207
2244
|
* @param locale - Optional locale for the template.
|
|
2208
2245
|
*/
|
|
2209
|
-
sendEmailChangeVerification?(newEmail: string, token: string, locale?: string): Promise<void>;
|
|
2246
|
+
sendEmailChangeVerification?(tenantId: string, newEmail: string, token: string, locale?: string): Promise<void>;
|
|
2210
2247
|
/**
|
|
2211
2248
|
* Notifies the **old** address that the account's address has changed.
|
|
2212
2249
|
*
|
|
@@ -2218,11 +2255,13 @@ interface IEmailProvider {
|
|
|
2218
2255
|
* Fire-and-forget — a delivery failure does not roll back a change the user asked for and
|
|
2219
2256
|
* has already proven.
|
|
2220
2257
|
*
|
|
2258
|
+
* @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
|
|
2259
|
+
* attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
|
|
2221
2260
|
* @param oldEmail - The address the account is leaving.
|
|
2222
2261
|
* @param newEmail - The address it moved to, so the notice can say what happened.
|
|
2223
2262
|
* @param locale - Optional locale for the template.
|
|
2224
2263
|
*/
|
|
2225
|
-
sendEmailChangedNotification?(oldEmail: string, newEmail: string, locale?: string): Promise<void>;
|
|
2264
|
+
sendEmailChangedNotification?(tenantId: string, oldEmail: string, newEmail: string, locale?: string): Promise<void>;
|
|
2226
2265
|
/**
|
|
2227
2266
|
* Notifies the user that multi-factor authentication (MFA) has been enabled on
|
|
2228
2267
|
* their account.
|
|
@@ -2231,10 +2270,12 @@ interface IEmailProvider {
|
|
|
2231
2270
|
* security alert — if the user did not initiate this change, they should be
|
|
2232
2271
|
* directed to contact support or reset their credentials.
|
|
2233
2272
|
*
|
|
2273
|
+
* @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
|
|
2274
|
+
* attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
|
|
2234
2275
|
* @param email - Recipient's email address.
|
|
2235
2276
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2236
2277
|
*/
|
|
2237
|
-
sendMfaEnabledNotification(email: string, locale?: string): Promise<void>;
|
|
2278
|
+
sendMfaEnabledNotification(tenantId: string, email: string, locale?: string): Promise<void>;
|
|
2238
2279
|
/**
|
|
2239
2280
|
* Notifies the user that multi-factor authentication (MFA) has been disabled on
|
|
2240
2281
|
* their account.
|
|
@@ -2243,10 +2284,12 @@ interface IEmailProvider {
|
|
|
2243
2284
|
* alert — if the user did not initiate this change, they should be directed to
|
|
2244
2285
|
* contact support or reset their credentials immediately.
|
|
2245
2286
|
*
|
|
2287
|
+
* @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
|
|
2288
|
+
* attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
|
|
2246
2289
|
* @param email - Recipient's email address.
|
|
2247
2290
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2248
2291
|
*/
|
|
2249
|
-
sendMfaDisabledNotification(email: string, locale?: string): Promise<void>;
|
|
2292
|
+
sendMfaDisabledNotification(tenantId: string, email: string, locale?: string): Promise<void>;
|
|
2250
2293
|
/**
|
|
2251
2294
|
* Sends a security alert about a newly established session.
|
|
2252
2295
|
*
|
|
@@ -2267,11 +2310,13 @@ interface IEmailProvider {
|
|
|
2267
2310
|
* So: decide in your `onNewSession` hook whether the session is worth alerting about, and
|
|
2268
2311
|
* call this when it is.
|
|
2269
2312
|
*
|
|
2313
|
+
* @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
|
|
2314
|
+
* attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
|
|
2270
2315
|
* @param email - Recipient's email address.
|
|
2271
2316
|
* @param sessionInfo - Device, IP, and session identifier details.
|
|
2272
2317
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2273
2318
|
*/
|
|
2274
|
-
sendNewSessionAlert?(email: string, sessionInfo: SessionInfo$1, locale?: string): Promise<void>;
|
|
2319
|
+
sendNewSessionAlert?(tenantId: string, email: string, sessionInfo: SessionInfo$1, locale?: string): Promise<void>;
|
|
2275
2320
|
/**
|
|
2276
2321
|
* Sends a tenant invitation email to a prospective member.
|
|
2277
2322
|
*
|
|
@@ -2279,11 +2324,13 @@ interface IEmailProvider {
|
|
|
2279
2324
|
* The email should prominently display the inviter's name, the tenant name,
|
|
2280
2325
|
* the accept URL, and the expiry date/time.
|
|
2281
2326
|
*
|
|
2327
|
+
* @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
|
|
2328
|
+
* attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
|
|
2282
2329
|
* @param email - Recipient's email address (the invitee).
|
|
2283
2330
|
* @param inviteData - Invitation metadata required to render the email.
|
|
2284
2331
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2285
2332
|
*/
|
|
2286
|
-
sendInvitation(email: string, inviteData: InviteData, locale?: string): Promise<void>;
|
|
2333
|
+
sendInvitation(tenantId: string, email: string, inviteData: InviteData, locale?: string): Promise<void>;
|
|
2287
2334
|
}
|
|
2288
2335
|
|
|
2289
2336
|
/**
|
|
@@ -2965,6 +3012,24 @@ interface MfaTempPayload {
|
|
|
2965
3012
|
type: 'mfa_challenge';
|
|
2966
3013
|
/** Indicates which authentication context triggered the MFA challenge. */
|
|
2967
3014
|
context: 'dashboard' | 'platform';
|
|
3015
|
+
/**
|
|
3016
|
+
* The tenant the dashboard challenge belongs to. Present on the dashboard plane, ABSENT on the
|
|
3017
|
+
* platform plane — platform admins carry no tenant. It is the whole reason the challenge can
|
|
3018
|
+
* resolve the pending account tenant-scoped: without it the second-factor step, the
|
|
3019
|
+
* account-status gate and the finally-minted session all resolved the account by `sub` alone, so
|
|
3020
|
+
* under a host schema whose ids are per-tenant sequential a challenge could decide against, and
|
|
3021
|
+
* mint a session for, a homonym in another tenant.
|
|
3022
|
+
*
|
|
3023
|
+
* NOT optional in effect, despite the `?`: `verifyMfaTempToken` REJECTS a dashboard token that
|
|
3024
|
+
* lacks it and a platform token that carries it. The `?` only expresses that the two planes
|
|
3025
|
+
* populate it differently — it is never a value the caller may omit and have honoured. A missing
|
|
3026
|
+
* claim reads as an invalid token, not as a fall back to the pre-tenant lookup: a fallback would
|
|
3027
|
+
* leave the tenant-blind path reachable to anyone who simply drops the field (RFC 8725 §3.9/§3.12;
|
|
3028
|
+
* ASVS 6.6.2 — the out-of-band token must be bound to the request that originated it). A token
|
|
3029
|
+
* minted before this claim existed is therefore refused, and the user redoes login within the
|
|
3030
|
+
* five-minute TTL; there is no in-flight fallback to drain.
|
|
3031
|
+
*/
|
|
3032
|
+
tenantId?: string;
|
|
2968
3033
|
/**
|
|
2969
3034
|
* The subject's token **epoch** at issuance, in the plane named by `context`.
|
|
2970
3035
|
*
|
|
@@ -3396,19 +3461,211 @@ interface OAuthMfaChallengeResult {
|
|
|
3396
3461
|
declare class NoOpEmailProvider implements IEmailProvider {
|
|
3397
3462
|
private readonly logger;
|
|
3398
3463
|
/** @inheritdoc */
|
|
3399
|
-
sendPasswordResetToken(email: string, _token: string, _locale?: string): Promise<void>;
|
|
3464
|
+
sendPasswordResetToken(_tenantId: string, email: string, _token: string, _locale?: string): Promise<void>;
|
|
3465
|
+
/** @inheritdoc */
|
|
3466
|
+
sendPasswordResetOtp(_tenantId: string, email: string, _otp: string, _locale?: string): Promise<void>;
|
|
3467
|
+
/** @inheritdoc */
|
|
3468
|
+
sendEmailVerificationOtp(_tenantId: string, email: string, _otp: string, _locale?: string): Promise<void>;
|
|
3469
|
+
/** @inheritdoc */
|
|
3470
|
+
sendMfaEnabledNotification(_tenantId: string, email: string, _locale?: string): Promise<void>;
|
|
3471
|
+
/** @inheritdoc */
|
|
3472
|
+
sendMfaDisabledNotification(_tenantId: string, email: string, _locale?: string): Promise<void>;
|
|
3473
|
+
/** @inheritdoc */
|
|
3474
|
+
sendNewSessionAlert(_tenantId: string, email: string, _sessionInfo: SessionInfo$1, _locale?: string): Promise<void>;
|
|
3475
|
+
/** @inheritdoc */
|
|
3476
|
+
sendInvitation(_tenantId: string, email: string, _inviteData: InviteData, _locale?: string): Promise<void>;
|
|
3477
|
+
}
|
|
3478
|
+
|
|
3479
|
+
/**
|
|
3480
|
+
* The delivery channel {@link DefaultAuthEmailProvider} sends through.
|
|
3481
|
+
*
|
|
3482
|
+
* Narrow by design: it names only the one call the provider makes, so the provider couples to no
|
|
3483
|
+
* concrete mailer. `@bymax-one/nest-notification`'s `EmailService.send` satisfies it structurally
|
|
3484
|
+
* — its input carries these fields and more, all the extras optional — and so does any adapter
|
|
3485
|
+
* exposing the same shape.
|
|
3486
|
+
*/
|
|
3487
|
+
interface AuthEmailSink {
|
|
3488
|
+
/**
|
|
3489
|
+
* Delivers one rendered message.
|
|
3490
|
+
*
|
|
3491
|
+
* @param input - Tenant, recipient, and the rendered subject and bodies.
|
|
3492
|
+
* @returns Anything; the provider ignores the result and never surfaces a rejection.
|
|
3493
|
+
*/
|
|
3494
|
+
send(input: {
|
|
3495
|
+
/** Tenant the message is attributed to, for the channel's audit log and routing. */
|
|
3496
|
+
tenantId: string;
|
|
3497
|
+
/** Recipient address. */
|
|
3498
|
+
to: string;
|
|
3499
|
+
/** Subject line. */
|
|
3500
|
+
subject: string;
|
|
3501
|
+
/** HTML body. */
|
|
3502
|
+
html: string;
|
|
3503
|
+
/** Plain-text body. */
|
|
3504
|
+
text: string;
|
|
3505
|
+
}): Promise<unknown>;
|
|
3506
|
+
}
|
|
3507
|
+
/** One rendered message, before the tenant and recipient are attached to it. */
|
|
3508
|
+
interface AuthEmailMessage {
|
|
3509
|
+
/** Subject line. Plain text — never rendered as HTML, so it needs no escaping. */
|
|
3510
|
+
readonly subject: string;
|
|
3511
|
+
/** Body as plain text. Rendered to minimal, escaped HTML by the provider when `html` is absent. */
|
|
3512
|
+
readonly text: string;
|
|
3513
|
+
/**
|
|
3514
|
+
* Body as HTML, used verbatim when present. The provider does not escape it — an override that
|
|
3515
|
+
* sets this owns its own escaping, which is the point: it is the seam for a product's real
|
|
3516
|
+
* `<a>` links, layout and branding, none of which the escaped-text default can carry. Leave it
|
|
3517
|
+
* unset to have the provider render {@link text} into safe, escaped paragraphs.
|
|
3518
|
+
*/
|
|
3519
|
+
readonly html?: string | undefined;
|
|
3520
|
+
}
|
|
3521
|
+
/**
|
|
3522
|
+
* The copy for every message the port can send, as pure renderers keyed by event.
|
|
3523
|
+
*
|
|
3524
|
+
* Each returns an {@link AuthEmailMessage}; the provider attaches the tenant and recipient and
|
|
3525
|
+
* handles escaping and delivery. Override any subset through
|
|
3526
|
+
* {@link DefaultAuthEmailProviderOptions.messages} — an entry left unset keeps the secure default.
|
|
3527
|
+
*/
|
|
3528
|
+
interface AuthEmailCatalogue {
|
|
3529
|
+
/** Password-reset link carrying a signed token. */
|
|
3530
|
+
passwordResetToken(input: {
|
|
3531
|
+
token: string;
|
|
3532
|
+
locale?: string | undefined;
|
|
3533
|
+
}): AuthEmailMessage;
|
|
3534
|
+
/** One-time code for the password-reset flow. */
|
|
3535
|
+
passwordResetOtp(input: {
|
|
3536
|
+
otp: string;
|
|
3537
|
+
locale?: string | undefined;
|
|
3538
|
+
}): AuthEmailMessage;
|
|
3539
|
+
/** One-time code that activates a newly registered account. */
|
|
3540
|
+
emailVerificationOtp(input: {
|
|
3541
|
+
otp: string;
|
|
3542
|
+
locale?: string | undefined;
|
|
3543
|
+
}): AuthEmailMessage;
|
|
3544
|
+
/** Notice that the account password changed (NIST SP 800-63B §4.6). */
|
|
3545
|
+
passwordChanged(input: {
|
|
3546
|
+
locale?: string | undefined;
|
|
3547
|
+
}): AuthEmailMessage;
|
|
3548
|
+
/** Code confirming ownership of an address the user is moving to. */
|
|
3549
|
+
emailChangeVerification(input: {
|
|
3550
|
+
token: string;
|
|
3551
|
+
locale?: string | undefined;
|
|
3552
|
+
}): AuthEmailMessage;
|
|
3553
|
+
/** Notice to the previous address that the account's email moved. */
|
|
3554
|
+
emailChanged(input: {
|
|
3555
|
+
oldEmail: string;
|
|
3556
|
+
newEmail: string;
|
|
3557
|
+
locale?: string | undefined;
|
|
3558
|
+
}): AuthEmailMessage;
|
|
3559
|
+
/** Notice that a second factor was added. */
|
|
3560
|
+
mfaEnabled(input: {
|
|
3561
|
+
locale?: string | undefined;
|
|
3562
|
+
}): AuthEmailMessage;
|
|
3563
|
+
/** Notice that a second factor was removed. */
|
|
3564
|
+
mfaDisabled(input: {
|
|
3565
|
+
locale?: string | undefined;
|
|
3566
|
+
}): AuthEmailMessage;
|
|
3567
|
+
/** Security alert about a newly established session. */
|
|
3568
|
+
newSessionAlert(input: {
|
|
3569
|
+
sessionInfo: SessionInfo$1;
|
|
3570
|
+
locale?: string | undefined;
|
|
3571
|
+
}): AuthEmailMessage;
|
|
3572
|
+
/** Invitation to join a tenant. */
|
|
3573
|
+
invitation(input: {
|
|
3574
|
+
invite: InviteData;
|
|
3575
|
+
locale?: string | undefined;
|
|
3576
|
+
}): AuthEmailMessage;
|
|
3577
|
+
}
|
|
3578
|
+
/** How the provider reacts to a delivery failure. */
|
|
3579
|
+
type DeliveryErrorPolicy = 'swallow' | 'rethrow';
|
|
3580
|
+
/** Options for {@link DefaultAuthEmailProvider}. */
|
|
3581
|
+
interface DefaultAuthEmailProviderOptions {
|
|
3582
|
+
/**
|
|
3583
|
+
* Per-event copy overrides. Any renderer set here replaces the default for that message; every
|
|
3584
|
+
* unset event keeps its secure default. The escaping and delivery-error policy apply to
|
|
3585
|
+
* overrides too.
|
|
3586
|
+
*/
|
|
3587
|
+
readonly messages?: Partial<AuthEmailCatalogue>;
|
|
3588
|
+
/**
|
|
3589
|
+
* What to do when the channel rejects a send. `'swallow'` (the default) logs the failure and
|
|
3590
|
+
* resolves, so a down channel never turns a notification into a failed user request. `'rethrow'`
|
|
3591
|
+
* logs and then re-throws, restoring the throw the two flows that react to one expect —
|
|
3592
|
+
* `PasswordResetService` deletes an undelivered reset token early, and `EmailChangeService` lets
|
|
3593
|
+
* a failed verification send surface rather than reporting "sent". The trade is symmetric: under
|
|
3594
|
+
* `'rethrow'` a channel outage also fails MFA, invitation and the other awaited sends. Pick the
|
|
3595
|
+
* failure mode the deployment's channel reliability warrants.
|
|
3596
|
+
*/
|
|
3597
|
+
readonly onDeliveryError?: DeliveryErrorPolicy;
|
|
3598
|
+
}
|
|
3599
|
+
/**
|
|
3600
|
+
* Default {@link IEmailProvider} over a {@link AuthEmailSink} delivery channel.
|
|
3601
|
+
*
|
|
3602
|
+
* Wire it by binding the auth email-provider token to a factory that hands it the channel:
|
|
3603
|
+
*
|
|
3604
|
+
* ```typescript
|
|
3605
|
+
* {
|
|
3606
|
+
* provide: BYMAX_AUTH_EMAIL_PROVIDER,
|
|
3607
|
+
* useFactory: (email: EmailService) => new DefaultAuthEmailProvider(email),
|
|
3608
|
+
* inject: [EmailService]
|
|
3609
|
+
* }
|
|
3610
|
+
* ```
|
|
3611
|
+
*
|
|
3612
|
+
* No method throws on a delivery failure — the library awaits most of these calls (enabling MFA,
|
|
3613
|
+
* sending an invitation, confirming an address change), so a channel that is down would turn each
|
|
3614
|
+
* into a failed request over a message that is a notification rather than the operation itself.
|
|
3615
|
+
* The failure is logged and the flow continues.
|
|
3616
|
+
*
|
|
3617
|
+
* That choice has a cost worth stating, because two flows react to a *throw* from the port. A
|
|
3618
|
+
* reset-token send that rejects lets `PasswordResetService` delete the stored token early rather
|
|
3619
|
+
* than leave it to its TTL; and `EmailChangeService` awaits the verification send before it records
|
|
3620
|
+
* "verification sent". Under the default both degrade gracefully rather than break: the reset token
|
|
3621
|
+
* still expires at its TTL and was never delivered to anyone, and the change still requires the
|
|
3622
|
+
* verification the recipient never got, so it cannot complete. A deployment that wants the throw
|
|
3623
|
+
* back on those flows constructs the provider with `{ onDeliveryError: 'rethrow' }`, accepting that
|
|
3624
|
+
* an outage then also fails the awaited sends (MFA, invitation). The default optimizes for the
|
|
3625
|
+
* common case: a transient channel outage must not fail the user's action.
|
|
3626
|
+
*/
|
|
3627
|
+
declare class DefaultAuthEmailProvider implements IEmailProvider {
|
|
3628
|
+
private readonly sink;
|
|
3629
|
+
/** Records a delivery this provider swallowed, so a silent channel is still visible somewhere. */
|
|
3630
|
+
private readonly logger;
|
|
3631
|
+
/** The copy in effect: the defaults, with any provided overrides layered on top. */
|
|
3632
|
+
private readonly messages;
|
|
3633
|
+
/** Whether a rejected send is re-thrown after logging; `false` (swallow) unless asked otherwise. */
|
|
3634
|
+
private readonly rethrowOnError;
|
|
3635
|
+
/**
|
|
3636
|
+
* @param sink - The delivery channel to send through.
|
|
3637
|
+
* @param options - Optional copy overrides and delivery-error policy.
|
|
3638
|
+
*/
|
|
3639
|
+
constructor(sink: AuthEmailSink, options?: DefaultAuthEmailProviderOptions);
|
|
3640
|
+
/** @inheritdoc */
|
|
3641
|
+
sendPasswordResetToken(tenantId: string, email: string, token: string, locale?: string): Promise<void>;
|
|
3642
|
+
/** @inheritdoc */
|
|
3643
|
+
sendPasswordResetOtp(tenantId: string, email: string, otp: string, locale?: string): Promise<void>;
|
|
3644
|
+
/** @inheritdoc */
|
|
3645
|
+
sendEmailVerificationOtp(tenantId: string, email: string, otp: string, locale?: string): Promise<void>;
|
|
3400
3646
|
/** @inheritdoc */
|
|
3401
|
-
|
|
3647
|
+
sendPasswordChangedNotification(tenantId: string, email: string, locale?: string): Promise<void>;
|
|
3402
3648
|
/** @inheritdoc */
|
|
3403
|
-
|
|
3649
|
+
sendEmailChangeVerification(tenantId: string, newEmail: string, token: string, locale?: string): Promise<void>;
|
|
3404
3650
|
/** @inheritdoc */
|
|
3405
|
-
|
|
3651
|
+
sendEmailChangedNotification(tenantId: string, oldEmail: string, newEmail: string, locale?: string): Promise<void>;
|
|
3406
3652
|
/** @inheritdoc */
|
|
3407
|
-
|
|
3653
|
+
sendMfaEnabledNotification(tenantId: string, email: string, locale?: string): Promise<void>;
|
|
3408
3654
|
/** @inheritdoc */
|
|
3409
|
-
|
|
3655
|
+
sendMfaDisabledNotification(tenantId: string, email: string, locale?: string): Promise<void>;
|
|
3410
3656
|
/** @inheritdoc */
|
|
3411
|
-
|
|
3657
|
+
sendNewSessionAlert(tenantId: string, email: string, sessionInfo: SessionInfo$1, locale?: string): Promise<void>;
|
|
3658
|
+
/** @inheritdoc */
|
|
3659
|
+
sendInvitation(tenantId: string, email: string, inviteData: InviteData, locale?: string): Promise<void>;
|
|
3660
|
+
/**
|
|
3661
|
+
* Renders the body to HTML (unless the message already carries its own), hands the message to the
|
|
3662
|
+
* channel, and swallows any delivery error.
|
|
3663
|
+
*
|
|
3664
|
+
* @param tenantId - Tenant the message is attributed to.
|
|
3665
|
+
* @param to - Recipient address.
|
|
3666
|
+
* @param message - The rendered subject and body, and optionally its own HTML.
|
|
3667
|
+
*/
|
|
3668
|
+
private deliver;
|
|
3412
3669
|
}
|
|
3413
3670
|
|
|
3414
3671
|
/**
|
|
@@ -4096,6 +4353,55 @@ declare class AuthRedisService {
|
|
|
4096
4353
|
redeemWsTicket(ticket: string): Promise<WsTicketSnapshot | null>;
|
|
4097
4354
|
}
|
|
4098
4355
|
|
|
4356
|
+
/**
|
|
4357
|
+
* The claims a revocation check reads off a verified access token. A caller passes the payload it
|
|
4358
|
+
* already verified; nothing here re-checks the signature.
|
|
4359
|
+
*/
|
|
4360
|
+
interface RevocableTokenPayload {
|
|
4361
|
+
/** The token's unique id, the key of the per-token blacklist (`rv:{jti}`). */
|
|
4362
|
+
readonly jti: string;
|
|
4363
|
+
/** The subject the token authenticates, the key of the per-user token epoch. */
|
|
4364
|
+
readonly sub: string;
|
|
4365
|
+
/** The epoch the token was stamped with, if any; an absent or malformed value reads as 0. */
|
|
4366
|
+
readonly epoch?: unknown;
|
|
4367
|
+
}
|
|
4368
|
+
/**
|
|
4369
|
+
* Answers whether an already-verified access token has been revoked, across both channels the auth
|
|
4370
|
+
* module writes to.
|
|
4371
|
+
*
|
|
4372
|
+
* There are two, and a check that consults only the first is not a revocation check. A single
|
|
4373
|
+
* logout writes `rv:{jti}` with the token's remaining TTL — the per-token blacklist. A password
|
|
4374
|
+
* reset, an MFA reset or an administrative revoke-all advances the user's token epoch — the bulk
|
|
4375
|
+
* channel, which invalidates every access token stamped below it in one write. Both channels this
|
|
4376
|
+
* service reads gate access tokens only; a refresh token is opaque and carries no epoch, so a bulk
|
|
4377
|
+
* flow revokes it through a separate session invalidation, not through either read here.
|
|
4378
|
+
*
|
|
4379
|
+
* `JwtAuthGuard`, `WsJwtGuard` and `JwtPlatformGuard` all consult both, and did so through three
|
|
4380
|
+
* separate copies of the same two Redis reads. This is that logic in one place — the guards
|
|
4381
|
+
* delegate to it, and it is exported so a consumer bridging `@bymax-one/nest-auth` to a realtime
|
|
4382
|
+
* transport can consult the same two channels rather than verifying a token's signature and
|
|
4383
|
+
* granting a stream that outlives every revocation. Without it, a socket that logs out keeps its
|
|
4384
|
+
* stream until the access token expires, while its HTTP requests are refused at once.
|
|
4385
|
+
*
|
|
4386
|
+
* @layer Service
|
|
4387
|
+
*/
|
|
4388
|
+
declare class AuthRevocationService {
|
|
4389
|
+
private readonly redis;
|
|
4390
|
+
/**
|
|
4391
|
+
* @param redis - The auth module's Redis service, holding both revocation channels.
|
|
4392
|
+
*/
|
|
4393
|
+
constructor(redis: AuthRedisService);
|
|
4394
|
+
/**
|
|
4395
|
+
* Whether a verified access token has been revoked.
|
|
4396
|
+
*
|
|
4397
|
+
* @param payload - The verified token's `jti`, `sub` and stamped `epoch`.
|
|
4398
|
+
* @param kind - Which plane the token belongs to; selects the epoch namespace, defaulting to the
|
|
4399
|
+
* dashboard plane an ordinary user token uses. The per-token blacklist is shared across planes.
|
|
4400
|
+
* @returns `true` when the token is on the blacklist or predates the user's current epoch.
|
|
4401
|
+
*/
|
|
4402
|
+
isAccessTokenRevoked(payload: RevocableTokenPayload, kind?: 'dashboard' | 'platform'): Promise<boolean>;
|
|
4403
|
+
}
|
|
4404
|
+
|
|
4099
4405
|
/**
|
|
4100
4406
|
* Auth response for cookie mode — tokens delivered via HttpOnly cookies.
|
|
4101
4407
|
* The response body contains only the user object.
|
|
@@ -4304,10 +4610,10 @@ declare class TokenDeliveryService {
|
|
|
4304
4610
|
declare class JwtAuthGuard implements CanActivate {
|
|
4305
4611
|
protected readonly jwtService: JwtService;
|
|
4306
4612
|
protected readonly tokenDelivery: TokenDeliveryService;
|
|
4307
|
-
protected readonly
|
|
4613
|
+
protected readonly revocation: AuthRevocationService;
|
|
4308
4614
|
protected readonly reflector: Reflector;
|
|
4309
4615
|
protected readonly options: ResolvedOptions;
|
|
4310
|
-
constructor(jwtService: JwtService, tokenDelivery: TokenDeliveryService,
|
|
4616
|
+
constructor(jwtService: JwtService, tokenDelivery: TokenDeliveryService, revocation: AuthRevocationService, reflector: Reflector, options: ResolvedOptions);
|
|
4311
4617
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
4312
4618
|
}
|
|
4313
4619
|
|
|
@@ -4342,10 +4648,10 @@ declare class JwtAuthGuard implements CanActivate {
|
|
|
4342
4648
|
declare class JwtPlatformGuard implements CanActivate {
|
|
4343
4649
|
private readonly jwtService;
|
|
4344
4650
|
private readonly tokenDelivery;
|
|
4345
|
-
private readonly
|
|
4651
|
+
private readonly revocation;
|
|
4346
4652
|
private readonly reflector;
|
|
4347
4653
|
private readonly options;
|
|
4348
|
-
constructor(jwtService: JwtService, tokenDelivery: TokenDeliveryService,
|
|
4654
|
+
constructor(jwtService: JwtService, tokenDelivery: TokenDeliveryService, revocation: AuthRevocationService, reflector: Reflector, options: ResolvedOptions);
|
|
4349
4655
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
4350
4656
|
}
|
|
4351
4657
|
|
|
@@ -4649,9 +4955,10 @@ declare class TrustedOriginGuard implements CanActivate {
|
|
|
4649
4955
|
* Verifies that the authenticated user's account status is not blocked.
|
|
4650
4956
|
*
|
|
4651
4957
|
* On each request, the user's current status is resolved from a Redis cache
|
|
4652
|
-
* (`us:{userId}`) to avoid a database round-trip on every request. A cache
|
|
4653
|
-
* triggers a repository lookup, and the result is cached for
|
|
4654
|
-
* `userStatusCacheTtlSeconds` (default: 60 s).
|
|
4958
|
+
* (`us:{tenantId}:{userId}`) to avoid a database round-trip on every request. A cache
|
|
4959
|
+
* miss triggers a tenant-scoped repository lookup, and the result is cached for
|
|
4960
|
+
* `userStatusCacheTtlSeconds` (default: 60 s). The tenant is part of the key because a
|
|
4961
|
+
* repository id is unique only within a tenant.
|
|
4655
4962
|
*
|
|
4656
4963
|
* Status-specific errors allow the client to display the correct message:
|
|
4657
4964
|
* - `BANNED` → `ACCOUNT_BANNED` (403)
|
|
@@ -4659,6 +4966,15 @@ declare class TrustedOriginGuard implements CanActivate {
|
|
|
4659
4966
|
* - `SUSPENDED` → `ACCOUNT_SUSPENDED` (403)
|
|
4660
4967
|
* - `PENDING` → `PENDING_APPROVAL` (403)
|
|
4661
4968
|
*
|
|
4969
|
+
* When `emailVerification.required` is enabled (the default), this guard also
|
|
4970
|
+
* refuses an account whose email is not yet verified, with `EMAIL_NOT_VERIFIED`.
|
|
4971
|
+
* This is what makes verification a gate on API access and not only on `login`:
|
|
4972
|
+
* registration issues a session before verification, and without this check that
|
|
4973
|
+
* session would reach every route this guard protects for the access token's
|
|
4974
|
+
* lifetime. The verified flag is cached alongside the status under
|
|
4975
|
+
* `uev:{tenantId}:{userId}`, on the same miss and the same TTL, so the check costs no
|
|
4976
|
+
* extra round-trip.
|
|
4977
|
+
*
|
|
4662
4978
|
* Routes without an authenticated user (`request.user` absent) are passed
|
|
4663
4979
|
* through — this guard is designed to be composed after {@link JwtAuthGuard}.
|
|
4664
4980
|
*
|
|
@@ -4779,10 +5095,10 @@ declare class WsTicketService {
|
|
|
4779
5095
|
*/
|
|
4780
5096
|
declare class WsJwtGuard implements CanActivate, OnModuleInit {
|
|
4781
5097
|
private readonly jwtService;
|
|
4782
|
-
private readonly
|
|
5098
|
+
private readonly revocation;
|
|
4783
5099
|
private readonly wsTickets;
|
|
4784
5100
|
private readonly options;
|
|
4785
|
-
constructor(jwtService: JwtService,
|
|
5101
|
+
constructor(jwtService: JwtService, revocation: AuthRevocationService, wsTickets: WsTicketService, options: ResolvedOptions);
|
|
4786
5102
|
/**
|
|
4787
5103
|
* Verifies that `@nestjs/websockets` is installed and throws a descriptive
|
|
4788
5104
|
* error at application startup if the package is absent.
|
|
@@ -5684,7 +6000,24 @@ declare class BruteForceService {
|
|
|
5684
6000
|
*/
|
|
5685
6001
|
declare class OtpService {
|
|
5686
6002
|
private readonly redis;
|
|
5687
|
-
|
|
6003
|
+
private readonly options;
|
|
6004
|
+
constructor(redis: AuthRedisService, options: ResolvedOptions);
|
|
6005
|
+
/**
|
|
6006
|
+
* Keyed one-way transform of an OTP under which it is stored and compared.
|
|
6007
|
+
*
|
|
6008
|
+
* The record is never the code itself: a six-digit code is a keyspace of a million, which a
|
|
6009
|
+
* plain digest lets anyone who reads Redis reverse instantly, so the transform is HMAC-SHA256
|
|
6010
|
+
* under the library's server-only `hmacKey` — the same key that already conceals the identifier.
|
|
6011
|
+
* It is bound to the identifier so the same code under two accounts does not collapse to one
|
|
6012
|
+
* value. `store` and `verify` compute it the same way; the byte-identical verify script keeps
|
|
6013
|
+
* comparing two opaque strings, so the rust-auth side stays in step by transforming the code the
|
|
6014
|
+
* same way before it reads or writes the shared record.
|
|
6015
|
+
*
|
|
6016
|
+
* @param identifier - The user-scoped identifier the record is keyed by.
|
|
6017
|
+
* @param code - The plaintext OTP.
|
|
6018
|
+
* @returns The hex HMAC written to, and compared against, the record.
|
|
6019
|
+
*/
|
|
6020
|
+
private fingerprint;
|
|
5688
6021
|
/**
|
|
5689
6022
|
* Generates a cryptographically secure numeric OTP string.
|
|
5690
6023
|
*
|
|
@@ -6478,9 +6811,12 @@ declare class TokenManagerService {
|
|
|
6478
6811
|
*
|
|
6479
6812
|
* @param userId - The user (or admin) pending MFA completion.
|
|
6480
6813
|
* @param context - Authentication context: `'dashboard'` or `'platform'`.
|
|
6814
|
+
* @param tenantId - The tenant the account belongs to, on the dashboard plane only. Stamped
|
|
6815
|
+
* into the token so the challenge resolves the account tenant-scoped rather than by `sub`
|
|
6816
|
+
* alone. Omitted on the platform plane, which has no tenant.
|
|
6481
6817
|
* @returns The signed MFA temp JWT.
|
|
6482
6818
|
*/
|
|
6483
|
-
issueMfaTempToken(userId: string, context: 'dashboard' | 'platform'): Promise<string>;
|
|
6819
|
+
issueMfaTempToken(userId: string, context: 'dashboard' | 'platform', tenantId?: string): Promise<string>;
|
|
6484
6820
|
/**
|
|
6485
6821
|
* Verifies a MFA temp token WITHOUT consuming it.
|
|
6486
6822
|
*
|
|
@@ -6518,6 +6854,7 @@ declare class TokenManagerService {
|
|
|
6518
6854
|
userId: string;
|
|
6519
6855
|
context: 'dashboard' | 'platform';
|
|
6520
6856
|
jti: string;
|
|
6857
|
+
tenantId?: string;
|
|
6521
6858
|
}>;
|
|
6522
6859
|
/**
|
|
6523
6860
|
* Atomically consumes a previously-verified MFA temp token.
|
|
@@ -7095,6 +7432,7 @@ declare class MfaService {
|
|
|
7095
7432
|
* @param context - Which identity plane the account belongs to.
|
|
7096
7433
|
* @param secretBase32 - The decrypted secret.
|
|
7097
7434
|
* @param recoveryCodes - The stored recovery digests, written back unchanged.
|
|
7435
|
+
* @param tenantId - The tenant the account belongs to, so the write is scoped like the read.
|
|
7098
7436
|
*/
|
|
7099
7437
|
private reencryptSecret;
|
|
7100
7438
|
/**
|
|
@@ -7285,7 +7623,7 @@ declare class MfaService {
|
|
|
7285
7623
|
* reused (rather than introducing a new one) because the consumer-facing
|
|
7286
7624
|
* meaning is the same: "platform MFA cannot operate".
|
|
7287
7625
|
*/
|
|
7288
|
-
setup(userId: string, context?: 'dashboard' | 'platform', password?: string): Promise<MfaSetupResult>;
|
|
7626
|
+
setup(userId: string, context?: 'dashboard' | 'platform', password?: string, tenantId?: string): Promise<MfaSetupResult>;
|
|
7289
7627
|
/**
|
|
7290
7628
|
* Verifies the first TOTP code from the user's authenticator app and permanently
|
|
7291
7629
|
* enables MFA on the account.
|
|
@@ -7306,7 +7644,7 @@ declare class MfaService {
|
|
|
7306
7644
|
* @throws `MFA_NOT_ENABLED` if `context === 'platform'` and the platform user
|
|
7307
7645
|
* repository was not configured at module registration.
|
|
7308
7646
|
*/
|
|
7309
|
-
verifyAndEnable(userId: string, code: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform'): Promise<void>;
|
|
7647
|
+
verifyAndEnable(userId: string, code: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform', tenantId?: string): Promise<void>;
|
|
7310
7648
|
/**
|
|
7311
7649
|
* Validates a TOTP or recovery code and exchanges the MFA temp token for full
|
|
7312
7650
|
* access tokens.
|
|
@@ -7349,7 +7687,7 @@ declare class MfaService {
|
|
|
7349
7687
|
* @throws `ACCOUNT_LOCKED` if the brute-force threshold has been reached.
|
|
7350
7688
|
* @throws `MFA_INVALID_CODE` if the submitted TOTP code is incorrect.
|
|
7351
7689
|
*/
|
|
7352
|
-
disable(userId: string, code: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform'): Promise<void>;
|
|
7690
|
+
disable(userId: string, code: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform', tenantId?: string): Promise<void>;
|
|
7353
7691
|
/**
|
|
7354
7692
|
* Removes a user's second factor without their TOTP code, for a support desk facing a user
|
|
7355
7693
|
* who has lost their authenticator AND their recovery codes.
|
|
@@ -7388,7 +7726,7 @@ declare class MfaService {
|
|
|
7388
7726
|
* `'platform'`. Must match the plane the account lives in, or the lookup misses.
|
|
7389
7727
|
* @throws `TOKEN_INVALID` if no user with that ID exists in the given plane.
|
|
7390
7728
|
*/
|
|
7391
|
-
resetMfa(userId: string, context?: 'dashboard' | 'platform'): Promise<void>;
|
|
7729
|
+
resetMfa(userId: string, context?: 'dashboard' | 'platform', tenantId?: string): Promise<void>;
|
|
7392
7730
|
/**
|
|
7393
7731
|
* Regenerates the user's MFA recovery codes after verifying a current TOTP code.
|
|
7394
7732
|
*
|
|
@@ -7426,7 +7764,7 @@ declare class MfaService {
|
|
|
7426
7764
|
* @throws `MFA_INVALID_CODE` if the submitted TOTP code is incorrect.
|
|
7427
7765
|
* @returns The freshly generated plain-text recovery codes, one-time display.
|
|
7428
7766
|
*/
|
|
7429
|
-
regenerateRecoveryCodes(userId: string, totpCode: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform'): Promise<{
|
|
7767
|
+
regenerateRecoveryCodes(userId: string, totpCode: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform', tenantId?: string): Promise<{
|
|
7430
7768
|
recoveryCodes: string[];
|
|
7431
7769
|
}>;
|
|
7432
7770
|
/**
|
|
@@ -7491,6 +7829,53 @@ declare class MfaService {
|
|
|
7491
7829
|
* @throws `TOKEN_INVALID` if the user is not found.
|
|
7492
7830
|
* @throws {@link AuthException} the status error when the account is blocked.
|
|
7493
7831
|
*/
|
|
7832
|
+
/**
|
|
7833
|
+
* A dashboard MFA flow MUST carry the tenant it was authenticated in; a platform flow MUST NOT.
|
|
7834
|
+
*
|
|
7835
|
+
* The controller sources the tenant from the verified JWT, which always carries a validated
|
|
7836
|
+
* `tenantId`, so this never trips through the HTTP surface. It guards the OTHER caller:
|
|
7837
|
+
* `MfaService` is a public API, and a host wiring it directly — or a future SSO path — could hand
|
|
7838
|
+
* a dashboard `userId` with no tenant, which would silently reach the tenant-blind account read
|
|
7839
|
+
* and key derivation. Refuse it here, naming the field, rather than let it degrade to the
|
|
7840
|
+
* pre-tenant behaviour, which is exactly the fallback an attacker would aim for.
|
|
7841
|
+
*
|
|
7842
|
+
* @param context - The identity plane the call is on.
|
|
7843
|
+
* @param tenantId - The tenant supplied by the caller, if any.
|
|
7844
|
+
* @throws {@link AuthException} `VALIDATION` (400) when a dashboard call omits the tenant, or a
|
|
7845
|
+
* platform call supplies one.
|
|
7846
|
+
*/
|
|
7847
|
+
private assertPlaneTenant;
|
|
7848
|
+
/**
|
|
7849
|
+
* The tenant-scoped brute-force identifier for one MFA flow, and the legacy plane-only one it
|
|
7850
|
+
* replaces — equal on the platform plane, where the subject never carried a tenant, and distinct
|
|
7851
|
+
* on the dashboard plane, where it now does.
|
|
7852
|
+
*
|
|
7853
|
+
* A rolling upgrade runs old and new code against one Redis at once: on the dashboard plane an
|
|
7854
|
+
* old pod counts a failure under `{flow}:{plane}:{userId}` while a new pod counts it under
|
|
7855
|
+
* `{flow}:{mfaSubject}`, and either alone leaves a hole — a lockout an old pod filled would not
|
|
7856
|
+
* stop a new pod, and a success on one would not clear the other. For one release every read
|
|
7857
|
+
* consults both and every write touches both, so the two move as one; a later release drops the
|
|
7858
|
+
* legacy arm. On the platform plane the two ids are identical (no tenant ever entered the
|
|
7859
|
+
* subject), so the legacy arm is skipped — operating it would just be the same key a second time,
|
|
7860
|
+
* double-counting a failure and locking a platform admin out at half the threshold. `{flow}`
|
|
7861
|
+
* (`challenge` / `disable` / `reauth`) keeps the three counters isolated, exactly as before.
|
|
7862
|
+
*/
|
|
7863
|
+
private mfaFlowCounterIds;
|
|
7864
|
+
/**
|
|
7865
|
+
* Locked out when EITHER the legacy or the tenant-scoped counter has reached the threshold, so
|
|
7866
|
+
* neither a lockout an old pod recorded nor one a new pod recorded can be bypassed mid-migration.
|
|
7867
|
+
*/
|
|
7868
|
+
private isMfaFlowLockedOut;
|
|
7869
|
+
/**
|
|
7870
|
+
* Records the failure under both counters so the budget an attacker spends is seen by old and
|
|
7871
|
+
* new code alike — but under the scoped id ONCE when the two coincide (platform plane).
|
|
7872
|
+
*/
|
|
7873
|
+
private recordMfaFlowFailure;
|
|
7874
|
+
/**
|
|
7875
|
+
* Clears both counters on success — resetting only one would leave the other to lock a
|
|
7876
|
+
* legitimately authenticated user out on the next attempt — collapsing to one when they coincide.
|
|
7877
|
+
*/
|
|
7878
|
+
private resetMfaFlowFailures;
|
|
7494
7879
|
private fetchUserForContext;
|
|
7495
7880
|
}
|
|
7496
7881
|
|
|
@@ -8329,4 +8714,4 @@ declare function AuthRateLimit(config: {
|
|
|
8329
8714
|
default: AuthRateLimitWindow;
|
|
8330
8715
|
}): MethodDecorator;
|
|
8331
8716
|
|
|
8332
|
-
export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, AllowAllBreachChecker, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthModuleAsyncOptions, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BearerAuthResponse, type BeforeRegisterResult, type BothAuthResponse, BruteForceService, BymaxAuthModule, type BymaxAuthModuleOptions, type BymaxAuthRateLimitOptions, ChangePasswordDto, type ClientIpSource, CommonPasswordChecker, type CookieAuthResponse, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, PlatformAuthService, type PlatformAuthenticatedRequest, type PlatformBearerAuthResponse, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsJwtGuard, WsTicketService, type WsTicketSnapshot, createAuthValidationPipe, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
|
|
8717
|
+
export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, AllowAllBreachChecker, type AuthEmailCatalogue, type AuthEmailMessage, type AuthEmailSink, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthModuleAsyncOptions, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthRevocationService, AuthService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BearerAuthResponse, type BeforeRegisterResult, type BothAuthResponse, BruteForceService, BymaxAuthModule, type BymaxAuthModuleOptions, type BymaxAuthRateLimitOptions, ChangePasswordDto, type ClientIpSource, CommonPasswordChecker, type CookieAuthResponse, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, DefaultAuthEmailProvider, type DefaultAuthEmailProviderOptions, type DeliveryErrorPolicy, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, PlatformAuthService, type PlatformAuthenticatedRequest, type PlatformBearerAuthResponse, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, type RevocableTokenPayload, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsJwtGuard, WsTicketService, type WsTicketSnapshot, createAuthValidationPipe, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
|