authhero 9.28.3 → 9.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/assets/u/widget/index.esm.js +1 -1
  2. package/dist/authhero.cjs +166 -405
  3. package/dist/authhero.d.ts +351 -296
  4. package/dist/authhero.mjs +28767 -55112
  5. package/dist/mfa-attempts-CQiD6hxP.mjs +26774 -0
  6. package/dist/mfa-attempts-DwATCXqC.js +254 -0
  7. package/dist/passkey-enrollment-D_WVyvv2.js +1 -0
  8. package/dist/tsconfig.types.tsbuildinfo +1 -1
  9. package/dist/types/authentication-flows/common.d.ts +4 -0
  10. package/dist/types/authentication-flows/mfa-attempts.d.ts +45 -0
  11. package/dist/types/authentication-flows/mfa.d.ts +20 -5
  12. package/dist/types/authentication-flows/passwordless.d.ts +4 -4
  13. package/dist/types/generated/locale-types.d.ts +6 -0
  14. package/dist/types/helpers/client.d.ts +2 -0
  15. package/dist/types/helpers/reserved-claims.d.ts +2 -2
  16. package/dist/types/helpers/session-mfa.d.ts +29 -0
  17. package/dist/types/hooks/post-user-login.d.ts +13 -0
  18. package/dist/types/index.d.ts +324 -296
  19. package/dist/types/routes/auth-api/index.d.ts +32 -32
  20. package/dist/types/routes/auth-api/passwordless.d.ts +16 -16
  21. package/dist/types/routes/auth-api/revoke.d.ts +6 -6
  22. package/dist/types/routes/auth-api/token.d.ts +10 -10
  23. package/dist/types/routes/management-api/action-executions.d.ts +1 -1
  24. package/dist/types/routes/management-api/actions.d.ts +1 -1
  25. package/dist/types/routes/management-api/branding.d.ts +1 -1
  26. package/dist/types/routes/management-api/clients.d.ts +2 -2
  27. package/dist/types/routes/management-api/connections.d.ts +6 -6
  28. package/dist/types/routes/management-api/email-templates.d.ts +18 -18
  29. package/dist/types/routes/management-api/failed-events.d.ts +2 -2
  30. package/dist/types/routes/management-api/guardian.d.ts +5 -5
  31. package/dist/types/routes/management-api/helpers.d.ts +1 -1
  32. package/dist/types/routes/management-api/index.d.ts +108 -80
  33. package/dist/types/routes/management-api/keys.d.ts +4 -4
  34. package/dist/types/routes/management-api/logs.d.ts +4 -4
  35. package/dist/types/routes/management-api/migration-sources.d.ts +6 -6
  36. package/dist/types/routes/management-api/organizations.d.ts +1 -1
  37. package/dist/types/routes/management-api/prompts.d.ts +4 -4
  38. package/dist/types/routes/management-api/roles.d.ts +1 -1
  39. package/dist/types/routes/management-api/sessions.d.ts +7 -0
  40. package/dist/types/routes/management-api/tenants.d.ts +6 -6
  41. package/dist/types/routes/management-api/users.d.ts +45 -24
  42. package/dist/types/routes/universal-login/common.d.ts +13 -6
  43. package/dist/types/seed.d.ts +6 -0
  44. package/dist/types/state-machines/login-session.d.ts +18 -0
  45. package/dist/types/types/AuthHeroConfig.d.ts +9 -0
  46. package/dist/types/types/Hooks.d.ts +10 -0
  47. package/dist/types/utils/totp.d.ts +6 -1
  48. package/package.json +6 -6
  49. package/dist/passkey-enrollment-CB7HjMH_.js +0 -1
