@aooth/auth-moost 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +165 -50
- package/dist/index.mjs +179 -15
- package/package.json +19 -19
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Mate, TConsoleBase, TInterceptorDef, TMateParamMeta, TMoostMetadata } from "moost";
|
|
2
2
|
import { AuthContext, AuthContext as AuthContext$1, AuthCredential, AuthEmailEvent, AuthEmailKind, AuthEmailKind as AuthEmailKind$1, AuthSmsEvent, AuthSmsKind, BuildMagicLinkUrl, BuildMagicLinkUrl as BuildMagicLinkUrl$1, CredentialMetadata, EmailSender, EmailSender as EmailSender$1, EnrichedSession, EnrichedSession as EnrichedSession$1, IssueResult, IssueResult as IssueResult$1, RateLimitDecision, RateLimitDecision as RateLimitDecision$1, RateLimitRule, RateLimitRule as RateLimitRule$1, RateLimitRuleInput, RateLimitRuleInput as RateLimitRuleInput$1, RateLimitStore, RateLimitStore as RateLimitStore$1, RateLimitStoreMemory, RateLimiter, RateLimiter as RateLimiter$1, RateLimiterOptions, SessionEnricher, SessionEnricher as SessionEnricher$1, SessionInfo, SessionInfo as SessionInfo$1, SmsSender, generateMagicLinkToken } from "@aooth/auth";
|
|
3
3
|
import { EventContext } from "@wooksjs/event-core";
|
|
4
|
-
import { TCookieAttributesInput } from "@wooksjs/event-http";
|
|
5
|
-
import { FederatedIdentityStore, FederatedProfileSnapshot, MfaMethod, TransferablePolicy, TrustedDeviceRecord, UserCredentials, UserService } from "@aooth/user";
|
|
4
|
+
import { HttpError, TCookieAttributesInput } from "@wooksjs/event-http";
|
|
5
|
+
import { FederatedIdentityStore, FederatedProfileSnapshot, MfaMethod, TransferablePolicy, TrustedDeviceRecord, UserAuthError, UserAuthErrorType, UserCredentials, UserService } from "@aooth/user";
|
|
6
6
|
import { HttpError as HttpError$1 } from "@moostjs/event-http";
|
|
7
7
|
import { FinishWfOpts, WfFinished, useAtscriptWf } from "@atscript/moost-wf";
|
|
8
|
-
import { MoostWf, WfOutlet, WfOutletTokenConfig, WfStateStrategy } from "@moostjs/event-wf";
|
|
8
|
+
import { MoostWf, WfOutlet, WfOutletTokenConfig, WfOutletTriggerConfig, WfStateStrategy } from "@moostjs/event-wf";
|
|
9
9
|
import { FederatedLoginService, NormalizedProfile, OAuthProviderRegistry } from "@aooth/idp";
|
|
10
10
|
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
11
11
|
import { AuthCodeStore, AuthorizationServerMetadata, AuthorizationServerMetadata as AuthorizationServerMetadata$1, BuildAuthorizationServerMetadataOptions, BuildProtectedResourceMetadataOptions, ClientRedirectPolicy, DynamicClientRegistration, DynamicClientRegistration as DynamicClientRegistration$1, DynamicClientRegistrationOptions, IdTokenSigner, OidcClaimsResolver, PendingAuthorizationStore, ProtectedResourceMetadata, WwwAuthenticateBearerChallengeOptions, buildAuthorizationServerMetadata, buildProtectedResourceMetadata, buildWwwAuthenticateBearerChallenge, canonicalizeIssuer } from "@aooth/auth/authz";
|
|
@@ -590,7 +590,85 @@ export declare class SessionsController {
|
|
|
590
590
|
revoked: number;
|
|
591
591
|
}>;
|
|
592
592
|
}
|
|
593
|
-
|
|
593
|
+
/** The body of an `HttpError` made by {@link userAuthErrorToHttp}. */
|
|
594
|
+
interface UserAuthErrorBody {
|
|
595
|
+
message: string;
|
|
596
|
+
/** The `UserAuthError` type (`"PASSWORD_IN_HISTORY"`, `"NOT_FOUND"`, …). */
|
|
597
|
+
code: UserAuthErrorType;
|
|
598
|
+
/** `POLICY_VIOLATION`: `{ policies: [{ description, passed }] }` — every policy and its result. */
|
|
599
|
+
params?: Record<string, unknown>;
|
|
600
|
+
/** The form field the error belongs to (password errors only). */
|
|
601
|
+
field?: "currentPassword" | "newPassword" | "confirmPassword";
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Map a `UserAuthError` (thrown by `UserService`) to an `HttpError` whose body
|
|
605
|
+
* carries `code` (the error type), the message and — for password errors —
|
|
606
|
+
* the form `field` it belongs to (named as in the bundled password forms):
|
|
607
|
+
*
|
|
608
|
+
* | type | status | field |
|
|
609
|
+
* |---|---|---|
|
|
610
|
+
* | `NOT_FOUND` | 404 | |
|
|
611
|
+
* | `ALREADY_EXISTS`, `CAS_EXHAUSTED` | 409 | |
|
|
612
|
+
* | `INVALID_CREDENTIALS` | 400 | `currentPassword` |
|
|
613
|
+
* | `PASSWORD_IN_HISTORY` | 400 | `newPassword` |
|
|
614
|
+
* | `POLICY_VIOLATION` (+ `params.policies`) | 422 | `newPassword` |
|
|
615
|
+
* | `PASSWORDS_MISMATCH` | 400 | `confirmPassword` |
|
|
616
|
+
* | `MFA_INVALID`, `MFA_NOT_CONFIGURED` | 400 | |
|
|
617
|
+
* | `INACTIVE`, `LOCKED`, `MFA_REQUIRED` | 403 | |
|
|
618
|
+
*
|
|
619
|
+
* For routes such as an admin "set password" endpoint. Do not use it on a
|
|
620
|
+
* sign-in endpoint: distinct answers for unknown, inactive and locked accounts
|
|
621
|
+
* let a caller enumerate accounts (the bundled login workflow answers them
|
|
622
|
+
* uniformly).
|
|
623
|
+
*/
|
|
624
|
+
export declare function userAuthErrorToHttp(err: UserAuthError): HttpError<UserAuthErrorBody>;
|
|
625
|
+
/**
|
|
626
|
+
* Error interceptor answering every `UserAuthError` a handler throws with
|
|
627
|
+
* {@link userAuthErrorToHttp}; other errors pass through. Attach it per
|
|
628
|
+
* controller (or per handler) where `UserService` errors should become 4xx
|
|
629
|
+
* instead of 500 — typically admin and self-service routes:
|
|
630
|
+
*
|
|
631
|
+
* ```ts
|
|
632
|
+
* @Controller("admin/users")
|
|
633
|
+
* @Intercept(userAuthErrorInterceptor)
|
|
634
|
+
* export class AdminUsersController {}
|
|
635
|
+
* ```
|
|
636
|
+
*
|
|
637
|
+
* Don't install it globally: a custom sign-in or recovery handler calling
|
|
638
|
+
* `login()` / `verifyMfa()` would then answer unknown, inactive and locked
|
|
639
|
+
* accounts with distinct 404 / 403 codes — account enumeration, defeating
|
|
640
|
+
* `lockoutDisclosure: 'uniform'`.
|
|
641
|
+
*/
|
|
642
|
+
export declare const userAuthErrorInterceptor: TInterceptorDef;
|
|
643
|
+
declare const HOOK_NAMES: readonly ["around", "beforePersist", "renderEnvelope", "restoreOnError", "maxRestores"];
|
|
644
|
+
/**
|
|
645
|
+
* Workflow-trigger hooks passed through to the wooks trigger
|
|
646
|
+
* (`handleWfOutletRequest`). Set them app-wide by overriding
|
|
647
|
+
* {@link WfTriggerProvider.triggerHooks}, or per route on `@WfTrigger(...)`
|
|
648
|
+
* (a route's hook replaces the provider's hook of the same name).
|
|
649
|
+
*
|
|
650
|
+
* - `around(run)` — wraps everything the request does to workflow state and
|
|
651
|
+
* the outside world (allow checks, consume/start/resume, `beforePersist`,
|
|
652
|
+
* persist, outlet delivery), e.g. `(run) => db.transaction(run)`. It may
|
|
653
|
+
* call `run()` again after a failure; each run starts over from the request.
|
|
654
|
+
* - `beforePersist(state, pause)` — runs right before a paused state is
|
|
655
|
+
* persisted, inside `around`; throw to abort (nothing persisted, no delivery).
|
|
656
|
+
* - `renderEnvelope(envelope, info)` — maps every body the trigger answers
|
|
657
|
+
* with (paused envelopes and finished values), e.g. to translate texts.
|
|
658
|
+
* - `restoreOnError` — opt-in (default off): when a resume fails after its
|
|
659
|
+
* token was consumed, put the pre-step state back under the same token so
|
|
660
|
+
* the link can be retried (at most `maxRestores` times, default 3, never
|
|
661
|
+
* extending its lifetime). Needs a durable strategy that reports expiries
|
|
662
|
+
* (`HandleStateStrategy`); it rolls back everything the step wrote to the
|
|
663
|
+
* workflow context. Leave it off for steps with side effects that must not
|
|
664
|
+
* run twice. Set provider-wide, it also covers the bundled credential steps
|
|
665
|
+
* (set password, recovery reset, MFA enrolment) — prefer enabling it per
|
|
666
|
+
* route, or a predicate that accepts only transient store errors. The
|
|
667
|
+
* bundled password forms refuse a restored state once the password changed.
|
|
668
|
+
*/
|
|
669
|
+
type WfTriggerHooks = Pick<WfOutletTriggerConfig, (typeof HOOK_NAMES)[number]>;
|
|
670
|
+
/** Per-request options of {@link WfTriggerProvider.handle} (what `@WfTrigger(...)` passes). */
|
|
671
|
+
interface WfTriggerOpts extends WfTriggerHooks {
|
|
594
672
|
/**
|
|
595
673
|
* Workflow ids this trigger may START and RESUME (a leading `/` is ignored).
|
|
596
674
|
* Omitted = unrestricted; `[]` = deny every workflow. A state token minted
|
|
@@ -600,19 +678,35 @@ interface WfTriggerOpts {
|
|
|
600
678
|
/** Per-endpoint token wire override. Defaults to the provider's wire (`{read:['body','query','cookie'], write:'body', name:'wfs'}`). */
|
|
601
679
|
token?: WfOutletTokenConfig;
|
|
602
680
|
}
|
|
681
|
+
/** Named state-strategy registry: the shape `handleAsOutletRequest` reads off `state`. */
|
|
682
|
+
type StateRegistry = {
|
|
683
|
+
strategies: Record<string, WfStateStrategy>;
|
|
684
|
+
default: string;
|
|
685
|
+
};
|
|
603
686
|
/**
|
|
604
|
-
*
|
|
687
|
+
* Derive the exact 32-byte key the encapsulated wf-state strategy requires from
|
|
688
|
+
* an arbitrary-length app secret.
|
|
605
689
|
*
|
|
606
|
-
* The
|
|
607
|
-
* `
|
|
608
|
-
*
|
|
609
|
-
*
|
|
690
|
+
* The default {@link WfTriggerProvider.wfStateSecret} reuses the auth secret via
|
|
691
|
+
* `AuthCredential.deriveStateKey()`, which only works for stores backed by a
|
|
692
|
+
* symmetric secret (JWT / encapsulated). A stateful store (e.g. atscript-db —
|
|
693
|
+
* the recommended default once you adopt the session-listing APIs) has no key
|
|
694
|
+
* material to derive from, so its `deriveStateKey()` throws. Such consumers must
|
|
695
|
+
* override `wfStateSecret()` and supply their own secret — but the strategy
|
|
696
|
+
* needs *exactly* 32 bytes (a raw string is otherwise parsed as hex), so the
|
|
697
|
+
* obvious `return env.MY_SECRET` fails. This helper does the SHA-256-to-32-bytes
|
|
698
|
+
* derivation for you, no `node:crypto` import required:
|
|
610
699
|
*
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
*
|
|
700
|
+
* ```ts
|
|
701
|
+
* protected override wfStateSecret(): Buffer {
|
|
702
|
+
* return deriveWfStateSecret(env.MY_SECRET);
|
|
703
|
+
* }
|
|
704
|
+
* ```
|
|
705
|
+
*
|
|
706
|
+
* Deterministic — the same input always yields the same key, so it is stable
|
|
707
|
+
* across restarts (matching what `deriveStateKey` provided).
|
|
614
708
|
*/
|
|
615
|
-
export declare
|
|
709
|
+
export declare function deriveWfStateSecret(secret: string): Buffer;
|
|
616
710
|
/**
|
|
617
711
|
* DI singleton owning the workflow-trigger wiring: state persistence, outlets,
|
|
618
712
|
* and token wire. Consumers subclass to swap the durable state strategy, add
|
|
@@ -644,35 +738,6 @@ export declare const WfTrigger: (opts?: WfTriggerOpts) => ClassDecorator & Metho
|
|
|
644
738
|
* and the wf engine reads action + form data directly from `body.input`. No
|
|
645
739
|
* app-level bridging of `body.action` is needed.
|
|
646
740
|
*/
|
|
647
|
-
/** Named state-strategy registry: the shape `handleAsOutletRequest` reads off `state`. */
|
|
648
|
-
type StateRegistry = {
|
|
649
|
-
strategies: Record<string, WfStateStrategy>;
|
|
650
|
-
default: string;
|
|
651
|
-
};
|
|
652
|
-
/**
|
|
653
|
-
* Derive the exact 32-byte key the encapsulated wf-state strategy requires from
|
|
654
|
-
* an arbitrary-length app secret.
|
|
655
|
-
*
|
|
656
|
-
* The default {@link WfTriggerProvider.wfStateSecret} reuses the auth secret via
|
|
657
|
-
* `AuthCredential.deriveStateKey()`, which only works for stores backed by a
|
|
658
|
-
* symmetric secret (JWT / encapsulated). A stateful store (e.g. atscript-db —
|
|
659
|
-
* the recommended default once you adopt the session-listing APIs) has no key
|
|
660
|
-
* material to derive from, so its `deriveStateKey()` throws. Such consumers must
|
|
661
|
-
* override `wfStateSecret()` and supply their own secret — but the strategy
|
|
662
|
-
* needs *exactly* 32 bytes (a raw string is otherwise parsed as hex), so the
|
|
663
|
-
* obvious `return env.MY_SECRET` fails. This helper does the SHA-256-to-32-bytes
|
|
664
|
-
* derivation for you, no `node:crypto` import required:
|
|
665
|
-
*
|
|
666
|
-
* ```ts
|
|
667
|
-
* protected override wfStateSecret(): Buffer {
|
|
668
|
-
* return deriveWfStateSecret(env.MY_SECRET);
|
|
669
|
-
* }
|
|
670
|
-
* ```
|
|
671
|
-
*
|
|
672
|
-
* Deterministic — the same input always yields the same key, so it is stable
|
|
673
|
-
* across restarts (matching what `deriveStateKey` provided).
|
|
674
|
-
*/
|
|
675
|
-
export declare function deriveWfStateSecret(secret: string): Buffer;
|
|
676
741
|
export declare class WfTriggerProvider {
|
|
677
742
|
protected readonly wf: MoostWf;
|
|
678
743
|
protected readonly auth: AuthCredential;
|
|
@@ -699,6 +764,19 @@ export declare class WfTriggerProvider {
|
|
|
699
764
|
/** Durable strategy a workflow swaps to after the first validated input. Default = encapsulated (no real store); customers override to return e.g. new HandleStateStrategy({ store: <redis/db> }). */
|
|
700
765
|
protected storeStrategy(): WfStateStrategy;
|
|
701
766
|
private makeEncapsulated;
|
|
767
|
+
/**
|
|
768
|
+
* App-wide workflow-trigger hooks ({@link WfTriggerHooks}): `around`,
|
|
769
|
+
* `beforePersist`, `renderEnvelope`, `restoreOnError` / `maxRestores`.
|
|
770
|
+
* Default: none. A route's `@WfTrigger({...})` option of the same name
|
|
771
|
+
* replaces the hook returned here. Called once per trigger request.
|
|
772
|
+
*
|
|
773
|
+
* ```ts
|
|
774
|
+
* protected override triggerHooks(): WfTriggerHooks {
|
|
775
|
+
* return { around: (run) => db.transaction(run) };
|
|
776
|
+
* }
|
|
777
|
+
* ```
|
|
778
|
+
*/
|
|
779
|
+
protected triggerHooks(): WfTriggerHooks;
|
|
702
780
|
private cachedState?;
|
|
703
781
|
/** Named strategy registry: every wf starts on `encapsulated` (default); a step calls swapStrategy('store') to move durable. Built lazily so subclass overrides (storeStrategy/wfStateSecret) are in effect. */
|
|
704
782
|
protected stateRegistry(): StateRegistry;
|
|
@@ -706,13 +784,29 @@ export declare class WfTriggerProvider {
|
|
|
706
784
|
* Handle one trigger request. `allow` lists the workflow ids this route may
|
|
707
785
|
* START and RESUME (matched without a leading `/`); omitted = unrestricted,
|
|
708
786
|
* `[]` = deny all. A state token minted for a workflow outside the list is
|
|
709
|
-
* refused with 403 before it is consumed.
|
|
787
|
+
* refused with 403 before it is consumed. Trigger hooks set in `opts`
|
|
788
|
+
* replace the {@link triggerHooks} of the same name.
|
|
710
789
|
*/
|
|
711
|
-
handle(opts?:
|
|
712
|
-
allow?: string[];
|
|
713
|
-
token?: WfOutletTokenConfig;
|
|
714
|
-
}): Promise<unknown>;
|
|
790
|
+
handle(opts?: WfTriggerOpts): Promise<unknown>;
|
|
715
791
|
}
|
|
792
|
+
/**
|
|
793
|
+
* Method decorator that turns a handler into a workflow trigger.
|
|
794
|
+
*
|
|
795
|
+
* The handler may have an empty body — the interceptor's after-phase invokes
|
|
796
|
+
* `WfTriggerProvider.handle()` when the handler returns `undefined`. Subclasses
|
|
797
|
+
* that need to short-circuit (e.g. emit a custom error response) just return a
|
|
798
|
+
* non-undefined value from the overridden handler and the trigger is skipped.
|
|
799
|
+
*
|
|
800
|
+
* `opts` also takes the workflow-trigger hooks (`around`, `beforePersist`,
|
|
801
|
+
* `renderEnvelope`, `restoreOnError`, `maxRestores` — see `WfTriggerHooks`);
|
|
802
|
+
* each one set here replaces the provider's `triggerHooks()` hook of the
|
|
803
|
+
* same name for this route.
|
|
804
|
+
*
|
|
805
|
+
* The single `useControllerContext().instantiate(...)` call is the one
|
|
806
|
+
* documented escape hatch: interceptors are functions, not classes, so there's
|
|
807
|
+
* no ctor to inject into. Every class still uses constructor injection.
|
|
808
|
+
*/
|
|
809
|
+
export declare const WfTrigger: (opts?: WfTriggerOpts) => ClassDecorator & MethodDecorator;
|
|
716
810
|
/** Name of the outlet `AuthWorkflow` pauses on for `inviteDelivery: 'deliver' | 'return-link'`. */
|
|
717
811
|
export declare const INVITE_OUTLET = "invite";
|
|
718
812
|
/**
|
|
@@ -806,7 +900,7 @@ interface RateLimitInterceptorOptions {
|
|
|
806
900
|
trustProxy?: boolean;
|
|
807
901
|
/** Emit draft `RateLimit-*` headers on every response of a limited route. Default: `true`. */
|
|
808
902
|
headers?: boolean;
|
|
809
|
-
/** App-wide default 429 message template. */
|
|
903
|
+
/** App-wide default 429 message template (placeholders `{{limit}}`, `{{window}}`, `{{delta}}`). */
|
|
810
904
|
message?: string;
|
|
811
905
|
}
|
|
812
906
|
/**
|
|
@@ -839,7 +933,9 @@ interface RateLimitInterceptorOptions {
|
|
|
839
933
|
*
|
|
840
934
|
* On rejection: draft `RateLimit-*` headers + `Retry-After` are written to
|
|
841
935
|
* the accumulated response (they survive the throw — wooks renders the error
|
|
842
|
-
* onto the same `HttpResponse`), then `HttpError(429
|
|
936
|
+
* onto the same `HttpResponse`), then an `HttpError(429)` is thrown whose body
|
|
937
|
+
* carries the rendered `message`, `code: "RATE_LIMITED"` and
|
|
938
|
+
* `params: { policy, limit, window, retryAfter }` (seconds) — translate by code.
|
|
843
939
|
*/
|
|
844
940
|
export declare function rateLimitInterceptors(opts?: RateLimitInterceptorOptions): TInterceptorDef[];
|
|
845
941
|
/**
|
|
@@ -2152,6 +2248,12 @@ interface AuthWfCtx {
|
|
|
2152
2248
|
* password. Server-only flow control.
|
|
2153
2249
|
*/
|
|
2154
2250
|
passwordStamp?: number;
|
|
2251
|
+
/**
|
|
2252
|
+
* `password.lastChanged` when a password form was first reached; a replay
|
|
2253
|
+
* after the password changed answers 410 `PASSWORD_CHANGED_SIGN_IN_AGAIN`.
|
|
2254
|
+
* Cleared once the password is stored. Server-only flow control.
|
|
2255
|
+
*/
|
|
2256
|
+
passwordFormStamp?: number;
|
|
2155
2257
|
/**
|
|
2156
2258
|
* Idempotency latch for the single `record-login` funnel step. Set true once
|
|
2157
2259
|
* a login has been stamped this run — by the `credentials` step (the password
|
|
@@ -3702,6 +3804,19 @@ export declare class AuthWorkflow {
|
|
|
3702
3804
|
* convention).
|
|
3703
3805
|
*/
|
|
3704
3806
|
changePasswordForm(ctx: AuthWfCtx): Promise<unknown>;
|
|
3807
|
+
/**
|
|
3808
|
+
* Refuse a password form whose account password changed after the form was
|
|
3809
|
+
* first reached: the first visit stamps `password.lastChanged`
|
|
3810
|
+
* (`ctx.passwordFormStamp`); a later visit that finds another value is a
|
|
3811
|
+
* replay of an already-used form — a single-use token put back by the
|
|
3812
|
+
* trigger's `restoreOnError` after a later failure, or a re-submitted
|
|
3813
|
+
* encapsulated token — and answers 410 `PASSWORD_CHANGED_SIGN_IN_AGAIN`
|
|
3814
|
+
* instead of changing the password again. Returns the account row; on an
|
|
3815
|
+
* invite accept it is read through {@link currentInviteRow}, so a cancelled
|
|
3816
|
+
* or superseded invite answers 410. A deleted account returns `null` and is
|
|
3817
|
+
* not checked: the step's own password write then answers it as a form error.
|
|
3818
|
+
*/
|
|
3819
|
+
private refusePasswordFormReplay;
|
|
3705
3820
|
/**
|
|
3706
3821
|
* Change-password terminal — sign the current device in on a FRESH session
|
|
3707
3822
|
* and end the one the change was made from, then emit a success message.
|
|
@@ -4530,4 +4645,4 @@ interface AuditEvent {
|
|
|
4530
4645
|
interface AuditEmitter {
|
|
4531
4646
|
emit(event: AuditEvent): Promise<void> | void;
|
|
4532
4647
|
}
|
|
4533
|
-
export { type AoothMessageCode, type AoothMessageParams, type AoothMessages, type AuditEmitter, type AuditEvent, type AuthBindings, type AuthContext, type AuthDeliveryPayload, type AuthEmailEvent, type AuthEmailKind, type AuthEmailOutletDeps, type AuthLoginResponse, type AuthLogoutBody, type AuthOkResponse, type AuthOptions, type AuthRefreshBody, type AuthSmsEvent, type AuthSmsKind, type AuthWfCompletionState, type AuthWfConsentsState, type AuthWfCtx, type AuthWfMfaEnrollState, type AuthWfOAuthState, type AuthWfPasswordUiState, type AuthWfPincodeUiState, type AuthWorkflowOpts, type AuthorizationServerMetadata, type AuthzReauthPolicy, type BuildAuthorizationServerMetadataOptions, type BuildMagicLinkUrl, type BuildProtectedResourceMetadataOptions, type ConcurrencyLimitOptions, type ConnectedAccount, type ConsentDescriptor, type ConsentDescriptorLike, type ConsentEvent, DynamicClientRegistration, type DynamicClientRegistrationOptions, type EmailSender, type EnrichedSession, type IssueResult, type LoginRedirect, type MfaSummary, type MfaTransport, type ProtectedResourceMetadata, type RateLimitBindings, type RateLimitDecision, type RateLimitDecoratorOptions, type RateLimitInterceptorOptions, type RateLimitKeyStrategy, type RateLimitRule, type RateLimitRuleInput, type RateLimitStore, RateLimitStoreMemory, RateLimiter, type RateLimiterOptions, type ResolvedAuthCookieConfig, type ResolvedAuthOptions, type ResolvedAuthWorkflowOpts, type SessionEnricher, type SessionInfo, type SmsSender, type SsoProvider, type TAuthMeta, type TRateLimitMeta, type WfTriggerOpts, type WwwAuthenticateBearerChallengeOptions, buildAuthorizationServerMetadata, buildProtectedResourceMetadata, buildWwwAuthenticateBearerChallenge, canonicalizeIssuer, generateMagicLinkToken };
|
|
4648
|
+
export { type AoothMessageCode, type AoothMessageParams, type AoothMessages, type AuditEmitter, type AuditEvent, type AuthBindings, type AuthContext, type AuthDeliveryPayload, type AuthEmailEvent, type AuthEmailKind, type AuthEmailOutletDeps, type AuthLoginResponse, type AuthLogoutBody, type AuthOkResponse, type AuthOptions, type AuthRefreshBody, type AuthSmsEvent, type AuthSmsKind, type AuthWfCompletionState, type AuthWfConsentsState, type AuthWfCtx, type AuthWfMfaEnrollState, type AuthWfOAuthState, type AuthWfPasswordUiState, type AuthWfPincodeUiState, type AuthWorkflowOpts, type AuthorizationServerMetadata, type AuthzReauthPolicy, type BuildAuthorizationServerMetadataOptions, type BuildMagicLinkUrl, type BuildProtectedResourceMetadataOptions, type ConcurrencyLimitOptions, type ConnectedAccount, type ConsentDescriptor, type ConsentDescriptorLike, type ConsentEvent, DynamicClientRegistration, type DynamicClientRegistrationOptions, type EmailSender, type EnrichedSession, type IssueResult, type LoginRedirect, type MfaSummary, type MfaTransport, type ProtectedResourceMetadata, type RateLimitBindings, type RateLimitDecision, type RateLimitDecoratorOptions, type RateLimitInterceptorOptions, type RateLimitKeyStrategy, type RateLimitRule, type RateLimitRuleInput, type RateLimitStore, RateLimitStoreMemory, RateLimiter, type RateLimiterOptions, type ResolvedAuthCookieConfig, type ResolvedAuthOptions, type ResolvedAuthWorkflowOpts, type SessionEnricher, type SessionInfo, type SmsSender, type SsoProvider, type TAuthMeta, type TRateLimitMeta, type UserAuthErrorBody, type WfTriggerHooks, type WfTriggerOpts, type WwwAuthenticateBearerChallengeOptions, buildAuthorizationServerMetadata, buildProtectedResourceMetadata, buildWwwAuthenticateBearerChallenge, canonicalizeIssuer, generateMagicLinkToken };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { C as RemoveMfaConfirmForm, D as StepUpConfirmForm, E as SignupForm, O as TermsBumpForm, T as SetPasswordForm, _ as PasswordReauthForm, a as ConcurrencyLimitForm, b as ProveControlOtpForm, c as EnrollConfirmForm, d as InviteChooseUsernameForm, f as InviteForm, g as MfaCodeForm, h as ManageMfaForm, i as ChangePasswordForm, l as EnrollPickMethodForm, n as AskPhoneForm, o as EmailIdentifierForm, p as LoginCredentialsForm, r as AuthorizeConsentForm, s as EnrollAddressForm, t as AskEmailForm, u as EnrollTotpQrForm, v as PincodeForm, w as Select2faForm, y as ProveControlForm } from "./forms-C_VNxSDn.mjs";
|
|
2
|
-
import { Controller, HandlerPaths, Inherit, Inject, InjectMoostLogger, Injectable, Intercept, MoostInit, Optional, Param, Resolve, TInterceptorPriority, defineAfterInterceptor, defineBeforeInterceptor, getMoostMate, useControllerContext, useLogger } from "moost";
|
|
2
|
+
import { Controller, HandlerPaths, Inherit, Inject, InjectMoostLogger, Injectable, Intercept, MoostInit, Optional, Param, Resolve, TInterceptorPriority, defineAfterInterceptor, defineBeforeInterceptor, defineErrorInterceptor, getMoostMate, useControllerContext, useLogger } from "moost";
|
|
3
3
|
import { AuthCredential, AuthError, RateLimitStoreMemory, RateLimitStoreMemory as RateLimitStoreMemory$1, RateLimiter, RateLimiter as RateLimiter$1, generateMagicLinkToken, generateOpaqueToken, parseRateLimitRule, pickGoverning } from "@aooth/auth";
|
|
4
4
|
import { current, defineWook, eventTypeKey, key } from "@wooksjs/event-core";
|
|
5
5
|
import { HttpError, resolveForwarded, useAuthorization, useCookies, useHeaders, useRequest, useResponse, useUrlParams } from "@wooksjs/event-http";
|
|
@@ -454,7 +454,9 @@ function useRateLimit(ctx = current()) {
|
|
|
454
454
|
*
|
|
455
455
|
* On rejection: draft `RateLimit-*` headers + `Retry-After` are written to
|
|
456
456
|
* the accumulated response (they survive the throw — wooks renders the error
|
|
457
|
-
* onto the same `HttpResponse`), then `HttpError(429
|
|
457
|
+
* onto the same `HttpResponse`), then an `HttpError(429)` is thrown whose body
|
|
458
|
+
* carries the rendered `message`, `code: "RATE_LIMITED"` and
|
|
459
|
+
* `params: { policy, limit, window, retryAfter }` (seconds) — translate by code.
|
|
458
460
|
*/
|
|
459
461
|
function rateLimitInterceptors(opts) {
|
|
460
462
|
const defaultRules = opts?.rules?.map((r) => parseRateLimitRule(r));
|
|
@@ -533,7 +535,11 @@ function rateLimitInterceptors(opts) {
|
|
|
533
535
|
}
|
|
534
536
|
if (!decision.allowed) {
|
|
535
537
|
response.setHeader("retry-after", String(Math.ceil(decision.resetAfterMs / 1e3)));
|
|
536
|
-
throw new HttpError(429,
|
|
538
|
+
throw new HttpError(429, {
|
|
539
|
+
message: decision.message ?? "Too many requests",
|
|
540
|
+
code: decision.code ?? "RATE_LIMITED",
|
|
541
|
+
...decision.params && { params: decision.params }
|
|
542
|
+
});
|
|
537
543
|
}
|
|
538
544
|
};
|
|
539
545
|
return [defineBeforeInterceptor(() => evaluate("pre"), TInterceptorPriority.BEFORE_GUARD), defineBeforeInterceptor(() => evaluate("post"), TInterceptorPriority.AFTER_GUARD)];
|
|
@@ -640,6 +646,13 @@ function __decorateMetadata(k, v) {
|
|
|
640
646
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
641
647
|
}
|
|
642
648
|
// src/wf-trigger/provider.ts
|
|
649
|
+
const HOOK_NAMES = [
|
|
650
|
+
"around",
|
|
651
|
+
"beforePersist",
|
|
652
|
+
"renderEnvelope",
|
|
653
|
+
"restoreOnError",
|
|
654
|
+
"maxRestores"
|
|
655
|
+
];
|
|
643
656
|
/**
|
|
644
657
|
* Derive the exact 32-byte key the encapsulated wf-state strategy requires from
|
|
645
658
|
* an arbitrary-length app secret.
|
|
@@ -677,18 +690,38 @@ function notAllowed(id) {
|
|
|
677
690
|
* Wrap a strategy so a resume is checked against the allow list BEFORE the
|
|
678
691
|
* state is consumed: the state is peeked (`retrieve`), refused with 403 when
|
|
679
692
|
* its workflow is not allowed on this route (the token stays usable on its
|
|
680
|
-
* own route), and only then consumed.
|
|
693
|
+
* own route), and only then consumed. The optional expiry-reporting methods
|
|
694
|
+
* (`persistEntry` / `consumeEntry`, which `restoreOnError` needs) are kept
|
|
695
|
+
* when the wrapped strategy has them.
|
|
681
696
|
*/
|
|
682
697
|
function guardStrategy(strategy, permits) {
|
|
683
|
-
|
|
698
|
+
const check = async (token) => {
|
|
699
|
+
const peeked = await strategy.retrieve(token);
|
|
700
|
+
if (peeked && !permits(peeked.schemaId)) throw notAllowed(peeked.schemaId);
|
|
701
|
+
};
|
|
702
|
+
const guarded = {
|
|
684
703
|
persist: (state, options, overrides) => strategy.persist(state, options, overrides),
|
|
685
704
|
retrieve: (token) => strategy.retrieve(token),
|
|
686
705
|
consume: async (token) => {
|
|
687
|
-
|
|
688
|
-
if (peeked && !permits(peeked.schemaId)) throw notAllowed(peeked.schemaId);
|
|
706
|
+
await check(token);
|
|
689
707
|
return strategy.consume(token);
|
|
690
708
|
}
|
|
691
709
|
};
|
|
710
|
+
if (strategy.persistEntry) guarded.persistEntry = (state, options, overrides) => strategy.persistEntry(state, options, overrides);
|
|
711
|
+
if (strategy.consumeEntry) guarded.consumeEntry = async (token) => {
|
|
712
|
+
await check(token);
|
|
713
|
+
return strategy.consumeEntry(token);
|
|
714
|
+
};
|
|
715
|
+
return guarded;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Run one trigger attempt. The invite outlet reads the link callback from a
|
|
719
|
+
* slot reserved on the HTTP event; it is reserved per run, so a run that
|
|
720
|
+
* `around` retries starts clean.
|
|
721
|
+
*/
|
|
722
|
+
function runTrigger(run) {
|
|
723
|
+
reservePendingInviteLink();
|
|
724
|
+
return run();
|
|
692
725
|
}
|
|
693
726
|
let WfTriggerProvider = class WfTriggerProvider {
|
|
694
727
|
wf;
|
|
@@ -736,6 +769,21 @@ let WfTriggerProvider = class WfTriggerProvider {
|
|
|
736
769
|
defaultTtl: this.wfStateEncapsulatedTtlMs()
|
|
737
770
|
});
|
|
738
771
|
}
|
|
772
|
+
/**
|
|
773
|
+
* App-wide workflow-trigger hooks ({@link WfTriggerHooks}): `around`,
|
|
774
|
+
* `beforePersist`, `renderEnvelope`, `restoreOnError` / `maxRestores`.
|
|
775
|
+
* Default: none. A route's `@WfTrigger({...})` option of the same name
|
|
776
|
+
* replaces the hook returned here. Called once per trigger request.
|
|
777
|
+
*
|
|
778
|
+
* ```ts
|
|
779
|
+
* protected override triggerHooks(): WfTriggerHooks {
|
|
780
|
+
* return { around: (run) => db.transaction(run) };
|
|
781
|
+
* }
|
|
782
|
+
* ```
|
|
783
|
+
*/
|
|
784
|
+
triggerHooks() {
|
|
785
|
+
return {};
|
|
786
|
+
}
|
|
739
787
|
cachedState;
|
|
740
788
|
/** Named strategy registry: every wf starts on `encapsulated` (default); a step calls swapStrategy('store') to move durable. Built lazily so subclass overrides (storeStrategy/wfStateSecret) are in effect. */
|
|
741
789
|
stateRegistry() {
|
|
@@ -752,7 +800,8 @@ let WfTriggerProvider = class WfTriggerProvider {
|
|
|
752
800
|
* Handle one trigger request. `allow` lists the workflow ids this route may
|
|
753
801
|
* START and RESUME (matched without a leading `/`); omitted = unrestricted,
|
|
754
802
|
* `[]` = deny all. A state token minted for a workflow outside the list is
|
|
755
|
-
* refused with 403 before it is consumed.
|
|
803
|
+
* refused with 403 before it is consumed. Trigger hooks set in `opts`
|
|
804
|
+
* replace the {@link triggerHooks} of the same name.
|
|
756
805
|
*/
|
|
757
806
|
async handle(opts = {}) {
|
|
758
807
|
const wfApp = this.wf.getWfApp();
|
|
@@ -781,8 +830,16 @@ let WfTriggerProvider = class WfTriggerProvider {
|
|
|
781
830
|
});
|
|
782
831
|
}
|
|
783
832
|
};
|
|
784
|
-
|
|
833
|
+
const base = this.triggerHooks();
|
|
834
|
+
const hooks = {};
|
|
835
|
+
for (const name of HOOK_NAMES) {
|
|
836
|
+
const value = opts[name] ?? base[name];
|
|
837
|
+
if (value !== void 0) hooks[name] = value;
|
|
838
|
+
}
|
|
839
|
+
const around = opts.around ?? base.around;
|
|
785
840
|
return handleAsOutletRequest({
|
|
841
|
+
...hooks,
|
|
842
|
+
around: around ? (run) => around(() => runTrigger(run)) : runTrigger,
|
|
786
843
|
state: stateConfig,
|
|
787
844
|
outlets: this.outlets,
|
|
788
845
|
token: opts.token ?? this.token
|
|
@@ -799,6 +856,11 @@ WfTriggerProvider = __decorate([Injectable(), __decorateMetadata("design:paramty
|
|
|
799
856
|
* that need to short-circuit (e.g. emit a custom error response) just return a
|
|
800
857
|
* non-undefined value from the overridden handler and the trigger is skipped.
|
|
801
858
|
*
|
|
859
|
+
* `opts` also takes the workflow-trigger hooks (`around`, `beforePersist`,
|
|
860
|
+
* `renderEnvelope`, `restoreOnError`, `maxRestores` — see `WfTriggerHooks`);
|
|
861
|
+
* each one set here replaces the provider's `triggerHooks()` hook of the
|
|
862
|
+
* same name for this route.
|
|
863
|
+
*
|
|
802
864
|
* The single `useControllerContext().instantiate(...)` call is the one
|
|
803
865
|
* documented escape hatch: interceptors are functions, not classes, so there's
|
|
804
866
|
* no ctor to inject into. Every class still uses constructor injection.
|
|
@@ -1045,6 +1107,82 @@ let OAuthRuntime = class OAuthRuntime {
|
|
|
1045
1107
|
}
|
|
1046
1108
|
};
|
|
1047
1109
|
OAuthRuntime = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [typeof OAuthProviderRegistry === "undefined" ? Object : OAuthProviderRegistry, typeof FederatedLoginService === "undefined" ? Object : FederatedLoginService])], OAuthRuntime);
|
|
1110
|
+
// src/user-errors.ts
|
|
1111
|
+
const STATUS = {
|
|
1112
|
+
NOT_FOUND: 404,
|
|
1113
|
+
ALREADY_EXISTS: 409,
|
|
1114
|
+
CAS_EXHAUSTED: 409,
|
|
1115
|
+
INVALID_CREDENTIALS: 400,
|
|
1116
|
+
MFA_INVALID: 400,
|
|
1117
|
+
MFA_NOT_CONFIGURED: 400,
|
|
1118
|
+
PASSWORDS_MISMATCH: 400,
|
|
1119
|
+
PASSWORD_IN_HISTORY: 400,
|
|
1120
|
+
POLICY_VIOLATION: 422,
|
|
1121
|
+
INACTIVE: 403,
|
|
1122
|
+
LOCKED: 403,
|
|
1123
|
+
MFA_REQUIRED: 403
|
|
1124
|
+
};
|
|
1125
|
+
const FIELD = {
|
|
1126
|
+
INVALID_CREDENTIALS: "currentPassword",
|
|
1127
|
+
POLICY_VIOLATION: "newPassword",
|
|
1128
|
+
PASSWORD_IN_HISTORY: "newPassword",
|
|
1129
|
+
PASSWORDS_MISMATCH: "confirmPassword"
|
|
1130
|
+
};
|
|
1131
|
+
/** The password-form field an error belongs to (shared with the bundled password forms). */
|
|
1132
|
+
function userAuthErrorField(type) {
|
|
1133
|
+
return FIELD[type];
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Map a `UserAuthError` (thrown by `UserService`) to an `HttpError` whose body
|
|
1137
|
+
* carries `code` (the error type), the message and — for password errors —
|
|
1138
|
+
* the form `field` it belongs to (named as in the bundled password forms):
|
|
1139
|
+
*
|
|
1140
|
+
* | type | status | field |
|
|
1141
|
+
* |---|---|---|
|
|
1142
|
+
* | `NOT_FOUND` | 404 | |
|
|
1143
|
+
* | `ALREADY_EXISTS`, `CAS_EXHAUSTED` | 409 | |
|
|
1144
|
+
* | `INVALID_CREDENTIALS` | 400 | `currentPassword` |
|
|
1145
|
+
* | `PASSWORD_IN_HISTORY` | 400 | `newPassword` |
|
|
1146
|
+
* | `POLICY_VIOLATION` (+ `params.policies`) | 422 | `newPassword` |
|
|
1147
|
+
* | `PASSWORDS_MISMATCH` | 400 | `confirmPassword` |
|
|
1148
|
+
* | `MFA_INVALID`, `MFA_NOT_CONFIGURED` | 400 | |
|
|
1149
|
+
* | `INACTIVE`, `LOCKED`, `MFA_REQUIRED` | 403 | |
|
|
1150
|
+
*
|
|
1151
|
+
* For routes such as an admin "set password" endpoint. Do not use it on a
|
|
1152
|
+
* sign-in endpoint: distinct answers for unknown, inactive and locked accounts
|
|
1153
|
+
* let a caller enumerate accounts (the bundled login workflow answers them
|
|
1154
|
+
* uniformly).
|
|
1155
|
+
*/
|
|
1156
|
+
function userAuthErrorToHttp(err) {
|
|
1157
|
+
const field = userAuthErrorField(err.type);
|
|
1158
|
+
const policies = err.type === "POLICY_VIOLATION" ? err.details?.policies : void 0;
|
|
1159
|
+
return new HttpError(STATUS[err.type], {
|
|
1160
|
+
message: err.message,
|
|
1161
|
+
code: err.type,
|
|
1162
|
+
...policies !== void 0 && { params: { policies } },
|
|
1163
|
+
...field && { field }
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Error interceptor answering every `UserAuthError` a handler throws with
|
|
1168
|
+
* {@link userAuthErrorToHttp}; other errors pass through. Attach it per
|
|
1169
|
+
* controller (or per handler) where `UserService` errors should become 4xx
|
|
1170
|
+
* instead of 500 — typically admin and self-service routes:
|
|
1171
|
+
*
|
|
1172
|
+
* ```ts
|
|
1173
|
+
* @Controller("admin/users")
|
|
1174
|
+
* @Intercept(userAuthErrorInterceptor)
|
|
1175
|
+
* export class AdminUsersController {}
|
|
1176
|
+
* ```
|
|
1177
|
+
*
|
|
1178
|
+
* Don't install it globally: a custom sign-in or recovery handler calling
|
|
1179
|
+
* `login()` / `verifyMfa()` would then answer unknown, inactive and locked
|
|
1180
|
+
* accounts with distinct 404 / 403 codes — account enumeration, defeating
|
|
1181
|
+
* `lockoutDisclosure: 'uniform'`.
|
|
1182
|
+
*/
|
|
1183
|
+
const userAuthErrorInterceptor = defineErrorInterceptor((error, reply) => {
|
|
1184
|
+
if (error instanceof UserAuthError) reply(userAuthErrorToHttp(error));
|
|
1185
|
+
}, TInterceptorPriority.CATCH_ERROR);
|
|
1048
1186
|
// src/workflow/auth-messages.ts
|
|
1049
1187
|
/**
|
|
1050
1188
|
* Code-keyed catalogue of every user-facing text `AuthWorkflow` produces —
|
|
@@ -2590,7 +2728,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
2590
2728
|
try {
|
|
2591
2729
|
return await op();
|
|
2592
2730
|
} catch (err) {
|
|
2593
|
-
if (err instanceof UserAuthError && err.type === "CAS_EXHAUSTED") throw
|
|
2731
|
+
if (err instanceof UserAuthError && err.type === "CAS_EXHAUSTED") throw userAuthErrorToHttp(err);
|
|
2594
2732
|
throw err;
|
|
2595
2733
|
}
|
|
2596
2734
|
}
|
|
@@ -3709,6 +3847,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3709
3847
|
const copy = await this.resolveSetPasswordCopy(ctx);
|
|
3710
3848
|
if (copy.heading !== void 0) password.heading = copy.heading;
|
|
3711
3849
|
if (copy.intro !== void 0) password.intro = copy.intro;
|
|
3850
|
+
const user = await this.refusePasswordFormReplay(ctx);
|
|
3712
3851
|
const wf = this.useAtscriptWfPublic(ctx, this.opts.forms.setPassword);
|
|
3713
3852
|
let input;
|
|
3714
3853
|
try {
|
|
@@ -3718,7 +3857,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3718
3857
|
throw err;
|
|
3719
3858
|
}
|
|
3720
3859
|
if (input.newPassword !== input.confirmPassword) throw this.throwPublic(ctx, wf, { errors: { confirmPassword: this.msg("PASSWORDS_DO_NOT_MATCH") } });
|
|
3721
|
-
if (ctx.accept)
|
|
3860
|
+
if (ctx.accept && !user?.account?.pendingInvitation) throw this.httpError(410, "INVITE_ALREADY_ACCEPTED");
|
|
3722
3861
|
try {
|
|
3723
3862
|
await this.users.setPassword(ctx.subject, input.newPassword);
|
|
3724
3863
|
} catch (err) {
|
|
@@ -3729,6 +3868,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3729
3868
|
ctx.isPasswordInitial = false;
|
|
3730
3869
|
ctx.isPasswordExpired = false;
|
|
3731
3870
|
ctx.passwordChanged = true;
|
|
3871
|
+
delete ctx.passwordFormStamp;
|
|
3732
3872
|
ctx.newPasswordRequired = false;
|
|
3733
3873
|
delete password.changeReason;
|
|
3734
3874
|
delete password.heading;
|
|
@@ -3780,6 +3920,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3780
3920
|
*/
|
|
3781
3921
|
async changePasswordForm(ctx) {
|
|
3782
3922
|
this.requireSubject(ctx);
|
|
3923
|
+
await this.refusePasswordFormReplay(ctx);
|
|
3783
3924
|
const wf = this.useAtscriptWfPublic(ctx, this.opts.forms.changePassword);
|
|
3784
3925
|
const input = wf.resolveInput();
|
|
3785
3926
|
if (input.newPassword !== input.confirmPassword) throw this.throwPublic(ctx, wf, { errors: { confirmPassword: this.msg("PASSWORDS_DO_NOT_MATCH") } });
|
|
@@ -3787,11 +3928,35 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3787
3928
|
await this.users.changePassword(ctx.subject, input.currentPassword, input.newPassword, input.confirmPassword);
|
|
3788
3929
|
} catch (err) {
|
|
3789
3930
|
if (err instanceof UserAuthError) {
|
|
3790
|
-
const field = err.type
|
|
3931
|
+
const field = userAuthErrorField(err.type) ?? "newPassword";
|
|
3791
3932
|
throw this.throwPublic(ctx, wf, { errors: { [field]: err.message } });
|
|
3792
3933
|
}
|
|
3793
3934
|
throw err;
|
|
3794
3935
|
}
|
|
3936
|
+
delete ctx.passwordFormStamp;
|
|
3937
|
+
}
|
|
3938
|
+
/**
|
|
3939
|
+
* Refuse a password form whose account password changed after the form was
|
|
3940
|
+
* first reached: the first visit stamps `password.lastChanged`
|
|
3941
|
+
* (`ctx.passwordFormStamp`); a later visit that finds another value is a
|
|
3942
|
+
* replay of an already-used form — a single-use token put back by the
|
|
3943
|
+
* trigger's `restoreOnError` after a later failure, or a re-submitted
|
|
3944
|
+
* encapsulated token — and answers 410 `PASSWORD_CHANGED_SIGN_IN_AGAIN`
|
|
3945
|
+
* instead of changing the password again. Returns the account row; on an
|
|
3946
|
+
* invite accept it is read through {@link currentInviteRow}, so a cancelled
|
|
3947
|
+
* or superseded invite answers 410. A deleted account returns `null` and is
|
|
3948
|
+
* not checked: the step's own password write then answers it as a form error.
|
|
3949
|
+
*/
|
|
3950
|
+
async refusePasswordFormReplay(ctx) {
|
|
3951
|
+
const user = ctx.accept ? await this.currentInviteRow(ctx) : await this.users.getUser(ctx.subject).catch((err) => {
|
|
3952
|
+
if (err instanceof UserAuthError && err.type === "NOT_FOUND") return null;
|
|
3953
|
+
throw err;
|
|
3954
|
+
});
|
|
3955
|
+
if (!user) return null;
|
|
3956
|
+
const current = user.password.lastChanged ?? 0;
|
|
3957
|
+
if (ctx.passwordFormStamp === void 0) ctx.passwordFormStamp = current;
|
|
3958
|
+
else if (ctx.passwordFormStamp !== current) throw this.httpError(410, "PASSWORD_CHANGED_SIGN_IN_AGAIN");
|
|
3959
|
+
return user;
|
|
3795
3960
|
}
|
|
3796
3961
|
/**
|
|
3797
3962
|
* Change-password terminal — sign the current device in on a FRESH session
|
|
@@ -4472,7 +4637,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4472
4637
|
const input = wf.resolveInput();
|
|
4473
4638
|
this.requireSubject(ctx);
|
|
4474
4639
|
try {
|
|
4475
|
-
await this.users.verifyMfa(ctx.subject, input.code, void 0, this.lockoutOverride(ctx));
|
|
4640
|
+
await this.withStoreErrorTranslation(() => this.users.verifyMfa(ctx.subject, input.code, void 0, this.lockoutOverride(ctx)));
|
|
4476
4641
|
(ctx.otp ??= {}).verified = true;
|
|
4477
4642
|
(ctx.session ??= {}).riskStepUpEvaluated = false;
|
|
4478
4643
|
if (ctx.deviceTrust?.enabled && ctx.deviceTrust?.optIn) (ctx.trust ??= {}).rememberDevice = Boolean(input.rememberDevice);
|
|
@@ -4485,7 +4650,6 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4485
4650
|
if (err.details?.lockEnds !== void 0) throw this.throwPublic(ctx, wf, { formMessage: this.msg("ACCOUNT_LOCKED") });
|
|
4486
4651
|
throw this.throwPublic(ctx, wf, { errors: { code: this.msg("INVALID_CODE") } });
|
|
4487
4652
|
}
|
|
4488
|
-
if (err.type === "CAS_EXHAUSTED") throw new HttpError$1(409, err.message);
|
|
4489
4653
|
}
|
|
4490
4654
|
throw err;
|
|
4491
4655
|
}
|
|
@@ -8066,4 +8230,4 @@ function createAuthEmailOutlet(deps) {
|
|
|
8066
8230
|
await deps.emailSender.send(event);
|
|
8067
8231
|
});
|
|
8068
8232
|
}
|
|
8069
|
-
export { ADD_MFA_WORKFLOW, AOOTH_MESSAGES, AUTHZ_BINDING_COOKIE, AUTH_CODE_STORE_TOKEN, AuthController, AuthGuarded, AuthWorkflow, AuthorizeController, AuthorizeRuntime, CHANGE_PASSWORD_WORKFLOW, CLIENT_REDIRECT_POLICY_TOKEN, ConsentStore, DEFAULT_AUTH_WORKFLOWS, DYNAMIC_CLIENT_STORE_TOKEN, DynamicClientRegistration, FEDERATED_IDENTITY_STORE_TOKEN, INVITE_OUTLET, OAUTH_CSRF_COOKIE, OAuthController, OAuthRuntime, PENDING_AUTHORIZATION_STORE_TOKEN, Public, RESERVED_USER_KEYS, RateLimit, RateLimitStoreMemory, RateLimited, RateLimiter, SessionEnricherProvider, SessionsController, UserId, WfTrigger, WfTriggerProvider, authGuardInterceptor, authzBindingCookieAttrs, buildAuthorizationServerMetadata, buildInviteAlreadyAcceptedEnvelope, buildProtectedResourceMetadata, buildWwwAuthenticateBearerChallenge, canonicalizeIssuer, createAuthEmailOutlet, createInviteOutlet, deriveWfStateSecret, generateMagicLinkToken, getAuthMate, getRateLimitMate, getRateLimitSubject, haversineKm, humanizeUserAgent, isSafeRelativeRedirect, oauthCsrfCookieAttrs, parseInviteRoles, rateLimitInterceptors, renderAoothMessage, resolveAoothMessage, resolveOAuthRedirect, setRateLimitSubject, stripReservedUserKeys, useAuth, useRateLimit };
|
|
8233
|
+
export { ADD_MFA_WORKFLOW, AOOTH_MESSAGES, AUTHZ_BINDING_COOKIE, AUTH_CODE_STORE_TOKEN, AuthController, AuthGuarded, AuthWorkflow, AuthorizeController, AuthorizeRuntime, CHANGE_PASSWORD_WORKFLOW, CLIENT_REDIRECT_POLICY_TOKEN, ConsentStore, DEFAULT_AUTH_WORKFLOWS, DYNAMIC_CLIENT_STORE_TOKEN, DynamicClientRegistration, FEDERATED_IDENTITY_STORE_TOKEN, INVITE_OUTLET, OAUTH_CSRF_COOKIE, OAuthController, OAuthRuntime, PENDING_AUTHORIZATION_STORE_TOKEN, Public, RESERVED_USER_KEYS, RateLimit, RateLimitStoreMemory, RateLimited, RateLimiter, SessionEnricherProvider, SessionsController, UserId, WfTrigger, WfTriggerProvider, authGuardInterceptor, authzBindingCookieAttrs, buildAuthorizationServerMetadata, buildInviteAlreadyAcceptedEnvelope, buildProtectedResourceMetadata, buildWwwAuthenticateBearerChallenge, canonicalizeIssuer, createAuthEmailOutlet, createInviteOutlet, deriveWfStateSecret, generateMagicLinkToken, getAuthMate, getRateLimitMate, getRateLimitSubject, haversineKm, humanizeUserAgent, isSafeRelativeRedirect, oauthCsrfCookieAttrs, parseInviteRoles, rateLimitInterceptors, renderAoothMessage, resolveAoothMessage, resolveOAuthRedirect, setRateLimitSubject, stripReservedUserKeys, useAuth, useRateLimit, userAuthErrorInterceptor, userAuthErrorToHttp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aooth/auth-moost",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Moost auth integration for aoothjs — AuthGuard interceptor, useAuth composable, REST endpoints, workflows",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aoothjs",
|
|
@@ -57,33 +57,33 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@atscript/moost-wf": "^0.1.
|
|
60
|
+
"@atscript/moost-wf": "^0.1.164",
|
|
61
61
|
"@wooksjs/http-body": "^0.8.0",
|
|
62
|
-
"@aooth/arbac-moost": "^0.2.
|
|
63
|
-
"@aooth/auth": "0.2.
|
|
64
|
-
"@aooth/
|
|
65
|
-
"@aooth/
|
|
62
|
+
"@aooth/arbac-moost": "^0.2.4",
|
|
63
|
+
"@aooth/auth": "0.2.4",
|
|
64
|
+
"@aooth/user": "0.2.4",
|
|
65
|
+
"@aooth/idp": "0.2.4"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@atscript/core": "^0.2.
|
|
69
|
-
"@atscript/typescript": "^0.2.
|
|
70
|
-
"@atscript/ui": "^0.1.
|
|
71
|
-
"@atscript/ui-fns": "^0.1.
|
|
72
|
-
"@moostjs/event-http": "^0.7.
|
|
73
|
-
"@moostjs/event-wf": "^0.7.
|
|
74
|
-
"moost": "^0.7.
|
|
75
|
-
"unplugin-atscript": "^0.2.
|
|
68
|
+
"@atscript/core": "^0.2.4",
|
|
69
|
+
"@atscript/typescript": "^0.2.4",
|
|
70
|
+
"@atscript/ui": "^0.1.164",
|
|
71
|
+
"@atscript/ui-fns": "^0.1.164",
|
|
72
|
+
"@moostjs/event-http": "^0.7.2",
|
|
73
|
+
"@moostjs/event-wf": "^0.7.2",
|
|
74
|
+
"moost": "^0.7.2",
|
|
75
|
+
"unplugin-atscript": "^0.2.4",
|
|
76
76
|
"wooks": "^0.8.0"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@atscript/moost-wf": "^0.1.
|
|
80
|
-
"@atscript/typescript": "^0.2.
|
|
81
|
-
"@moostjs/event-http": "^0.7.
|
|
82
|
-
"@moostjs/event-wf": "^0.7.
|
|
79
|
+
"@atscript/moost-wf": "^0.1.164",
|
|
80
|
+
"@atscript/typescript": "^0.2.4",
|
|
81
|
+
"@moostjs/event-http": "^0.7.2",
|
|
82
|
+
"@moostjs/event-wf": "^0.7.2",
|
|
83
83
|
"@wooksjs/event-core": "^0.8.0",
|
|
84
84
|
"@wooksjs/event-http": "^0.8.0",
|
|
85
85
|
"@wooksjs/http-body": "^0.8.0",
|
|
86
|
-
"moost": "^0.7.
|
|
86
|
+
"moost": "^0.7.2"
|
|
87
87
|
},
|
|
88
88
|
"peerDependenciesMeta": {
|
|
89
89
|
"@atscript/typescript": {
|