@@ -22,6 +22,8 @@ export interface CreateAuthTokensParams {
22
22
  authParams: AuthParams;
23
23
  client: AuthTokenClient;
24
24
  loginSession?: LoginSession;
25
+ /** Authentication Methods References for the id_token `amr` claim. Defaults to what the login session recorded. */
26
+ amr?: string[];
25
27
  user?: User;
26
28
  session_id?: string;
27
29
  refresh_token?: string;
@@ -60,6 +62,8 @@ export interface CreateAuthTokensParams {
60
62
  */
61
63
  code?: string;
62
64
  }
65
+ /** `["mfa"]` when the login session completed an MFA factor, else undefined. */
66
+ export declare function amrFromLoginSession(loginSession: LoginSession | undefined | null): string[] | undefined;
63
67
  export declare function createAuthTokens(ctx: Context<{
64
68
  Bindings: Bindings;
65
69
  Variables: Variables;
@@ -0,0 +1,45 @@
1
+ import { Context } from "hono";
2
+ import { LoginSession } from "@authhero/adapter-interfaces";
3
+ import { Bindings, Variables } from "../types";
4
+ type MfaContext = Context<{
5
+ Bindings: Bindings;
6
+ Variables: Variables;
7
+ }>;
8
+ /**
9
+ * Failed MFA code verifications allowed per login session. The attempt that
10
+ * reaches this count fails the login session.
11
+ */
12
+ export declare const MFA_MAX_FAILED_ATTEMPTS = 5;
13
+ /** MFA SMS messages (first send plus resends) allowed per login session. */
14
+ export declare const MFA_MAX_SMS_SENDS = 5;
15
+ /** `failure_reason` stored on a login session locked out by MFA failures. */
16
+ export declare const MFA_LOCKOUT_REASON = "too_many_mfa_failures";
17
+ /** Thrown by sendMfaOtp when the SMS send limit has been reached. */
18
+ export declare class MfaSmsRateLimitError extends Error {
19
+ constructor();
20
+ }
21
+ /** True when the session was locked out or has used all its attempts. */
22
+ export declare function isMfaLockedOut(loginSession: Pick<LoginSession, "state" | "failure_reason" | "state_data">): boolean;
23
+ /**
24
+ * Call before verifying an MFA code. Returns false when the attempt must be
25
+ * rejected without checking the code: the session is locked out, or the
26
+ * per-user rate limit (when configured) is exhausted, in which case the
27
+ * session is failed too.
28
+ */
29
+ export declare function checkMfaAttemptAllowed(ctx: MfaContext, tenantId: string, loginSession: LoginSession, userId: string): Promise<boolean>;
30
+ /**
31
+ * Count a failed MFA verification on the login session. Fails the login
32
+ * session and logs a lockout when the limit is reached.
33
+ */
34
+ export declare function recordMfaFailure(ctx: MfaContext, tenantId: string, loginSessionId: string, userId: string): Promise<{
35
+ lockedOut: boolean;
36
+ }>;
37
+ /** Clear the failed-attempt counter after a successful verification. */
38
+ export declare function resetMfaFailures(ctx: MfaContext, tenantId: string, loginSessionId: string): Promise<void>;
39
+ /**
40
+ * Count an MFA SMS send on the login session and consume the per-user (or,
41
+ * without a user, per-number) rate limit. Throws MfaSmsRateLimitError when
42
+ * either limit is reached. Counted before sending, so failed sends count too.
43
+ */
44
+ export declare function enforceMfaSmsSendLimit(ctx: MfaContext, tenantId: string, loginSessionId: string, phoneNumber: string, userId?: string): Promise<void>;
45
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { Context } from "hono";
2
- import { LoginSession, AuthenticationMethod } from "@authhero/adapter-interfaces";
2
+ import { LoginSession, AuthenticationMethod, MfaPolicy } from "@authhero/adapter-interfaces";
3
3
  import { Bindings, Variables } from "../types";
4
4
  import { EnrichedClient } from "../helpers/client";
5
5
  export type MfaCheckResult = {
@@ -13,20 +13,33 @@ export type MfaCheckResult = {
13
13
  enrollment: AuthenticationMethod;
14
14
  allEnrollments: AuthenticationMethod[];
15
15
  };
16
+ /**
17
+ * Whether the tenant MFA policy alone requires MFA. `all-applications` is
18
+ * Auth0's name for `always`. `confidence-score` (adaptive MFA) is accepted but
19
+ * not supported: with no risk score to consult it is enforced like `always`,
20
+ * never skipped. Fails closed: anything but an unset policy or `never`
21
+ * requires MFA.
22
+ */
23
+ export declare function tenantPolicyRequiresMfa(policy: MfaPolicy | undefined): boolean;
16
24
  /**
17
25
  * Check if MFA is required for a user based on tenant policy and enrollment status.
26
+ *
27
+ * `options.force` requires MFA whatever the tenant policy says; it is set when
28
+ * a post-login action called `api.multifactor.enable(...)`.
18
29
  */
19
30
  export declare function checkMfaRequired(ctx: Context<{
20
31
  Bindings: Bindings;
21
32
  Variables: Variables;
22
- }>, tenantId: string, userId: string): Promise<MfaCheckResult>;
33
+ }>, tenantId: string, userId: string, options?: {
34
+ force?: boolean;
35
+ }): Promise<MfaCheckResult>;
23
36
  /**
24
37
  * Send an MFA OTP code via SMS using the tenant's configured SMS provider.
25
38
  */
26
39
  export declare function sendMfaOtp(ctx: Context<{
27
40
  Bindings: Bindings;
28
41
  Variables: Variables;
29
- }>, client: EnrichedClient, loginSession: LoginSession, phoneNumber: string): Promise<void>;
42
+ }>, client: EnrichedClient, loginSession: LoginSession, phoneNumber: string, userId?: string): Promise<void>;
30
43
  /**
31
44
  * Verify an MFA OTP code against the stored code.
32
45
  * Returns true if valid, false otherwise.
@@ -44,6 +57,8 @@ export declare function generateTotpSecret(): string;
44
57
  */
45
58
  export declare function createTotpUri(issuer: string, accountName: string, secretBase32: string): string;
46
59
  /**
47
- * Verify a TOTP code against a base32-encoded secret.
60
+ * Verify a TOTP code against a base32-encoded secret. Returns the matched
61
+ * time step, or null if the code is invalid. The step must then be recorded
62
+ * with `authenticationMethods.consumeTotpStep` to reject replays.
48
63
  */
49
- export declare function verifyTotpCode(secretBase32: string, code: string): Promise<boolean>;
64
+ export declare function verifyTotpCode(secretBase32: string, code: string): Promise<number | null>;
@@ -291,7 +291,7 @@ export declare function passwordlessGrantUser(ctx: Context<{
291
291
  } | undefined;
292
292
  } | undefined;
293
293
  mfa?: {
294
- policy?: "never" | "always" | undefined;
294
+ policy?: "never" | "always" | "all-applications" | "confidence-score" | undefined;
295
295
  factors?: {
296
296
  sms: boolean;
297
297
  otp: boolean;
@@ -391,7 +391,7 @@ export declare function passwordlessGrantUser(ctx: Context<{
391
391
  } | undefined;
392
392
  unique?: boolean | undefined;
393
393
  profile_required?: boolean | undefined;
394
- verification_method?: "code" | "link" | undefined;
394
+ verification_method?: "link" | "code" | undefined;
395
395
  } | undefined;
396
396
  username?: {
397
397
  identifier?: {
@@ -569,8 +569,8 @@ export declare function passwordlessGrantUser(ctx: Context<{
569
569
  } | undefined;
570
570
  authenticated_at?: string | undefined;
571
571
  };
572
- connectionType: "sms" | "email" | "username";
573
- authConnection: "sms" | "email" | "username";
572
+ connectionType: "email" | "sms" | "username";
573
+ authConnection: "email" | "sms" | "username";
574
574
  session_id: string | undefined;
575
575
  authParams: {
576
576
  audience?: string | undefined;
@@ -169,6 +169,8 @@ export interface CommonAccountMfaPhoneEnrollmentScreen {
169
169
  noCodeText: () => string;
170
170
  invalidCodeText: () => string;
171
171
  sessionInvalidText: () => string;
172
+ tooManyFailuresText: () => string;
173
+ tooManySmsText: () => string;
172
174
  }
173
175
  export interface CommonAccountMfaTotpEnrollmentScreen {
174
176
  title: () => string;
@@ -182,6 +184,7 @@ export interface CommonAccountMfaTotpEnrollmentScreen {
182
184
  noCodeText: () => string;
183
185
  invalidCodeText: () => string;
184
186
  verificationFailedText: () => string;
187
+ tooManyFailuresText: () => string;
185
188
  }
186
189
  export interface ConsentScreen {
187
190
  buttonText: () => string;
@@ -619,6 +622,7 @@ export interface MfaOtpMfaTotpEnrollmentScreen {
619
622
  enrollmentComplete: () => string;
620
623
  pickAuthenticatorText: () => string;
621
624
  qrCodeAltText: () => string;
625
+ "too-many-failures": () => string;
622
626
  }
623
627
  export interface MfaOtpMfaTotpChallengeScreen {
624
628
  title: () => string;
@@ -631,6 +635,7 @@ export interface MfaOtpMfaTotpChallengeScreen {
631
635
  pageTitle: (vars: {
632
636
  clientName: string;
633
637
  }) => string;
638
+ "too-many-failures": () => string;
634
639
  }
635
640
  export interface MfaPhoneMfaPhoneChallengeScreen {
636
641
  pageTitle: (vars: {
@@ -663,6 +668,7 @@ export interface MfaPhoneMfaPhoneChallengeScreen {
663
668
  unexpectedError: () => string;
664
669
  resendSuccess: () => string;
665
670
  enrollmentComplete: () => string;
671
+ "too-many-failures": () => string;
666
672
  }
667
673
  export interface MfaPhoneMfaPhoneEnrollmentScreen {
668
674
  pageTitle: (vars: {
@@ -325,6 +325,8 @@ export declare const enrichedClientSchema: z.ZodObject<{
325
325
  policy: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
326
326
  never: "never";
327
327
  always: "always";
328
+ "all-applications": "all-applications";
329
+ "confidence-score": "confidence-score";
328
330
  }>>>;
329
331
  factors: z.ZodOptional<z.ZodObject<{
330
332
  sms: z.ZodDefault<z.ZodBoolean>;
@@ -14,9 +14,9 @@ export declare const USERINFO_RESERVED_CLAIMS: readonly ["iss", "sub", "aud", "e
14
14
  * vendor/tenant for downstream APIs while `sub` stays `auth-service`.
15
15
  * Client-bound mints keep `azp` locked (see below).
16
16
  */
17
- export declare const SERVICE_TOKEN_RESERVED_CLAIMS: ("sid" | "sub" | "tenant_id" | "client_id" | "org_name" | "scope" | "jti" | "exp" | "iat" | "org_id" | "iss" | "aud" | "auth_time" | "acr" | "amr" | "gty" | "permissions" | "nbf" | "act" | "requested_userinfo_claims")[];
17
+ export declare const SERVICE_TOKEN_RESERVED_CLAIMS: ("sub" | "sid" | "client_id" | "scope" | "tenant_id" | "org_name" | "jti" | "exp" | "iat" | "org_id" | "iss" | "aud" | "auth_time" | "acr" | "amr" | "gty" | "permissions" | "nbf" | "act" | "requested_userinfo_claims")[];
18
18
  /** Client-bound mints: `azp` must stay the registered client id. */
19
- export declare const CLIENT_SERVICE_TOKEN_RESERVED_CLAIMS: ("sid" | "sub" | "tenant_id" | "client_id" | "org_name" | "scope" | "jti" | "exp" | "iat" | "org_id" | "iss" | "aud" | "auth_time" | "acr" | "amr" | "azp" | "gty" | "permissions" | "nbf" | "act" | "requested_userinfo_claims")[];
19
+ export declare const CLIENT_SERVICE_TOKEN_RESERVED_CLAIMS: ("sub" | "sid" | "client_id" | "scope" | "tenant_id" | "org_name" | "jti" | "exp" | "iat" | "org_id" | "iss" | "aud" | "auth_time" | "acr" | "amr" | "azp" | "gty" | "permissions" | "nbf" | "act" | "requested_userinfo_claims")[];
20
20
  export type AccessTokenReservedClaim = (typeof ACCESS_TOKEN_RESERVED_CLAIMS)[number];
21
21
  export type IdTokenReservedClaim = (typeof ID_TOKEN_RESERVED_CLAIMS)[number];
22
22
  /**
@@ -0,0 +1,29 @@
1
+ import type { Session, SessionsAdapter } from "@authhero/adapter-interfaces";
2
+ /** `name` of the session authentication method recorded for a completed MFA. */
3
+ export declare const SESSION_MFA_METHOD_NAME = "mfa";
4
+ export interface SessionMfaCompletion {
5
+ /** Latest time MFA was completed in this session (ISO 8601). */
6
+ completed_at: string;
7
+ /** Authentication method types used, oldest first (e.g. "totp", "phone"). */
8
+ types: string[];
9
+ }
10
+ /**
11
+ * The MFA this browser session has completed, or undefined when it never did
12
+ * (including sessions from before MFA was recorded on the session, #1668).
13
+ */
14
+ export declare function getSessionMfaCompletion(session: Pick<Session, "authentication">): SessionMfaCompletion | undefined;
15
+ /**
16
+ * Whether `session` satisfies the tenant's MFA requirement for `userId`.
17
+ * Only a session that belongs to that same user counts, so a session reused
18
+ * for impersonation never lends its MFA to the impersonated user.
19
+ */
20
+ export declare function sessionSatisfiesMfa(session: Pick<Session, "authentication" | "user_id" | "revoked_at" | "expires_at" | "idle_expires_at">, userId: string): boolean;
21
+ /**
22
+ * Append a completed MFA to the browser session. Idempotent for a given
23
+ * `timestamp`, so re-entering the auth flow for the same login (e.g. after a
24
+ * hook redirect) doesn't stack duplicate entries.
25
+ */
26
+ export declare function recordSessionMfa(sessions: Pick<SessionsAdapter, "update">, tenantId: string, session: Session, method: {
27
+ type?: string;
28
+ timestamp: string;
29
+ }): Promise<void>;
@@ -2,6 +2,19 @@ import { Context } from "hono";
2
2
  import { DataAdapters, LoginSession, User } from "@authhero/adapter-interfaces";
3
3
  import { Bindings, Variables } from "../types";
4
4
  import { EnrichedClient } from "../helpers/client";
5
+ import { MfaRequiredByAction } from "../state-machines/login-session";
6
+ /**
7
+ * Fold one `api.multifactor.enable(provider, options)` call into the request
8
+ * collected so far for this login.
9
+ *
10
+ * Conservative by design (issue #1670): once any action has required MFA it
11
+ * stays required. `"none"` is a no-op rather than Auth0's "skip MFA", so it can
12
+ * never remove MFA required by the tenant policy or by another action. Every
13
+ * other provider, including ones AuthHero has no specific support for (e.g.
14
+ * "duo"), requires MFA with any factor the tenant has enabled. The browser may
15
+ * only be remembered when every enabling call allowed it.
16
+ */
17
+ export declare function mergeMfaRequest(current: MfaRequiredByAction | undefined, provider: unknown, options: unknown): MfaRequiredByAction | undefined;
5
18
  /**
6
19
  * Checks for post-user-login hooks (form, page, template, code, or webhook)
7
20
  * and handles them in that order. Also: