@aooth/auth-moost 0.1.85 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atscript/index.d.mts +42 -27
- package/dist/atscript/index.mjs +2 -2
- package/dist/forms-DDn6m5rP.mjs +474 -0
- package/dist/index.d.mts +432 -42
- package/dist/index.mjs +910 -348
- package/package.json +24 -24
- package/src/atscript/models/forms.as +26 -6
- package/src/atscript/models/forms.as.d.ts +43 -27
- package/dist/forms-B9-r2zT5.mjs +0 -474
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { C as
|
|
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-DDn6m5rP.mjs";
|
|
2
2
|
import { Controller, HandlerPaths, Inherit, Inject, InjectMoostLogger, Injectable, Intercept, MoostInit, Optional, Param, Resolve, TInterceptorPriority, defineAfterInterceptor, defineBeforeInterceptor, getMoostMate, useControllerContext, useLogger } from "moost";
|
|
3
|
-
import { AuthCredential, AuthError, RateLimitStoreMemory, RateLimiter, RateLimiter as RateLimiter$1, generateMagicLinkToken, generateOpaqueToken, parseRateLimitRule } from "@aooth/auth";
|
|
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
|
-
import { HttpError, useAuthorization, useCookies, useHeaders, useRequest, useResponse, useUrlParams } from "@wooksjs/event-http";
|
|
5
|
+
import { HttpError, resolveForwarded, useAuthorization, useCookies, useHeaders, useRequest, useResponse, useUrlParams } from "@wooksjs/event-http";
|
|
6
6
|
import { ArbacAction, ArbacResource, getArbacMate, useArbac } from "@aooth/arbac-moost";
|
|
7
7
|
import { FederatedIdentityStore, SEEN_DEVICES_DEFAULT_CAP, UserAuthError, UserService, generateMfaCode, generateTotpSecret, generateTotpUri, maskEmail, maskPhone, pickDefinedProfile, verifyTotpCode } from "@aooth/user";
|
|
8
8
|
import { Body, Delete, Get, HttpError as HttpError$1, Post, Query } from "@moostjs/event-http";
|
|
9
|
-
import { createHash, timingSafeEqual } from "node:crypto";
|
|
9
|
+
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
10
10
|
import { createAsHttpOutlet, finishWf, handleAsOutletRequest, useAtscriptWf } from "@atscript/moost-wf";
|
|
11
|
-
import { EncapsulatedStateStrategy, MoostWf, Step, StepRetriableError, StepTTL, Workflow, WorkflowParam, WorkflowSchema, createEmailOutlet, outletEmail, swapStrategy, useWfFinished, useWfState } from "@moostjs/event-wf";
|
|
11
|
+
import { EncapsulatedStateStrategy, MoostWf, Step, StepRetriableError, StepTTL, Workflow, WorkflowParam, WorkflowSchema, createEmailOutlet, outlet, outletEmail, swapStrategy, useWfFinished, useWfState } from "@moostjs/event-wf";
|
|
12
12
|
import { FederatedLoginService, OAuthError, OAuthProviderRegistry, generateRandomState, pkceChallengeFor } from "@aooth/idp";
|
|
13
13
|
import { ClientRegistrationError, DynamicClientRegistration, NoopOidcClaimsResolver, buildAuthorizationServerMetadata, buildAuthorizationServerMetadata as buildAuthorizationServerMetadata$1, buildProtectedResourceMetadata, buildWwwAuthenticateBearerChallenge, canonicalizeIssuer, canonicalizeIssuer as canonicalizeIssuer$1, tokenPolicyToIssueOptions } from "@aooth/auth/authz";
|
|
14
14
|
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
|
|
@@ -75,21 +75,26 @@ function resolveAuthOptions(opts = {}) {
|
|
|
75
75
|
sameSite: "lax",
|
|
76
76
|
httpOnly: true,
|
|
77
77
|
path: "/",
|
|
78
|
+
persistent: false,
|
|
78
79
|
...opts.cookie
|
|
79
80
|
};
|
|
81
|
+
const refreshCookie = {
|
|
82
|
+
name: "aooth_refresh",
|
|
83
|
+
secure: cookie.secure,
|
|
84
|
+
sameSite: cookie.sameSite,
|
|
85
|
+
httpOnly: cookie.httpOnly,
|
|
86
|
+
...cookie.domain !== void 0 && { domain: cookie.domain },
|
|
87
|
+
path: "/auth/refresh",
|
|
88
|
+
persistent: false,
|
|
89
|
+
...opts.refreshCookie
|
|
90
|
+
};
|
|
91
|
+
const enableCookie = opts.enableCookie ?? true;
|
|
80
92
|
return {
|
|
81
93
|
cookie,
|
|
82
|
-
refreshCookie
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
httpOnly: cookie.httpOnly,
|
|
87
|
-
...cookie.domain !== void 0 && { domain: cookie.domain },
|
|
88
|
-
path: "/auth/refresh",
|
|
89
|
-
...opts.refreshCookie
|
|
90
|
-
},
|
|
91
|
-
enableCookie: opts.enableCookie ?? true,
|
|
92
|
-
enableBearer: opts.enableBearer ?? true
|
|
94
|
+
refreshCookie,
|
|
95
|
+
enableCookie,
|
|
96
|
+
enableBearer: opts.enableBearer ?? true,
|
|
97
|
+
exposeTokensInBody: opts.exposeTokensInBody ?? !enableCookie
|
|
93
98
|
};
|
|
94
99
|
}
|
|
95
100
|
//#endregion
|
|
@@ -104,6 +109,15 @@ const authCredentialKey = key("auth.credential");
|
|
|
104
109
|
*/
|
|
105
110
|
const authOptionsKey = key("auth.options");
|
|
106
111
|
/**
|
|
112
|
+
* `Max-Age` for a persistent cookie carrying a token that expires at
|
|
113
|
+
* `expiresAt` (ms epoch). A unit-explicit `'<n>s'` string — wooks reads a
|
|
114
|
+
* bare number differently across versions.
|
|
115
|
+
*/
|
|
116
|
+
function persistFor(c, expiresAt) {
|
|
117
|
+
if (!c.persistent || expiresAt === void 0) return void 0;
|
|
118
|
+
return { maxAge: `${Math.max(0, Math.floor((expiresAt - Date.now()) / 1e3))}s` };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
107
121
|
* `sameSite` is upper-cased because wooks accepts `'Lax' | 'Strict' | 'None'`
|
|
108
122
|
* while `ResolvedAuthCookieConfig` stores lower-case for ergonomics.
|
|
109
123
|
*
|
|
@@ -174,12 +188,29 @@ const useAuth = defineWook((ctx) => {
|
|
|
174
188
|
if (!token && options.enableCookie) token = useCookies(ctx).getCookie(options.cookie.name) ?? void 0;
|
|
175
189
|
return token;
|
|
176
190
|
};
|
|
177
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Build the `cookies` map for `useWfFinished({ cookies })`. The outlet
|
|
193
|
+
* trigger's HTTP layer turns the entries into `Set-Cookie` headers, mirroring
|
|
194
|
+
* what `writeCookies()` does for the REST controller.
|
|
195
|
+
*/
|
|
196
|
+
const buildFinishedCookies = (issue) => {
|
|
178
197
|
const options = requireOptions();
|
|
179
|
-
if (!options.enableCookie) return;
|
|
198
|
+
if (!options.enableCookie) return void 0;
|
|
199
|
+
const cookies = { [options.cookie.name]: {
|
|
200
|
+
value: issue.accessToken,
|
|
201
|
+
options: cookieAttrsFrom(options.cookie, persistFor(options.cookie, issue.accessExpiresAt))
|
|
202
|
+
} };
|
|
203
|
+
if (issue.refreshToken) cookies[options.refreshCookie.name] = {
|
|
204
|
+
value: issue.refreshToken,
|
|
205
|
+
options: cookieAttrsFrom(options.refreshCookie, persistFor(options.refreshCookie, issue.refreshExpiresAt))
|
|
206
|
+
};
|
|
207
|
+
return cookies;
|
|
208
|
+
};
|
|
209
|
+
const writeCookies = (issue) => {
|
|
210
|
+
const cookies = buildFinishedCookies(issue);
|
|
211
|
+
if (!cookies) return;
|
|
180
212
|
const response = useResponse(current());
|
|
181
|
-
response.setCookie(
|
|
182
|
-
if (issue.refreshToken) response.setCookie(options.refreshCookie.name, issue.refreshToken, cookieAttrsFrom(options.refreshCookie));
|
|
213
|
+
for (const [name, cookie] of Object.entries(cookies)) response.setCookie(name, cookie.value, cookie.options);
|
|
183
214
|
};
|
|
184
215
|
const clearCookies = () => {
|
|
185
216
|
const options = requireOptions();
|
|
@@ -189,40 +220,24 @@ const useAuth = defineWook((ctx) => {
|
|
|
189
220
|
response.setCookie(options.refreshCookie.name, "", cookieAttrsFrom(options.refreshCookie, { maxAge: 0 }));
|
|
190
221
|
};
|
|
191
222
|
/**
|
|
192
|
-
* With `
|
|
193
|
-
* `accessExpiresAt` so clients can schedule a silent
|
|
194
|
-
* themselves travel only via the cookies set by
|
|
223
|
+
* With `exposeTokensInBody === false` (the cookie default) the response shape
|
|
224
|
+
* still carries `userId` + `accessExpiresAt` so clients can schedule a silent
|
|
225
|
+
* refresh, but the tokens themselves travel only via the cookies set by
|
|
226
|
+
* `writeCookies`.
|
|
195
227
|
*/
|
|
196
|
-
const buildLoginResponseFn = (userId, issue) => {
|
|
228
|
+
const buildLoginResponseFn = (userId, issue, opts) => {
|
|
197
229
|
const options = requireOptions();
|
|
230
|
+
const expose = opts?.exposeTokens ?? options.exposeTokensInBody;
|
|
198
231
|
return {
|
|
199
232
|
userId,
|
|
200
233
|
accessExpiresAt: issue.accessExpiresAt,
|
|
201
234
|
...issue.refreshExpiresAt !== void 0 && { refreshExpiresAt: issue.refreshExpiresAt },
|
|
202
|
-
...
|
|
235
|
+
...expose && {
|
|
203
236
|
accessToken: issue.accessToken,
|
|
204
237
|
...issue.refreshToken && { refreshToken: issue.refreshToken }
|
|
205
238
|
}
|
|
206
239
|
};
|
|
207
240
|
};
|
|
208
|
-
/**
|
|
209
|
-
* Build the `cookies` map for `useWfFinished({ cookies })`. The outlet
|
|
210
|
-
* trigger's HTTP layer turns the entries into `Set-Cookie` headers, mirroring
|
|
211
|
-
* what `writeCookies()` does for the REST controller.
|
|
212
|
-
*/
|
|
213
|
-
const buildFinishedCookies = (issue) => {
|
|
214
|
-
const options = requireOptions();
|
|
215
|
-
if (!options.enableCookie) return void 0;
|
|
216
|
-
const cookies = { [options.cookie.name]: {
|
|
217
|
-
value: issue.accessToken,
|
|
218
|
-
options: cookieAttrsFrom(options.cookie)
|
|
219
|
-
} };
|
|
220
|
-
if (issue.refreshToken) cookies[options.refreshCookie.name] = {
|
|
221
|
-
value: issue.refreshToken,
|
|
222
|
-
options: cookieAttrsFrom(options.refreshCookie)
|
|
223
|
-
};
|
|
224
|
-
return cookies;
|
|
225
|
-
};
|
|
226
241
|
const cookieAttrs = (extra) => {
|
|
227
242
|
return cookieAttrsFrom(requireOptions().cookie, extra);
|
|
228
243
|
};
|
|
@@ -378,6 +393,261 @@ const Public = () => {
|
|
|
378
393
|
*/
|
|
379
394
|
const UserId = () => Resolve(() => useAuth().getUserId());
|
|
380
395
|
//#endregion
|
|
396
|
+
//#region src/rate-limit/composables.ts
|
|
397
|
+
/**
|
|
398
|
+
* Internal: the governing decision for this event (across every policy
|
|
399
|
+
* evaluated so far), written by `rateLimitInterceptors`.
|
|
400
|
+
*/
|
|
401
|
+
const rateLimitDecisionKey = key("aooth.rateLimit.decision");
|
|
402
|
+
/** Internal: phases (`pre` / `post`) that already evaluated this event — the double-count guard. */
|
|
403
|
+
const rateLimitPhasesKey = key("aooth.rateLimit.phases");
|
|
404
|
+
/**
|
|
405
|
+
* Internal: named rate-limit subjects for this event — subject kind
|
|
406
|
+
* (`'user'`, `'tenant'`, …) → resolved caller identity, written via
|
|
407
|
+
* {@link setRateLimitSubject} and read by the post-guard rate-limit phase.
|
|
408
|
+
*/
|
|
409
|
+
const rateLimitSubjectsKey = key("aooth.rateLimit.subjects");
|
|
410
|
+
/**
|
|
411
|
+
* Supply the rate-limit subject for a named key strategy — the seam for
|
|
412
|
+
* custom IAMs / tenant resolvers. Call from GUARD-priority (or earlier)
|
|
413
|
+
* code; the value is used VERBATIM as the counter subject (include your own
|
|
414
|
+
* prefix, e.g. `iam:<sub>`) and always wins over the built-in `user` /
|
|
415
|
+
* `session` derivations. Full contract: docs `/moost/rate-limit`.
|
|
416
|
+
*/
|
|
417
|
+
function setRateLimitSubject(kind, subject, ctx = current()) {
|
|
418
|
+
const subjects = ctx.has(rateLimitSubjectsKey) ? ctx.get(rateLimitSubjectsKey) : {};
|
|
419
|
+
subjects[kind] = subject;
|
|
420
|
+
ctx.set(rateLimitSubjectsKey, subjects);
|
|
421
|
+
}
|
|
422
|
+
/** Read a named rate-limit subject set for this event (or `undefined`). */
|
|
423
|
+
function getRateLimitSubject(kind, ctx = current()) {
|
|
424
|
+
return ctx.has(rateLimitSubjectsKey) ? ctx.get(rateLimitSubjectsKey)[kind] : void 0;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Read the current event's rate-limit state. A plain function (not a cached
|
|
428
|
+
* wook) — it's a single slot read, and workflow child events inherit the
|
|
429
|
+
* HTTP parent's slot transparently.
|
|
430
|
+
*/
|
|
431
|
+
function useRateLimit(ctx = current()) {
|
|
432
|
+
return { decision: ctx.has(rateLimitDecisionKey) ? ctx.get(rateLimitDecisionKey) : null };
|
|
433
|
+
}
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src/rate-limit/interceptor.ts
|
|
436
|
+
/**
|
|
437
|
+
* Global interceptor PAIR enforcing `@RateLimit` metadata (RL.spec.md §5.2)
|
|
438
|
+
* — register with spread:
|
|
439
|
+
*
|
|
440
|
+
* ```ts
|
|
441
|
+
* app.applyGlobalInterceptors(
|
|
442
|
+
* authGuardInterceptor({ ... }),
|
|
443
|
+
* ...rateLimitInterceptors({ limiter, trustProxy: true }),
|
|
444
|
+
* )
|
|
445
|
+
* ```
|
|
446
|
+
*
|
|
447
|
+
* Two phases, because the primary target is public endpoints and
|
|
448
|
+
* `authGuardInterceptor` is NOT free there — with any `Authorization`
|
|
449
|
+
* header present it runs full credential validation before tolerating the
|
|
450
|
+
* failure on `@Public()` routes:
|
|
451
|
+
*
|
|
452
|
+
* - `BEFORE_GUARD` phase owns routes whose effective key strategy is
|
|
453
|
+
* `'ip'` or a custom resolver — floods are rejected before any
|
|
454
|
+
* token/credential work.
|
|
455
|
+
* - `AFTER_GUARD` phase owns `'user'` / `'auto'` keyed routes — those need
|
|
456
|
+
* the auth context `useAuth()` reads, and by definition target
|
|
457
|
+
* authenticated traffic where the guard must run anyway.
|
|
458
|
+
*
|
|
459
|
+
* Ownership is static per policy (from metadata/options): a route whose
|
|
460
|
+
* stacked policies mix both kinds is evaluated by both phases, each checking
|
|
461
|
+
* its own policies. A per-event phase marker guards against double counting
|
|
462
|
+
* when the pair is also attached per-controller (see {@link RateLimited}).
|
|
463
|
+
*
|
|
464
|
+
* On rejection: draft `RateLimit-*` headers + `Retry-After` are written to
|
|
465
|
+
* the accumulated response (they survive the throw — wooks renders the error
|
|
466
|
+
* onto the same `HttpResponse`), then `HttpError(429, message)` is thrown.
|
|
467
|
+
*/
|
|
468
|
+
function rateLimitInterceptors(opts) {
|
|
469
|
+
const defaultRules = opts?.rules?.map((r) => parseRateLimitRule(r));
|
|
470
|
+
const limiter = opts?.limiter ?? new RateLimiter$1();
|
|
471
|
+
const emitHeaders = opts?.headers ?? true;
|
|
472
|
+
const trustProxy = opts?.trustProxy ?? false;
|
|
473
|
+
const routeConfigs = /* @__PURE__ */ new WeakMap();
|
|
474
|
+
const resolveRouteConfig = (cc) => {
|
|
475
|
+
const ctor = cc.getController().constructor;
|
|
476
|
+
const method = String(cc.getMethod());
|
|
477
|
+
let byMethod = routeConfigs.get(ctor);
|
|
478
|
+
if (!byMethod) {
|
|
479
|
+
byMethod = /* @__PURE__ */ new Map();
|
|
480
|
+
routeConfigs.set(ctor, byMethod);
|
|
481
|
+
}
|
|
482
|
+
const cached = byMethod.get(method);
|
|
483
|
+
if (cached !== void 0) return cached;
|
|
484
|
+
const cMeta = cc.getControllerMeta();
|
|
485
|
+
const mMeta = cc.getMethodMeta();
|
|
486
|
+
let config = null;
|
|
487
|
+
const disabled = mMeta?.rateLimitDisabled ?? cMeta?.rateLimitDisabled ?? false;
|
|
488
|
+
const declared = mMeta?.rateLimitPolicies ?? cMeta?.rateLimitPolicies ?? (defaultRules && defaultRules.length > 0 ? [{ rules: defaultRules }] : void 0);
|
|
489
|
+
if (!disabled && declared && declared.length > 0) {
|
|
490
|
+
const baseScope = `${ctor.name}.${method}`;
|
|
491
|
+
const route = {
|
|
492
|
+
pre: [],
|
|
493
|
+
post: []
|
|
494
|
+
};
|
|
495
|
+
for (const [i, policy] of declared.entries()) {
|
|
496
|
+
const rawKey = policy.options?.key ?? opts?.key ?? "ip";
|
|
497
|
+
const keyStrategy = rawKey === "auto" ? "user" : rawKey;
|
|
498
|
+
const message = policy.options?.message ?? opts?.message;
|
|
499
|
+
route[typeof keyStrategy === "string" && keyStrategy !== "ip" ? "post" : "pre"].push({
|
|
500
|
+
rules: policy.rules,
|
|
501
|
+
keyStrategy,
|
|
502
|
+
scope: policy.options?.id ?? (i === 0 ? baseScope : `${baseScope}#${i}`),
|
|
503
|
+
...message !== void 0 && { defaultMessage: message },
|
|
504
|
+
policyHeader: policy.rules.map((p) => `${p.limit};w=${Math.max(1, Math.round(p.window / 1e3))}`).join(", ")
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
config = route;
|
|
508
|
+
}
|
|
509
|
+
byMethod.set(method, config);
|
|
510
|
+
return config;
|
|
511
|
+
};
|
|
512
|
+
const evaluate = async (phase) => {
|
|
513
|
+
const ctx = current();
|
|
514
|
+
if (ctx.get(eventTypeKey) !== "http") return;
|
|
515
|
+
const done = ctx.has(rateLimitPhasesKey) ? ctx.get(rateLimitPhasesKey) : [];
|
|
516
|
+
if (done.includes(phase)) return;
|
|
517
|
+
const config = resolveRouteConfig(useControllerContext(ctx));
|
|
518
|
+
if (!config) return;
|
|
519
|
+
const owned = config[phase];
|
|
520
|
+
if (owned.length === 0) return;
|
|
521
|
+
ctx.set(rateLimitPhasesKey, [...done, phase]);
|
|
522
|
+
const decisions = [];
|
|
523
|
+
const headers = [];
|
|
524
|
+
for (const policy of owned) {
|
|
525
|
+
const subject = await resolveSubject(policy.keyStrategy, trustProxy, ctx);
|
|
526
|
+
if (subject == null) continue;
|
|
527
|
+
decisions.push(await limiter.check(policy.scope, subject, policy.rules, { ...policy.defaultMessage !== void 0 && { defaultMessage: policy.defaultMessage } }));
|
|
528
|
+
headers.push(policy.policyHeader);
|
|
529
|
+
}
|
|
530
|
+
if (ctx.has(rateLimitDecisionKey)) decisions.unshift(ctx.get(rateLimitDecisionKey));
|
|
531
|
+
if (decisions.length === 0) return;
|
|
532
|
+
const decision = pickGoverning(decisions, (d) => !d.allowed);
|
|
533
|
+
ctx.set(rateLimitDecisionKey, decision);
|
|
534
|
+
const response = useResponse(ctx);
|
|
535
|
+
if (emitHeaders) {
|
|
536
|
+
const prior = response.getHeader("ratelimit-policy");
|
|
537
|
+
if (typeof prior === "string" && prior) headers.unshift(prior);
|
|
538
|
+
response.setHeader("ratelimit-limit", String(decision.limit));
|
|
539
|
+
response.setHeader("ratelimit-remaining", String(decision.remaining));
|
|
540
|
+
response.setHeader("ratelimit-reset", String(Math.ceil(decision.resetAfterMs / 1e3)));
|
|
541
|
+
response.setHeader("ratelimit-policy", headers.join(", "));
|
|
542
|
+
}
|
|
543
|
+
if (!decision.allowed) {
|
|
544
|
+
response.setHeader("retry-after", String(Math.ceil(decision.resetAfterMs / 1e3)));
|
|
545
|
+
throw new HttpError(429, decision.message ?? "Too many requests");
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
return [defineBeforeInterceptor(() => evaluate("pre"), TInterceptorPriority.BEFORE_GUARD), defineBeforeInterceptor(() => evaluate("post"), TInterceptorPriority.AFTER_GUARD)];
|
|
549
|
+
}
|
|
550
|
+
async function resolveSubject(strategy, trustProxy, ctx) {
|
|
551
|
+
if (typeof strategy === "function") return await strategy();
|
|
552
|
+
if (strategy !== "ip") {
|
|
553
|
+
const subject = getRateLimitSubject(strategy, ctx);
|
|
554
|
+
if (subject !== void 0) return subject;
|
|
555
|
+
const auth = strategy === "user" || strategy === "session" ? useAuth(ctx).getAuthContext() : null;
|
|
556
|
+
if (strategy === "user" && auth?.userId !== void 0) return `u:${auth.userId}`;
|
|
557
|
+
if (strategy === "session" && auth?.sessionId !== void 0) return `s:${auth.sessionId}`;
|
|
558
|
+
}
|
|
559
|
+
return `ip:${clientIp(trustProxy, ctx)}`;
|
|
560
|
+
}
|
|
561
|
+
/** Hop 0 (the socket peer) is the one trusted proxy. */
|
|
562
|
+
const trustOneHop = (_addr, hop) => hop < 1;
|
|
563
|
+
/**
|
|
564
|
+
* `trustProxy: true` resolves like wooks' deprecated `getIp({ trustProxy: true })`
|
|
565
|
+
* (one trusted hop, the right-most forwarded entry; `''` with no known peer)
|
|
566
|
+
* without its deprecation notice; otherwise the app's own `getIp()`.
|
|
567
|
+
*/
|
|
568
|
+
function clientIp(trustProxy, ctx) {
|
|
569
|
+
const req = useRequest(ctx);
|
|
570
|
+
return trustProxy ? resolveForwarded(req.raw, trustOneHop).ip : req.getIp();
|
|
571
|
+
}
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region src/rate-limit/mate.ts
|
|
574
|
+
function getRateLimitMate() {
|
|
575
|
+
return getMoostMate();
|
|
576
|
+
}
|
|
577
|
+
//#endregion
|
|
578
|
+
//#region src/rate-limit/decorator.ts
|
|
579
|
+
function RateLimit(...args) {
|
|
580
|
+
const mate = getRateLimitMate();
|
|
581
|
+
if (args.length === 1 && args[0] === false) return mate.decorate("rateLimitDisabled", true);
|
|
582
|
+
const inputs = [...args];
|
|
583
|
+
let options;
|
|
584
|
+
const last = inputs[inputs.length - 1];
|
|
585
|
+
if (typeof last === "object" && last !== null && !("limit" in last)) options = inputs.pop();
|
|
586
|
+
if (inputs.length === 0) throw new Error("@RateLimit requires at least one rule (or the literal `false` to opt out)");
|
|
587
|
+
const rules = inputs.map((r) => parseRateLimitRule(r));
|
|
588
|
+
const policy = options ? {
|
|
589
|
+
rules,
|
|
590
|
+
options
|
|
591
|
+
} : { rules };
|
|
592
|
+
return mate.decorate((meta) => {
|
|
593
|
+
meta.rateLimitPolicies = [policy, ...meta.rateLimitPolicies ?? []];
|
|
594
|
+
return meta;
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Decorator-factory sugar for attaching the `rateLimitInterceptors(opts)`
|
|
599
|
+
* PAIR to a specific controller or method instead of globally — the
|
|
600
|
+
* `AuthGuarded` counterpart. Attaching the pair (not one phase) matters:
|
|
601
|
+
* dropping the pre-guard def loses flood protection for ip-keyed routes,
|
|
602
|
+
* dropping the post-guard def silently disables `key: 'user'` routes.
|
|
603
|
+
*/
|
|
604
|
+
function RateLimited(opts) {
|
|
605
|
+
const [pre, post] = rateLimitInterceptors(opts);
|
|
606
|
+
const interceptPre = Intercept(pre);
|
|
607
|
+
const interceptPost = Intercept(post);
|
|
608
|
+
return ((target, key, descriptor) => {
|
|
609
|
+
interceptPre(target, key, descriptor);
|
|
610
|
+
interceptPost(target, key, descriptor);
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
//#endregion
|
|
614
|
+
//#region src/workflow/invite-outlet.ts
|
|
615
|
+
/** Name of the outlet `AuthWorkflow` pauses on for `inviteDelivery: 'deliver' | 'return-link'`. */
|
|
616
|
+
const INVITE_OUTLET = "invite";
|
|
617
|
+
const pendingInviteLinkKey = key("aooth.invite.pendingLink");
|
|
618
|
+
/**
|
|
619
|
+
* Trigger side: reserve the slot on the HTTP event before the workflow runs.
|
|
620
|
+
* Workflow steps run in a child event, and a child's write lands in the
|
|
621
|
+
* nearest context already holding the slot — so the step's callback becomes
|
|
622
|
+
* visible to the `invite` outlet, which runs back on the HTTP event.
|
|
623
|
+
*/
|
|
624
|
+
function reservePendingInviteLink() {
|
|
625
|
+
current().set(pendingInviteLinkKey, null);
|
|
626
|
+
}
|
|
627
|
+
/** Step side: register what to do with the token once the pause is persisted. */
|
|
628
|
+
function setPendingInviteLink(fn) {
|
|
629
|
+
current().set(pendingInviteLinkKey, fn);
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* The `invite` outlet (registered by default on `WfTriggerProvider`): hands
|
|
633
|
+
* the resume token to the callback the `send-email` step registered, which
|
|
634
|
+
* builds the link and delivers it (`'deliver'`) or returns it to the issuer
|
|
635
|
+
* (`'return-link'`). The token never rides the response on its own.
|
|
636
|
+
*/
|
|
637
|
+
function createInviteOutlet() {
|
|
638
|
+
return {
|
|
639
|
+
name: INVITE_OUTLET,
|
|
640
|
+
tokenDelivery: "out-of-band",
|
|
641
|
+
async deliver(_request, token) {
|
|
642
|
+
const ctx = current();
|
|
643
|
+
const pending = ctx.has(pendingInviteLinkKey) ? ctx.get(pendingInviteLinkKey) : null;
|
|
644
|
+
if (!pending) throw new Error("The invite outlet has no pending link — the trigger must run through WfTriggerProvider.handle()");
|
|
645
|
+
ctx.set(pendingInviteLinkKey, null);
|
|
646
|
+
return { response: await pending(token) };
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
//#endregion
|
|
381
651
|
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateMetadata.js
|
|
382
652
|
function __decorateMetadata(k, v) {
|
|
383
653
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
@@ -410,10 +680,39 @@ function __decorateMetadata(k, v) {
|
|
|
410
680
|
function deriveWfStateSecret(secret) {
|
|
411
681
|
return createHash("sha256").update(secret).digest();
|
|
412
682
|
}
|
|
683
|
+
/** One canonical workflow-id form for allow-list matching: no leading `/`. */
|
|
684
|
+
function normalizeWfId(id) {
|
|
685
|
+
return id.replace(/^\/+/, "");
|
|
686
|
+
}
|
|
687
|
+
function notAllowed(id) {
|
|
688
|
+
return new HttpError(403, `Workflow '${normalizeWfId(id)}' is not allowed`);
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Wrap a strategy so a resume is checked against the allow list BEFORE the
|
|
692
|
+
* state is consumed: the state is peeked (`retrieve`), refused with 403 when
|
|
693
|
+
* its workflow is not allowed on this route (the token stays usable on its
|
|
694
|
+
* own route), and only then consumed.
|
|
695
|
+
*/
|
|
696
|
+
function guardStrategy(strategy, permits) {
|
|
697
|
+
return {
|
|
698
|
+
persist: (state, options, overrides) => strategy.persist(state, options, overrides),
|
|
699
|
+
retrieve: (token) => strategy.retrieve(token),
|
|
700
|
+
consume: async (token) => {
|
|
701
|
+
const peeked = await strategy.retrieve(token);
|
|
702
|
+
if (peeked && !permits(peeked.schemaId)) throw notAllowed(peeked.schemaId);
|
|
703
|
+
return strategy.consume(token);
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
413
707
|
let WfTriggerProvider = class WfTriggerProvider {
|
|
414
708
|
wf;
|
|
415
709
|
auth;
|
|
416
|
-
|
|
710
|
+
/**
|
|
711
|
+
* Outlets the trigger can pause on: HTTP (forms) and `invite` (the link of
|
|
712
|
+
* `AuthWorkflowOpts.inviteDelivery: 'deliver' | 'return-link'`). Append an
|
|
713
|
+
* `email` outlet (`createAuthEmailOutlet`) for the default invite delivery.
|
|
714
|
+
*/
|
|
715
|
+
outlets = [createAsHttpOutlet(), createInviteOutlet()];
|
|
417
716
|
token = {
|
|
418
717
|
read: [
|
|
419
718
|
"body",
|
|
@@ -463,23 +762,42 @@ let WfTriggerProvider = class WfTriggerProvider {
|
|
|
463
762
|
};
|
|
464
763
|
return this.cachedState;
|
|
465
764
|
}
|
|
765
|
+
/**
|
|
766
|
+
* Handle one trigger request. `allow` lists the workflow ids this route may
|
|
767
|
+
* START and RESUME (matched without a leading `/`); omitted = unrestricted,
|
|
768
|
+
* `[]` = deny all. A state token minted for a workflow outside the list is
|
|
769
|
+
* refused with 403 before it is consumed.
|
|
770
|
+
*/
|
|
466
771
|
async handle(opts = {}) {
|
|
467
772
|
const wfApp = this.wf.getWfApp();
|
|
773
|
+
const allowed = opts.allow && new Set(opts.allow.map(normalizeWfId));
|
|
774
|
+
const permits = (schemaId) => !allowed || allowed.has(normalizeWfId(schemaId));
|
|
775
|
+
const registry = this.stateRegistry();
|
|
776
|
+
const stateConfig = allowed ? {
|
|
777
|
+
default: registry.default,
|
|
778
|
+
strategies: Object.fromEntries(Object.entries(registry.strategies).map(([name, strategy]) => [name, guardStrategy(strategy, permits)]))
|
|
779
|
+
} : registry;
|
|
468
780
|
const deps = {
|
|
469
|
-
start: (schemaId, context, o) =>
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
781
|
+
start: (schemaId, context, o) => {
|
|
782
|
+
if (!permits(schemaId)) throw notAllowed(schemaId);
|
|
783
|
+
return wfApp.start(schemaId, context, {
|
|
784
|
+
input: o?.input,
|
|
785
|
+
eventContext: o?.eventContext ?? current(),
|
|
786
|
+
strategy: o?.strategy
|
|
787
|
+
});
|
|
788
|
+
},
|
|
789
|
+
resume: (state, o) => {
|
|
790
|
+
if (!permits(state.schemaId)) throw notAllowed(state.schemaId);
|
|
791
|
+
return wfApp.resume(state, {
|
|
792
|
+
input: o?.input,
|
|
793
|
+
eventContext: o?.eventContext ?? current(),
|
|
794
|
+
strategy: o?.strategy
|
|
795
|
+
});
|
|
796
|
+
}
|
|
479
797
|
};
|
|
798
|
+
reservePendingInviteLink();
|
|
480
799
|
return handleAsOutletRequest({
|
|
481
|
-
|
|
482
|
-
state: this.stateRegistry(),
|
|
800
|
+
state: stateConfig,
|
|
483
801
|
outlets: this.outlets,
|
|
484
802
|
token: opts.token ?? this.token
|
|
485
803
|
}, deps);
|
|
@@ -562,7 +880,7 @@ function oauthCsrfCookieAttrs(opts) {
|
|
|
562
880
|
secure: opts.secure,
|
|
563
881
|
sameSite: "Lax",
|
|
564
882
|
path: opts.path ?? "/",
|
|
565
|
-
maxAge:
|
|
883
|
+
maxAge: `${opts.maxAgeSec ?? 600}s`
|
|
566
884
|
};
|
|
567
885
|
}
|
|
568
886
|
/**
|
|
@@ -751,6 +1069,79 @@ let OAuthRuntime = class OAuthRuntime {
|
|
|
751
1069
|
};
|
|
752
1070
|
OAuthRuntime = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [typeof OAuthProviderRegistry === "undefined" ? Object : OAuthProviderRegistry, typeof FederatedLoginService === "undefined" ? Object : FederatedLoginService])], OAuthRuntime);
|
|
753
1071
|
//#endregion
|
|
1072
|
+
//#region src/workflow/auth-messages.ts
|
|
1073
|
+
/**
|
|
1074
|
+
* Code-keyed catalogue of every user-facing text `AuthWorkflow` produces —
|
|
1075
|
+
* form errors, banners, finish envelopes and button labels. Templates are
|
|
1076
|
+
* English; `{name}` placeholders are filled from the message params.
|
|
1077
|
+
*
|
|
1078
|
+
* Override per app with `AuthWorkflowOpts.messages` (a partial map, or a
|
|
1079
|
+
* function that receives the code and params and returns the text — e.g. a
|
|
1080
|
+
* lookup in your own i18n library), or override `AuthWorkflow.msg()`.
|
|
1081
|
+
*/
|
|
1082
|
+
const AOOTH_MESSAGES = {
|
|
1083
|
+
INVALID_CREDENTIALS: "Invalid credentials",
|
|
1084
|
+
ACCOUNT_LOCKED: "Account locked, please try again later",
|
|
1085
|
+
INVALID_PASSWORD: "Invalid password",
|
|
1086
|
+
INCORRECT_PASSWORD: "Incorrect password",
|
|
1087
|
+
SESSION_LIMIT_REACHED: "Session limit reached",
|
|
1088
|
+
PASSWORD_CHANGED_SIGN_IN_AGAIN: "Your password was changed. Please sign in again.",
|
|
1089
|
+
INVALID_CODE: "Invalid code",
|
|
1090
|
+
/** Params: `seconds`. */
|
|
1091
|
+
RESEND_WAIT: "Please wait {seconds}s before requesting a new code.",
|
|
1092
|
+
/** Params: `seconds`. */
|
|
1093
|
+
RESEND_WAIT_ANOTHER: "Please wait {seconds}s before requesting another code",
|
|
1094
|
+
/** Params: `seconds`, `channel` (`SMS` / `email`). */
|
|
1095
|
+
RESEND_WAIT_CHANNEL: "Please wait {seconds}s before requesting another {channel} code",
|
|
1096
|
+
TOTP_RESEND_NOT_APPLICABLE: "Resend is not applicable for TOTP",
|
|
1097
|
+
UNKNOWN_MFA_METHOD: "Unknown MFA method",
|
|
1098
|
+
UNKNOWN_METHOD: "Unknown method",
|
|
1099
|
+
METHOD_UNAVAILABLE: "That method isn't available",
|
|
1100
|
+
METHOD_NOT_CHANGEABLE: "That method can't be changed here.",
|
|
1101
|
+
KEEP_ONE_MFA_METHOD: "You must keep at least one two-factor method.",
|
|
1102
|
+
CHOOSE_OPTION: "Choose an option",
|
|
1103
|
+
ALL_MFA_METHODS_SET_UP: "You've already set up every available authentication method.",
|
|
1104
|
+
NO_MFA_CHANGES: "No changes were made to your two-factor methods.",
|
|
1105
|
+
PASSWORDS_DO_NOT_MATCH: "Passwords do not match",
|
|
1106
|
+
PASSWORD_CHANGE_TOO_RECENT: "You changed your password too recently. Please try again later.",
|
|
1107
|
+
PASSWORD_CHANGED: "Your password has been changed.",
|
|
1108
|
+
PASSWORD_UPDATED_REDIRECTING: "Password updated. Redirecting to sign-in…",
|
|
1109
|
+
PASSWORD_UPDATED_STILL_LOCKED: "Password updated, but your account is still locked. Contact an administrator to regain access.",
|
|
1110
|
+
RECOVERY_INSTRUCTIONS_SENT: "If an account exists, you will receive instructions.",
|
|
1111
|
+
SIGNUP_DISABLED: "Self-signup is currently disabled.",
|
|
1112
|
+
ALREADY_HAVE_ACCOUNT: "You already have an account. Please sign in.",
|
|
1113
|
+
ACCOUNT_LINKED: "Account linked.",
|
|
1114
|
+
INVALID_ROLE: "Invalid role",
|
|
1115
|
+
INVITE_ALREADY_PENDING: "Invite already pending",
|
|
1116
|
+
USER_ALREADY_EXISTS: "User already exists",
|
|
1117
|
+
DUPLICATE_INVITE_REJECTED: "Duplicate invite rejected",
|
|
1118
|
+
INVITE_CANCELLED: "This invite has been cancelled",
|
|
1119
|
+
INVITE_REPLACED: "This invite was replaced by a newer one",
|
|
1120
|
+
INVITE_ALREADY_ACCEPTED: "This invite was already accepted.",
|
|
1121
|
+
CHOOSE_USERNAME_TAKEN: "This username is taken",
|
|
1122
|
+
USERNAME_NOT_ALLOWED: "This username is not allowed",
|
|
1123
|
+
AUTHZ_EXPIRED: "Authorization request expired. Please try again.",
|
|
1124
|
+
AUTHZ_BROWSER_MISMATCH: "This authorization could not be verified for your browser. Please start again.",
|
|
1125
|
+
AUTHZ_FAILED: "Authorization could not be completed. Please start again.",
|
|
1126
|
+
GO_TO_SIGN_IN: "Go to sign-in",
|
|
1127
|
+
BACK_TO_SIGN_IN: "Back to sign-in",
|
|
1128
|
+
REQUEST_NEW_INVITE: "Request a new invite",
|
|
1129
|
+
BACK: "Back",
|
|
1130
|
+
GO_NOW: "Go now"
|
|
1131
|
+
};
|
|
1132
|
+
/** Fill `{name}` placeholders from `params`; unknown placeholders are kept. */
|
|
1133
|
+
function renderAoothMessage(template, params = {}) {
|
|
1134
|
+
return template.replace(/\{(\w+)\}/g, (whole, name) => Object.prototype.hasOwnProperty.call(params, name) ? String(params[name]) : whole);
|
|
1135
|
+
}
|
|
1136
|
+
/** Resolve `code` through `messages` (when given), falling back to the English template. */
|
|
1137
|
+
function resolveAoothMessage(code, params = {}, messages) {
|
|
1138
|
+
if (typeof messages === "function") {
|
|
1139
|
+
const text = messages(code, params);
|
|
1140
|
+
if (text !== void 0) return text;
|
|
1141
|
+
} else if (messages?.[code] !== void 0) return renderAoothMessage(messages[code], params);
|
|
1142
|
+
return renderAoothMessage(AOOTH_MESSAGES[code], params);
|
|
1143
|
+
}
|
|
1144
|
+
//#endregion
|
|
754
1145
|
//#region src/workflow/auth-workflow.schemas.ts
|
|
755
1146
|
/**
|
|
756
1147
|
* Canonical OTP send-then-check pair. Used by:
|
|
@@ -906,6 +1297,9 @@ const mfaLoopSchema = [{ id: "prepare-mfa" }, {
|
|
|
906
1297
|
/**
|
|
907
1298
|
* Forced password change — used by login.flow + invite.start (NOT recovery — recovery's
|
|
908
1299
|
* gating differs: gated directly on `otp.verified`, NOT `newPasswordRequired`).
|
|
1300
|
+
* login.flow revokes the user's existing sessions after its MFA loop (gated on
|
|
1301
|
+
* `ctx.passwordChanged`), never here: the old password alone must not be
|
|
1302
|
+
* enough to sign the user out everywhere.
|
|
909
1303
|
*/
|
|
910
1304
|
const passwordPhaseSchema = [{
|
|
911
1305
|
condition: (ctx) => !!ctx.newPasswordRequired,
|
|
@@ -971,6 +1365,7 @@ const DEFAULT_FORMS = {
|
|
|
971
1365
|
pincode: PincodeForm,
|
|
972
1366
|
setPassword: SetPasswordForm,
|
|
973
1367
|
changePassword: ChangePasswordForm,
|
|
1368
|
+
inviteChooseUsername: InviteChooseUsernameForm,
|
|
974
1369
|
proveControl: ProveControlForm,
|
|
975
1370
|
proveControlOtp: ProveControlOtpForm,
|
|
976
1371
|
termsBump: TermsBumpForm,
|
|
@@ -979,6 +1374,28 @@ const DEFAULT_FORMS = {
|
|
|
979
1374
|
signup: SignupForm,
|
|
980
1375
|
authzConsent: AuthorizeConsentForm
|
|
981
1376
|
};
|
|
1377
|
+
/**
|
|
1378
|
+
* Process-wide warn-once latches (module level: `AuthWorkflow` may be
|
|
1379
|
+
* event-scoped, and a per-instance flag would warn on every request).
|
|
1380
|
+
*/
|
|
1381
|
+
const warnedOnce = {
|
|
1382
|
+
openInviteWhitelist: false,
|
|
1383
|
+
crossIssuerReuse: false
|
|
1384
|
+
};
|
|
1385
|
+
/** Sliding lifetime of a shadow failure counter (and of a shadow "permanent" lock). */
|
|
1386
|
+
const SHADOW_TTL_MS = 720 * 60 * 6e4;
|
|
1387
|
+
/** Key prefix of an active shadow lock (kept longest by the default store). */
|
|
1388
|
+
const SHADOW_LOCK_PREFIX = "shadow-lock:";
|
|
1389
|
+
/** Cap of the default (process-wide, in-memory) shadow-lockout store. */
|
|
1390
|
+
const SHADOW_STORE_MAX_ENTRIES = 5e4;
|
|
1391
|
+
let sharedShadowStore;
|
|
1392
|
+
function defaultShadowStore() {
|
|
1393
|
+
sharedShadowStore ??= new RateLimitStoreMemory$1({
|
|
1394
|
+
maxEntries: SHADOW_STORE_MAX_ENTRIES,
|
|
1395
|
+
evictLast: (key) => key.startsWith(SHADOW_LOCK_PREFIX)
|
|
1396
|
+
});
|
|
1397
|
+
return sharedShadowStore;
|
|
1398
|
+
}
|
|
982
1399
|
function mergeAuthWorkflowOpts(opts) {
|
|
983
1400
|
const deviceTrust = {
|
|
984
1401
|
cookieName: "aooth_trusted_device",
|
|
@@ -991,6 +1408,12 @@ function mergeAuthWorkflowOpts(opts) {
|
|
|
991
1408
|
autoLoginOnRecover: opts.autoLoginOnRecover ?? false,
|
|
992
1409
|
invitableRoles: opts.invitableRoles ?? [],
|
|
993
1410
|
allowAnyInviteRole: opts.allowAnyInviteRole ?? false,
|
|
1411
|
+
inviteDelivery: opts.inviteDelivery ?? "outlet-email",
|
|
1412
|
+
...opts.inviteLinkUrl && { inviteLinkUrl: opts.inviteLinkUrl },
|
|
1413
|
+
inviteUsername: opts.inviteUsername ?? "email",
|
|
1414
|
+
...opts.messages !== void 0 && { messages: opts.messages },
|
|
1415
|
+
lockoutDisclosure: opts.lockoutDisclosure ?? "uniform",
|
|
1416
|
+
lockoutShadowStore: opts.lockoutShadowStore ?? defaultShadowStore(),
|
|
994
1417
|
mfa: {
|
|
995
1418
|
pincodeLength: opts.mfa?.pincodeLength ?? 6,
|
|
996
1419
|
pincodeTtlMs: opts.mfa?.pincodeTtlMs ?? 300 * 1e3,
|
|
@@ -1108,15 +1531,16 @@ function parseInviteRoles(input) {
|
|
|
1108
1531
|
*/
|
|
1109
1532
|
function buildInviteAlreadyAcceptedEnvelope(opts) {
|
|
1110
1533
|
const altUrl = opts.alreadyAcceptedRedirectUrl;
|
|
1534
|
+
const msg = (code) => resolveAoothMessage(code, {}, opts.messages);
|
|
1111
1535
|
return {
|
|
1112
1536
|
message: {
|
|
1113
1537
|
level: "info",
|
|
1114
|
-
text: "
|
|
1538
|
+
text: msg("INVITE_ALREADY_ACCEPTED")
|
|
1115
1539
|
},
|
|
1116
1540
|
next: {
|
|
1117
1541
|
trigger: "manual",
|
|
1118
1542
|
primary: {
|
|
1119
|
-
label: "
|
|
1543
|
+
label: msg("GO_TO_SIGN_IN"),
|
|
1120
1544
|
action: {
|
|
1121
1545
|
type: "redirect",
|
|
1122
1546
|
target: opts.loginUrl,
|
|
@@ -1124,7 +1548,7 @@ function buildInviteAlreadyAcceptedEnvelope(opts) {
|
|
|
1124
1548
|
}
|
|
1125
1549
|
},
|
|
1126
1550
|
...altUrl && { options: [{
|
|
1127
|
-
label: "
|
|
1551
|
+
label: msg("REQUEST_NEW_INVITE"),
|
|
1128
1552
|
action: {
|
|
1129
1553
|
type: "redirect",
|
|
1130
1554
|
target: altUrl,
|
|
@@ -1148,6 +1572,12 @@ const ALT_HANDLED = Symbol("ALT_HANDLED");
|
|
|
1148
1572
|
* re-decorating the step in a subclass.
|
|
1149
1573
|
*/
|
|
1150
1574
|
const INVITE_LINK_TTL_MS = 10080 * 60 * 1e3;
|
|
1575
|
+
/** One canonical form of a chosen username: Unicode NFKC, surrounding whitespace trimmed. */
|
|
1576
|
+
function normalizeUsername(raw) {
|
|
1577
|
+
return String(raw).normalize("NFKC").trim();
|
|
1578
|
+
}
|
|
1579
|
+
/** Loose email shape — `account.verifiedEmail` is only recorded for a value that looks like one. */
|
|
1580
|
+
const EMAIL_SHAPE = /^[^@\s]+@[^@\s]+\.[^@\s]+$/;
|
|
1151
1581
|
/**
|
|
1152
1582
|
* Read a single field from the raw wf input envelope without validating
|
|
1153
1583
|
* against any form schema. Used by alt-action handlers that carry a payload
|
|
@@ -1205,12 +1635,21 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
1205
1635
|
users;
|
|
1206
1636
|
auth;
|
|
1207
1637
|
consentStore;
|
|
1208
|
-
/**
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1638
|
+
/** The invite context every invite hook receives: issuer, app context, extra form fields. */
|
|
1639
|
+
inviteHookInput(ctx) {
|
|
1640
|
+
const admin = ctx.admin;
|
|
1641
|
+
return {
|
|
1642
|
+
...admin?.invitedBy && { invitedBy: admin.invitedBy },
|
|
1643
|
+
...admin?.app && { app: admin.app },
|
|
1644
|
+
...admin?.form && { form: admin.form }
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
/** Warn once per process when a `'reuse'` re-invite crosses issuers. */
|
|
1648
|
+
warnCrossIssuerReuse() {
|
|
1649
|
+
if (warnedOnce.crossIssuerReuse) return;
|
|
1650
|
+
warnedOnce.crossIssuerReuse = true;
|
|
1651
|
+
useLogger("aooth:auth", current()).warn("A re-invite ('reuse') took over a pending invite issued by another user — its roles and extras were replaced and the earlier link no longer works. Override `duplicateInviteCheck()` (it receives `invitedBy`, `app` and `pending`) to refuse it.");
|
|
1652
|
+
}
|
|
1214
1653
|
constructor(opts, users, auth, consentStore) {
|
|
1215
1654
|
this.opts = mergeAuthWorkflowOpts(opts);
|
|
1216
1655
|
this.users = users;
|
|
@@ -1218,6 +1657,23 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
1218
1657
|
this.consentStore = consentStore;
|
|
1219
1658
|
}
|
|
1220
1659
|
/**
|
|
1660
|
+
* Resolve a user-facing text by code (`AOOTH_MESSAGES`) through
|
|
1661
|
+
* `opts.messages`. Every form error, banner, finish message and button label
|
|
1662
|
+
* the workflow produces goes through here — override for full control
|
|
1663
|
+
* (e.g. to call your i18n library with the request's locale).
|
|
1664
|
+
*/
|
|
1665
|
+
msg(code, params) {
|
|
1666
|
+
return resolveAoothMessage(code, params, this.opts.messages);
|
|
1667
|
+
}
|
|
1668
|
+
/** An `HttpError` whose body carries the message `code` next to its (resolved) text. */
|
|
1669
|
+
httpError(status, code) {
|
|
1670
|
+
return new HttpError$1(status, {
|
|
1671
|
+
message: this.msg(code),
|
|
1672
|
+
statusCode: status,
|
|
1673
|
+
code
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1221
1677
|
* Unified outbound dispatch hook for direct synchronous deliveries
|
|
1222
1678
|
* (MFA / recovery / enrollment pincodes, new-device notices). NOT used for
|
|
1223
1679
|
* resume-token flows — the invite magic link is emitted via the wf engine's
|
|
@@ -1362,6 +1818,16 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
1362
1818
|
return [];
|
|
1363
1819
|
}
|
|
1364
1820
|
/**
|
|
1821
|
+
* App context of an invite, resolved once when the issue phase starts
|
|
1822
|
+
* (`init-invite-admin`) from the trigger's START input (`{ wfid, input: {
|
|
1823
|
+
* formData } }` — the `startFormData` argument) and the session. Return
|
|
1824
|
+
* e.g. `{ tenantId }`; the value is kept server-side as `ctx.admin.app` and
|
|
1825
|
+
* handed to `prepareUser`, `inferAdminRoles` and `duplicateInviteCheck`.
|
|
1826
|
+
* Throw an `HttpError` to refuse the invite (e.g. the issuer may not invite
|
|
1827
|
+
* into that tenant). Default: `undefined` (no app context).
|
|
1828
|
+
*/
|
|
1829
|
+
resolveInviteContext(_ctx, _startFormData) {}
|
|
1830
|
+
/**
|
|
1365
1831
|
* Override the structural duplicate rule for `admin-form`. Default: a row
|
|
1366
1832
|
* still parked on `account.pendingInvitation` → `'reuse'` (re-invite:
|
|
1367
1833
|
* `create-user` refreshes the existing record in place and `send-email`
|
|
@@ -1371,7 +1837,11 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
1371
1837
|
* Multi-tenant apps that allow re-inviting the same email into a different
|
|
1372
1838
|
* tenant override to `'allow'`. Apps that want the strict legacy behavior
|
|
1373
1839
|
* ("Invite already pending" error on a duplicate invite of a pending user)
|
|
1374
|
-
* return `'reject'` for pending rows.
|
|
1840
|
+
* return `'reject'` for pending rows. Compare `invitedBy` / `app` with
|
|
1841
|
+
* `pending` and `existingUser` to refuse taking over another issuer's (or
|
|
1842
|
+
* tenant's) pending invite. On `'reuse'` the row's roles and extras are
|
|
1843
|
+
* REPLACED by this invite's, and every link issued before is superseded
|
|
1844
|
+
* (answers 410 "replaced").
|
|
1375
1845
|
*/
|
|
1376
1846
|
duplicateInviteCheck(input) {
|
|
1377
1847
|
if (input.existingUser?.account?.pendingInvitation) return "reuse";
|
|
@@ -1631,7 +2101,8 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
1631
2101
|
* successful change (OWASP Session Management) and applies NO rate limit —
|
|
1632
2102
|
* current-password re-entry (enforced by `UserService.changePassword`) is the
|
|
1633
2103
|
* primary protection, not throttling. Customers override to add a min-interval
|
|
1634
|
-
* (`rateLimit.minIntervalMs`) or to keep other sessions alive.
|
|
2104
|
+
* (`rateLimit.minIntervalMs`) or to keep other sessions alive. The session the
|
|
2105
|
+
* change was made from is always ended (see `finish-change-password`).
|
|
1635
2106
|
*
|
|
1636
2107
|
* Whether the flow may be STARTED at all is governed by arbac on the trigger
|
|
1637
2108
|
* route (deny the `change-password` action to forbid it for SSO-only orgs) —
|
|
@@ -2063,6 +2534,8 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
2063
2534
|
"policies"
|
|
2064
2535
|
]);
|
|
2065
2536
|
if (sub) pub.password = sub;
|
|
2537
|
+
const mismatch = this.msg("PASSWORDS_DO_NOT_MATCH");
|
|
2538
|
+
if (mismatch !== AOOTH_MESSAGES.PASSWORDS_DO_NOT_MATCH) pub.messages = { PASSWORDS_DO_NOT_MATCH: mismatch };
|
|
2066
2539
|
}
|
|
2067
2540
|
if (ctx.admin) {
|
|
2068
2541
|
const sub = pickDefined(ctx.admin, ["availableRoles"]);
|
|
@@ -2469,14 +2942,18 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
2469
2942
|
await this.seedChannelState(ctx, user);
|
|
2470
2943
|
return true;
|
|
2471
2944
|
}
|
|
2472
|
-
initInviteAdmin(ctx) {
|
|
2945
|
+
async initInviteAdmin(ctx) {
|
|
2473
2946
|
ctx.autoLogin = this.opts.autoLoginOnInvite;
|
|
2947
|
+
const startFormData = useWfState().input()?.formData;
|
|
2948
|
+
const app = await this.resolveInviteContext(ctx, startFormData);
|
|
2949
|
+
if (app !== void 0) (ctx.admin ??= {}).app = app;
|
|
2474
2950
|
}
|
|
2475
2951
|
initInviteAccept(ctx) {
|
|
2476
2952
|
ctx.isFirstLogin = true;
|
|
2477
2953
|
ctx.newPasswordRequired = true;
|
|
2478
2954
|
ctx.autoLogin = this.opts.autoLoginOnInvite;
|
|
2479
2955
|
(ctx.password ??= {}).changeReason = "initial";
|
|
2956
|
+
if (this.opts.inviteUsername === "choose") (ctx.accept ??= {}).chooseUsername = true;
|
|
2480
2957
|
}
|
|
2481
2958
|
initRecovery(ctx) {
|
|
2482
2959
|
ctx.autoLogin = this.opts.autoLoginOnRecover;
|
|
@@ -2567,6 +3044,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
2567
3044
|
try {
|
|
2568
3045
|
const result = await this.users.login(input.username, input.password, this.lockoutOverride(ctx));
|
|
2569
3046
|
ctx.subject = result.user.id;
|
|
3047
|
+
ctx.passwordStamp = result.user.password.lastChanged ?? 0;
|
|
2570
3048
|
ctx.loginRecorded = true;
|
|
2571
3049
|
swapStrategy("store");
|
|
2572
3050
|
if (ctx.guards?.passwordInitial && result.user.password.isInitial) ctx.isPasswordInitial = true;
|
|
@@ -2587,13 +3065,48 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
2587
3065
|
if (!ctx.notice?.email) await this.seedCorrespondenceEmail(ctx, result.user);
|
|
2588
3066
|
} catch (err) {
|
|
2589
3067
|
if (err instanceof UserAuthError) {
|
|
2590
|
-
|
|
2591
|
-
throw this.throwPublic(ctx, wf, { formMessage: "
|
|
3068
|
+
const locked = await this.failedLoginReadsLocked(ctx, err, input.username);
|
|
3069
|
+
throw this.throwPublic(ctx, wf, { formMessage: this.msg(locked ? "ACCOUNT_LOCKED" : "INVALID_CREDENTIALS") });
|
|
2592
3070
|
}
|
|
2593
3071
|
throw err;
|
|
2594
3072
|
}
|
|
2595
3073
|
}
|
|
2596
3074
|
/**
|
|
3075
|
+
* Whether a failed password sign-in answers "Account locked" — see
|
|
3076
|
+
* `AuthWorkflowOpts.lockoutDisclosure`. Under `'uniform'` an unknown or
|
|
3077
|
+
* inactive handle keeps a shadow failure counter in `lockoutShadowStore`
|
|
3078
|
+
* that mirrors a real account exactly: every failure counts (the counter is
|
|
3079
|
+
* not reset when it trips — like `failedLoginAttempts`), a lock starts when
|
|
3080
|
+
* `failures >= threshold` and none is active, the tripping attempt still
|
|
3081
|
+
* reads "Invalid credentials", and a permanent lock stays on while probed.
|
|
3082
|
+
* Keys are a hash of the normalised handle (bounded size); the counter
|
|
3083
|
+
* slides for 30 days of inactivity.
|
|
3084
|
+
*/
|
|
3085
|
+
async failedLoginReadsLocked(ctx, err, handle) {
|
|
3086
|
+
const mode = this.opts.lockoutDisclosure;
|
|
3087
|
+
if (mode === "generic") return false;
|
|
3088
|
+
if (err.type === "LOCKED") return true;
|
|
3089
|
+
if (mode !== "uniform" || err.type !== "NOT_FOUND" && err.type !== "INACTIVE") return false;
|
|
3090
|
+
const { threshold, duration } = {
|
|
3091
|
+
...this.users.getConfig().lockout,
|
|
3092
|
+
...this.lockoutOverride(ctx)
|
|
3093
|
+
};
|
|
3094
|
+
if (threshold <= 0) return false;
|
|
3095
|
+
const store = this.opts.lockoutShadowStore;
|
|
3096
|
+
const id = createHash("sha256").update(handle.trim().toLowerCase()).digest("base64url");
|
|
3097
|
+
const lockKey = `${SHADOW_LOCK_PREFIX}${id}`;
|
|
3098
|
+
if (store.get && await store.get(lockKey) > 0) {
|
|
3099
|
+
if (duration <= 0) await store.expire?.(lockKey, SHADOW_TTL_MS);
|
|
3100
|
+
return true;
|
|
3101
|
+
}
|
|
3102
|
+
const failKey = `shadow-fail:${id}`;
|
|
3103
|
+
const failures = await store.hit(failKey, SHADOW_TTL_MS);
|
|
3104
|
+
if (failures > 1) await store.expire?.(failKey, SHADOW_TTL_MS);
|
|
3105
|
+
if (!store.get) return failures > threshold;
|
|
3106
|
+
if (failures >= threshold) await store.hit(lockKey, duration > 0 ? duration : SHADOW_TTL_MS);
|
|
3107
|
+
return false;
|
|
3108
|
+
}
|
|
3109
|
+
/**
|
|
2597
3110
|
* Route a credentials alt-action click (forgotPassword / signup / magicLink
|
|
2598
3111
|
* / sso-<id>) to a `finishWf` redirect envelope. Returns `ALT_HANDLED` when
|
|
2599
3112
|
* the caller should short-circuit without running form validation.
|
|
@@ -2684,7 +3197,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
2684
3197
|
data: { sent: true },
|
|
2685
3198
|
message: {
|
|
2686
3199
|
level: "info",
|
|
2687
|
-
text:
|
|
3200
|
+
text: this.msg("RECOVERY_INSTRUCTIONS_SENT")
|
|
2688
3201
|
}
|
|
2689
3202
|
});
|
|
2690
3203
|
}
|
|
@@ -2866,8 +3379,8 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
2866
3379
|
async prepareAvailableRoles(ctx) {
|
|
2867
3380
|
const roles = await this.getAvailableRoles();
|
|
2868
3381
|
if (roles) (ctx.admin ??= {}).availableRoles = roles;
|
|
2869
|
-
else if (!
|
|
2870
|
-
|
|
3382
|
+
else if (!warnedOnce.openInviteWhitelist && this.inviteWhitelistIsOpen()) {
|
|
3383
|
+
warnedOnce.openInviteWhitelist = true;
|
|
2871
3384
|
useLogger("aooth:auth", current()).warn("Invite role whitelist is OFF — the admin invite form can assign ANY role, including privileged ones. Set `invitableRoles` (intersected with the inviter's ARBAC grants), override `getAvailableRoles()`, or set `allowAnyInviteRole: true` to acknowledge the open default.");
|
|
2872
3385
|
}
|
|
2873
3386
|
}
|
|
@@ -2926,24 +3439,32 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
2926
3439
|
*/
|
|
2927
3440
|
async adminForm(ctx) {
|
|
2928
3441
|
const wf = this.useAtscriptWfPublic(ctx, this.opts.forms.invite);
|
|
2929
|
-
const
|
|
2930
|
-
const
|
|
2931
|
-
const parsed = this.effectiveInviteRoles(ctx, input.roles);
|
|
3442
|
+
const { email, roles, ...extra } = wf.resolveInput();
|
|
3443
|
+
const parsed = this.effectiveInviteRoles(ctx, roles);
|
|
2932
3444
|
if (Array.isArray(ctx.admin?.availableRoles)) {
|
|
2933
3445
|
const allowed = new Set(ctx.admin.availableRoles);
|
|
2934
|
-
if (parsed.find((r) => !allowed.has(r)) !== void 0) throw this.throwPublic(ctx, wf, { errors: { roles: "
|
|
3446
|
+
if (parsed.find((r) => !allowed.has(r)) !== void 0) throw this.throwPublic(ctx, wf, { errors: { roles: this.msg("INVALID_ROLE") } });
|
|
2935
3447
|
}
|
|
3448
|
+
if (Object.keys(extra).length > 0) (ctx.admin ??= {}).form = extra;
|
|
2936
3449
|
const existing = await this.users.findByHandle(email);
|
|
3450
|
+
const invitedBy = useAuth().getAuthContext()?.userId;
|
|
3451
|
+
const pendingIssuer = existing?.account?.pendingInvitation ? existing.account.invitedBy : void 0;
|
|
3452
|
+
if (invitedBy) (ctx.admin ??= {}).invitedBy = invitedBy;
|
|
2937
3453
|
const action = await this.duplicateInviteCheck({
|
|
2938
3454
|
email,
|
|
2939
|
-
existingUser: existing
|
|
3455
|
+
existingUser: existing,
|
|
3456
|
+
...this.inviteHookInput(ctx),
|
|
3457
|
+
...existing?.account?.pendingInvitation && { pending: pendingIssuer === void 0 ? {} : { invitedBy: pendingIssuer } }
|
|
2940
3458
|
});
|
|
2941
3459
|
if (action === "reject") {
|
|
2942
|
-
if (existing?.account?.pendingInvitation) throw this.throwPublic(ctx, wf, { errors: { email: "
|
|
2943
|
-
if (existing) throw this.throwPublic(ctx, wf, { errors: { email: "
|
|
2944
|
-
throw this.throwPublic(ctx, wf, { errors: { email: "
|
|
3460
|
+
if (existing?.account?.pendingInvitation) throw this.throwPublic(ctx, wf, { errors: { email: this.msg("INVITE_ALREADY_PENDING") } });
|
|
3461
|
+
if (existing) throw this.throwPublic(ctx, wf, { errors: { email: this.msg("USER_ALREADY_EXISTS") } });
|
|
3462
|
+
throw this.throwPublic(ctx, wf, { errors: { email: this.msg("DUPLICATE_INVITE_REJECTED") } });
|
|
3463
|
+
}
|
|
3464
|
+
if (action === "reuse") {
|
|
3465
|
+
(ctx.admin ??= {}).reuseExisting = true;
|
|
3466
|
+
if (pendingIssuer !== void 0 && invitedBy !== void 0 && pendingIssuer !== invitedBy) this.warnCrossIssuerReuse();
|
|
2945
3467
|
}
|
|
2946
|
-
if (action === "reuse") (ctx.admin ??= {}).reuseExisting = true;
|
|
2947
3468
|
ctx.email = email;
|
|
2948
3469
|
if (parsed.length > 0) (ctx.admin ??= {}).roles = parsed;
|
|
2949
3470
|
}
|
|
@@ -2953,7 +3474,10 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
2953
3474
|
*/
|
|
2954
3475
|
async inferRoles(ctx) {
|
|
2955
3476
|
if (!ctx.email) return void 0;
|
|
2956
|
-
const inferred = await this.inferAdminRoles({
|
|
3477
|
+
const inferred = await this.inferAdminRoles({
|
|
3478
|
+
email: ctx.email,
|
|
3479
|
+
...this.inviteHookInput(ctx)
|
|
3480
|
+
});
|
|
2957
3481
|
if (inferred.length === 0) return void 0;
|
|
2958
3482
|
const admin = ctx.admin ??= {};
|
|
2959
3483
|
const merged = /* @__PURE__ */ new Set([...admin.roles ?? [], ...inferred]);
|
|
@@ -2966,16 +3490,26 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
2966
3490
|
*/
|
|
2967
3491
|
async buildUserExtras(ctx) {
|
|
2968
3492
|
if (!ctx.email) throw new HttpError$1(500, "Workflow state corrupted: missing email");
|
|
2969
|
-
const invitedBy = useAuth().getAuthContext()?.userId;
|
|
3493
|
+
const invitedBy = ctx.admin?.invitedBy ?? useAuth().getAuthContext()?.userId;
|
|
3494
|
+
if (invitedBy) (ctx.admin ??= {}).invitedBy = invitedBy;
|
|
2970
3495
|
const preparedInput = {
|
|
2971
3496
|
email: ctx.email,
|
|
2972
3497
|
roles: ctx.admin?.roles ?? [],
|
|
2973
|
-
...
|
|
3498
|
+
...this.inviteHookInput(ctx)
|
|
2974
3499
|
};
|
|
2975
|
-
const extras = await this.prepareUser(preparedInput);
|
|
3500
|
+
const extras = await this.prepareUser(preparedInput) ?? {};
|
|
2976
3501
|
(ctx.admin ??= {}).userExtras = extras;
|
|
2977
3502
|
}
|
|
2978
3503
|
/**
|
|
3504
|
+
* Invariant of the invite issue phase: once the admin form is accepted, the
|
|
3505
|
+
* pending user must exist before the link is sent. An issue phase that ends
|
|
3506
|
+
* without one (a broken override, a store that silently dropped the row) is
|
|
3507
|
+
* a server error — never a bare `{ finished: true }`.
|
|
3508
|
+
*/
|
|
3509
|
+
assertInviteCreated(ctx) {
|
|
3510
|
+
if (ctx.email && !ctx.subject) throw new HttpError$1(500, "Invite issue failed: the invited user was not created");
|
|
3511
|
+
}
|
|
3512
|
+
/**
|
|
2979
3513
|
* Create the user row from `ctx.admin.userExtras` (plus the admin-supplied
|
|
2980
3514
|
* `ctx.admin.roles`), then stamp `pendingInvitation = true` via a follow-up
|
|
2981
3515
|
* deep-merge update so `createUser`-applied account defaults survive.
|
|
@@ -2995,18 +3529,25 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
2995
3529
|
*/
|
|
2996
3530
|
async createUser(ctx) {
|
|
2997
3531
|
if (!ctx.email) throw new HttpError$1(500, "Workflow state corrupted: missing email");
|
|
2998
|
-
const
|
|
3532
|
+
const admin = ctx.admin ??= {};
|
|
3533
|
+
const adminRoles = admin.roles;
|
|
2999
3534
|
const fields = {
|
|
3000
|
-
...
|
|
3535
|
+
...admin.userExtras,
|
|
3001
3536
|
...adminRoles && adminRoles.length > 0 && { roles: adminRoles }
|
|
3002
3537
|
};
|
|
3003
|
-
|
|
3538
|
+
admin.inviteNonce = randomBytes(16).toString("base64url");
|
|
3539
|
+
const pendingAccount = {
|
|
3540
|
+
pendingInvitation: true,
|
|
3541
|
+
inviteNonce: admin.inviteNonce,
|
|
3542
|
+
...admin.invitedBy && { invitedBy: admin.invitedBy }
|
|
3543
|
+
};
|
|
3544
|
+
if (admin.reuseExisting) {
|
|
3004
3545
|
const existing = await this.users.findByHandle(ctx.email);
|
|
3005
3546
|
if (existing) {
|
|
3006
|
-
if (!existing.account?.pendingInvitation) throw
|
|
3547
|
+
if (!existing.account?.pendingInvitation) throw this.httpError(409, "USER_ALREADY_EXISTS");
|
|
3007
3548
|
await this.users.update(existing.id, {
|
|
3008
3549
|
...fields,
|
|
3009
|
-
account:
|
|
3550
|
+
account: pendingAccount
|
|
3010
3551
|
});
|
|
3011
3552
|
ctx.subject = existing.id;
|
|
3012
3553
|
return;
|
|
@@ -3016,10 +3557,10 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3016
3557
|
try {
|
|
3017
3558
|
created = await this.users.createUser(ctx.email, void 0, fields);
|
|
3018
3559
|
} catch (err) {
|
|
3019
|
-
if (err instanceof UserAuthError && err.type === "ALREADY_EXISTS") throw
|
|
3560
|
+
if (err instanceof UserAuthError && err.type === "ALREADY_EXISTS") throw this.httpError(409, "USER_ALREADY_EXISTS");
|
|
3020
3561
|
throw err;
|
|
3021
3562
|
}
|
|
3022
|
-
await this.users.update(created.id, { account:
|
|
3563
|
+
await this.users.update(created.id, { account: pendingAccount });
|
|
3023
3564
|
ctx.subject = created.id;
|
|
3024
3565
|
}
|
|
3025
3566
|
/**
|
|
@@ -3045,12 +3586,40 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3045
3586
|
const admin = ctx.admin ??= {};
|
|
3046
3587
|
if (admin.emailDispatched) return void 0;
|
|
3047
3588
|
admin.emailDispatched = true;
|
|
3589
|
+
const mode = this.opts.inviteDelivery;
|
|
3590
|
+
admin.inviteDelivery = mode;
|
|
3048
3591
|
swapStrategy("store");
|
|
3049
|
-
|
|
3050
|
-
|
|
3592
|
+
const email = ctx.email;
|
|
3593
|
+
if (mode === "outlet-email") return outletEmail(email, "invite.magicLink", {
|
|
3594
|
+
username: email,
|
|
3051
3595
|
...ctx.subject && { userId: ctx.subject },
|
|
3052
3596
|
...admin.roles && { roles: admin.roles }
|
|
3053
3597
|
});
|
|
3598
|
+
const buildUrl = this.opts.inviteLinkUrl;
|
|
3599
|
+
if (!buildUrl) throw new HttpError$1(500, `inviteDelivery '${mode}' requires AuthWorkflowOpts.inviteLinkUrl`);
|
|
3600
|
+
const userId = ctx.subject;
|
|
3601
|
+
setPendingInviteLink(async (token) => {
|
|
3602
|
+
const url = buildUrl(token, { ...userId && { userId } });
|
|
3603
|
+
if (mode === "return-link") return {
|
|
3604
|
+
outlet: "invite",
|
|
3605
|
+
data: {
|
|
3606
|
+
inviteLink: url,
|
|
3607
|
+
...userId && { userId }
|
|
3608
|
+
}
|
|
3609
|
+
};
|
|
3610
|
+
await this.deliver({
|
|
3611
|
+
kind: "invite-link",
|
|
3612
|
+
channel: "email",
|
|
3613
|
+
recipient: email,
|
|
3614
|
+
url,
|
|
3615
|
+
expiresInMs: INVITE_LINK_TTL_MS
|
|
3616
|
+
});
|
|
3617
|
+
return {
|
|
3618
|
+
sent: true,
|
|
3619
|
+
outlet: "invite"
|
|
3620
|
+
};
|
|
3621
|
+
});
|
|
3622
|
+
return outlet(INVITE_OUTLET, { target: email });
|
|
3054
3623
|
}
|
|
3055
3624
|
/**
|
|
3056
3625
|
* Check whether the invite was already accepted. Sets
|
|
@@ -3058,10 +3627,57 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3058
3627
|
* cleared.
|
|
3059
3628
|
*/
|
|
3060
3629
|
async checkPendingInvitation(ctx) {
|
|
3061
|
-
if (!ctx.
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3630
|
+
if (!(await this.currentInviteRow(ctx)).account?.pendingInvitation) (ctx.accept ??= {}).alreadyAccepted = true;
|
|
3631
|
+
}
|
|
3632
|
+
/**
|
|
3633
|
+
* Username policy for `inviteUsername: 'choose'`, applied to the normalised
|
|
3634
|
+
* (NFKC, trimmed) pick. Return a message code to refuse it. Default: at most
|
|
3635
|
+
* 256 characters, no whitespace or control characters, and no `@` unless it
|
|
3636
|
+
* is the invited address itself — a chosen name must not look like someone
|
|
3637
|
+
* else's email handle (sign-in resolves `username` before email columns).
|
|
3638
|
+
*/
|
|
3639
|
+
validateChosenUsername(ctx, username) {
|
|
3640
|
+
if (username.length === 0 || username.length > 256) return "USERNAME_NOT_ALLOWED";
|
|
3641
|
+
if (/[\s\u0000-\u001f\u007f]/.test(username)) return "USERNAME_NOT_ALLOWED";
|
|
3642
|
+
if (username.includes("@") && username.toLowerCase() !== ctx.email?.toLowerCase()) return "USERNAME_NOT_ALLOWED";
|
|
3643
|
+
}
|
|
3644
|
+
/**
|
|
3645
|
+
* The invited account, refusing a cancelled invite (410 `INVITE_CANCELLED`,
|
|
3646
|
+
* the row is gone) or a superseded link (410 `INVITE_REPLACED`, a re-invite
|
|
3647
|
+
* rotated the account's marker away from this run's).
|
|
3648
|
+
*/
|
|
3649
|
+
async currentInviteRow(ctx) {
|
|
3650
|
+
this.requireSubject(ctx);
|
|
3651
|
+
const user = await this.users.findByIdentifier(ctx.subject);
|
|
3652
|
+
if (!user) throw this.httpError(410, "INVITE_CANCELLED");
|
|
3653
|
+
const current = user.account?.inviteNonce;
|
|
3654
|
+
if (current !== void 0 && current !== ctx.admin?.inviteNonce) throw this.httpError(410, "INVITE_REPLACED");
|
|
3655
|
+
return user;
|
|
3656
|
+
}
|
|
3657
|
+
/**
|
|
3658
|
+
* Re-check, right before an invite-accept write, that this run's link is
|
|
3659
|
+
* still the current one and the invite is still pending — a re-invite or a
|
|
3660
|
+
* parallel acceptance may have happened while this run was paused.
|
|
3661
|
+
*/
|
|
3662
|
+
async assertInviteStillOpen(ctx) {
|
|
3663
|
+
if (!(await this.currentInviteRow(ctx)).account?.pendingInvitation) throw this.httpError(410, "INVITE_ALREADY_ACCEPTED");
|
|
3664
|
+
}
|
|
3665
|
+
/**
|
|
3666
|
+
* `inviteUsername: 'choose'` — the invitee picks the username they will
|
|
3667
|
+
* sign in with (the invited email stays the correspondence address). The
|
|
3668
|
+
* pick replaces the account's login handle; a taken one re-pauses.
|
|
3669
|
+
*/
|
|
3670
|
+
async chooseUsername(ctx) {
|
|
3671
|
+
this.requireSubject(ctx);
|
|
3672
|
+
const wf = this.useAtscriptWfPublic(ctx, this.opts.forms.inviteChooseUsername);
|
|
3673
|
+
const username = normalizeUsername(wf.resolveInput().username);
|
|
3674
|
+
await this.assertInviteStillOpen(ctx);
|
|
3675
|
+
const refused = this.validateChosenUsername(ctx, username);
|
|
3676
|
+
if (refused) throw this.throwPublic(ctx, wf, { errors: { username: this.msg(refused) } });
|
|
3677
|
+
const taken = await this.users.findByHandle(username);
|
|
3678
|
+
if (taken && taken.id !== ctx.subject) throw this.throwPublic(ctx, wf, { errors: { username: this.msg("CHOOSE_USERNAME_TAKEN") } });
|
|
3679
|
+
await this.users.update(ctx.subject, { username });
|
|
3680
|
+
(ctx.accept ??= {}).usernameChosen = true;
|
|
3065
3681
|
}
|
|
3066
3682
|
/**
|
|
3067
3683
|
* Emit the "this invite was already accepted" finish envelope and short-
|
|
@@ -3070,7 +3686,8 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3070
3686
|
idempotentRedirect(ctx) {
|
|
3071
3687
|
finishWf(buildInviteAlreadyAcceptedEnvelope({
|
|
3072
3688
|
loginUrl: ctx.accept.loginUrl,
|
|
3073
|
-
alreadyAcceptedRedirectUrl: ctx.accept.alreadyAcceptedRedirectUrl
|
|
3689
|
+
alreadyAcceptedRedirectUrl: ctx.accept.alreadyAcceptedRedirectUrl,
|
|
3690
|
+
...this.opts.messages !== void 0 && { messages: this.opts.messages }
|
|
3074
3691
|
}));
|
|
3075
3692
|
}
|
|
3076
3693
|
/**
|
|
@@ -3078,12 +3695,17 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3078
3695
|
*/
|
|
3079
3696
|
async unsetPendingInvitation(ctx) {
|
|
3080
3697
|
this.requireSubject(ctx);
|
|
3081
|
-
await this.users.
|
|
3698
|
+
if (!await this.users.acceptInvitation(ctx.subject, ctx.admin?.inviteNonce)) {
|
|
3699
|
+
await this.assertInviteStillOpen(ctx);
|
|
3700
|
+
throw this.httpError(410, "INVITE_ALREADY_ACCEPTED");
|
|
3701
|
+
}
|
|
3082
3702
|
}
|
|
3083
3703
|
/** Activate the invited user account (flips the account status flag). */
|
|
3084
3704
|
async activateUser(ctx) {
|
|
3085
3705
|
this.requireSubject(ctx);
|
|
3086
|
-
|
|
3706
|
+
if (ctx.accept) await this.currentInviteRow(ctx);
|
|
3707
|
+
const proved = ctx.email && ctx.admin?.inviteDelivery !== "return-link" && EMAIL_SHAPE.test(ctx.email) ? ctx.email : void 0;
|
|
3708
|
+
await this.users.activateAccount(ctx.subject, proved ? { verifiedEmail: proved } : {});
|
|
3087
3709
|
}
|
|
3088
3710
|
/**
|
|
3089
3711
|
* Emit the success-confirmation envelope. The downstream `finalize-auto-
|
|
@@ -3120,7 +3742,8 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3120
3742
|
if (ctx.postReset && err instanceof StepRetriableError) throw this.stampRecoveryExpiry(err);
|
|
3121
3743
|
throw err;
|
|
3122
3744
|
}
|
|
3123
|
-
if (input.newPassword !== input.confirmPassword) throw this.throwPublic(ctx, wf, { errors: { confirmPassword: "
|
|
3745
|
+
if (input.newPassword !== input.confirmPassword) throw this.throwPublic(ctx, wf, { errors: { confirmPassword: this.msg("PASSWORDS_DO_NOT_MATCH") } });
|
|
3746
|
+
if (ctx.accept) await this.assertInviteStillOpen(ctx);
|
|
3124
3747
|
try {
|
|
3125
3748
|
await this.users.setPassword(ctx.subject, input.newPassword);
|
|
3126
3749
|
} catch (err) {
|
|
@@ -3130,6 +3753,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3130
3753
|
this.processInlineConsent(ctx, input, wf);
|
|
3131
3754
|
ctx.isPasswordInitial = false;
|
|
3132
3755
|
ctx.isPasswordExpired = false;
|
|
3756
|
+
ctx.passwordChanged = true;
|
|
3133
3757
|
ctx.newPasswordRequired = false;
|
|
3134
3758
|
delete password.changeReason;
|
|
3135
3759
|
delete password.heading;
|
|
@@ -3154,12 +3778,12 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3154
3778
|
finishWf({
|
|
3155
3779
|
message: {
|
|
3156
3780
|
level: "warn",
|
|
3157
|
-
text:
|
|
3781
|
+
text: this.msg("PASSWORD_CHANGE_TOO_RECENT")
|
|
3158
3782
|
},
|
|
3159
3783
|
next: {
|
|
3160
3784
|
trigger: "manual",
|
|
3161
3785
|
primary: {
|
|
3162
|
-
label: "
|
|
3786
|
+
label: this.msg("BACK"),
|
|
3163
3787
|
action: {
|
|
3164
3788
|
type: "redirect",
|
|
3165
3789
|
target: this.opts.loginUrl,
|
|
@@ -3183,7 +3807,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3183
3807
|
this.requireSubject(ctx);
|
|
3184
3808
|
const wf = this.useAtscriptWfPublic(ctx, this.opts.forms.changePassword);
|
|
3185
3809
|
const input = wf.resolveInput();
|
|
3186
|
-
if (input.newPassword !== input.confirmPassword) throw this.throwPublic(ctx, wf, { errors: { confirmPassword: "
|
|
3810
|
+
if (input.newPassword !== input.confirmPassword) throw this.throwPublic(ctx, wf, { errors: { confirmPassword: this.msg("PASSWORDS_DO_NOT_MATCH") } });
|
|
3187
3811
|
try {
|
|
3188
3812
|
await this.users.changePassword(ctx.subject, input.currentPassword, input.newPassword, input.confirmPassword);
|
|
3189
3813
|
} catch (err) {
|
|
@@ -3195,22 +3819,48 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3195
3819
|
}
|
|
3196
3820
|
}
|
|
3197
3821
|
/**
|
|
3198
|
-
* Change-password terminal —
|
|
3199
|
-
*
|
|
3200
|
-
*
|
|
3201
|
-
*
|
|
3202
|
-
*
|
|
3822
|
+
* Change-password terminal — sign the current device in on a FRESH session
|
|
3823
|
+
* and end the one the change was made from, then emit a success message.
|
|
3824
|
+
* The new pair is minted under a new session id, so the pre-change session
|
|
3825
|
+
* (its access token, refresh token and every rotation) is revoked here —
|
|
3826
|
+
* whatever `revokeOtherSessions` says, since that policy covers only the
|
|
3827
|
+
* user's OTHER sessions. Runs AFTER the optional `revoke-sessions` step, so
|
|
3828
|
+
* the default net effect is "kill every old session, keep this device on a
|
|
3829
|
+
* new one" (OWASP Session Management: no ghost sessions survive a credential
|
|
3830
|
+
* change).
|
|
3831
|
+
*
|
|
3832
|
+
* The pre-change session is revoked BEFORE the issue, so a failed issue
|
|
3833
|
+
* (store error, `maxConcurrent` refusal) leaves the user signed out, never on
|
|
3834
|
+
* the old session. A refresh in flight during the change is covered by
|
|
3835
|
+
* `AuthCredential`'s revocation protocol (it can't leave live credentials in
|
|
3836
|
+
* a revoked session).
|
|
3837
|
+
*
|
|
3838
|
+
* When one session can't be targeted — a stateless store (JWT /
|
|
3839
|
+
* encapsulated), or a legacy credential minted before `sessionId` existed
|
|
3840
|
+
* (its fallback id, the access token's fingerprint, never reaches the refresh
|
|
3841
|
+
* row) — ALL of the user's sessions are revoked (`revokeAllForUser`, also
|
|
3842
|
+
* under `revokeOtherSessions: false`). A stateless store also denylists the
|
|
3843
|
+
* presented access token (best effort): its revocation epoch is process-local.
|
|
3203
3844
|
*/
|
|
3204
3845
|
async finishChangePassword(ctx) {
|
|
3205
3846
|
this.requireSubject(ctx);
|
|
3206
|
-
const issue = await this.issueForContext(ctx);
|
|
3207
3847
|
const auth = useAuth();
|
|
3848
|
+
const prior = auth.getAuthContext();
|
|
3849
|
+
const priorSessionId = prior?.sessionId;
|
|
3850
|
+
const stateful = this.auth.canEnumerateSessions;
|
|
3851
|
+
if (stateful && priorSessionId !== void 0 && priorSessionId !== prior?.credentialId) await this.auth.revokeSession(ctx.subject, priorSessionId);
|
|
3852
|
+
else {
|
|
3853
|
+
await this.auth.revokeAllForUser(ctx.subject);
|
|
3854
|
+
const accessToken = stateful ? void 0 : auth.extractToken();
|
|
3855
|
+
if (accessToken) await this.auth.revoke(accessToken).catch(() => void 0);
|
|
3856
|
+
}
|
|
3857
|
+
const issue = await this.issueForContext(ctx);
|
|
3208
3858
|
const envelope = {
|
|
3209
3859
|
finished: true,
|
|
3210
3860
|
data: auth.buildLoginResponse(ctx.subject, issue),
|
|
3211
3861
|
message: {
|
|
3212
3862
|
level: "success",
|
|
3213
|
-
text:
|
|
3863
|
+
text: this.msg("PASSWORD_CHANGED")
|
|
3214
3864
|
}
|
|
3215
3865
|
};
|
|
3216
3866
|
useWfFinished().set({
|
|
@@ -3304,7 +3954,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3304
3954
|
},
|
|
3305
3955
|
message: {
|
|
3306
3956
|
level: "info",
|
|
3307
|
-
text:
|
|
3957
|
+
text: this.msg("ALL_MFA_METHODS_SET_UP")
|
|
3308
3958
|
}
|
|
3309
3959
|
};
|
|
3310
3960
|
else envelope = {
|
|
@@ -3315,7 +3965,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3315
3965
|
},
|
|
3316
3966
|
message: {
|
|
3317
3967
|
level: "info",
|
|
3318
|
-
text:
|
|
3968
|
+
text: this.msg("NO_MFA_CHANGES")
|
|
3319
3969
|
}
|
|
3320
3970
|
};
|
|
3321
3971
|
return envelope;
|
|
@@ -3405,7 +4055,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3405
4055
|
return;
|
|
3406
4056
|
}
|
|
3407
4057
|
const input = wf.resolveInput();
|
|
3408
|
-
if (!await this.users.verifyPassword(username, input.password)) throw this.throwPublic(ctx, wf, { errors: { password: "
|
|
4058
|
+
if (!await this.users.verifyPassword(username, input.password)) throw this.throwPublic(ctx, wf, { errors: { password: this.msg("INCORRECT_PASSWORD") } });
|
|
3409
4059
|
(ctx.otp ??= {}).verified = true;
|
|
3410
4060
|
}
|
|
3411
4061
|
/**
|
|
@@ -3450,12 +4100,12 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3450
4100
|
const action = sep >= 0 ? input.operation.slice(0, sep) : "";
|
|
3451
4101
|
const target = sep >= 0 ? input.operation.slice(sep + 1) : "";
|
|
3452
4102
|
if (action === "add") {
|
|
3453
|
-
if (!candidates.includes(target)) throw this.throwPublic(ctx, wf, { errors: { operation: "
|
|
4103
|
+
if (!candidates.includes(target)) throw this.throwPublic(ctx, wf, { errors: { operation: this.msg("METHOD_UNAVAILABLE") } });
|
|
3454
4104
|
} else if (action === "replace" || action === "remove") {
|
|
3455
|
-
if (locked.has(target)) throw this.throwPublic(ctx, wf, { formMessage:
|
|
3456
|
-
if (!enrolled.some((e) => e.kind === target)) throw this.throwPublic(ctx, wf, { errors: { operation: "
|
|
3457
|
-
if (action === "remove" && addMfa.removeBlocked) throw this.throwPublic(ctx, wf, { formMessage:
|
|
3458
|
-
} else throw this.throwPublic(ctx, wf, { errors: { operation: "
|
|
4105
|
+
if (locked.has(target)) throw this.throwPublic(ctx, wf, { formMessage: this.msg("METHOD_NOT_CHANGEABLE") });
|
|
4106
|
+
if (!enrolled.some((e) => e.kind === target)) throw this.throwPublic(ctx, wf, { errors: { operation: this.msg("UNKNOWN_METHOD") } });
|
|
4107
|
+
if (action === "remove" && addMfa.removeBlocked) throw this.throwPublic(ctx, wf, { formMessage: this.msg("KEEP_ONE_MFA_METHOD") });
|
|
4108
|
+
} else throw this.throwPublic(ctx, wf, { errors: { operation: this.msg("CHOOSE_OPTION") } });
|
|
3459
4109
|
addMfa.action = action;
|
|
3460
4110
|
addMfa.target = target;
|
|
3461
4111
|
const m = ctx.mfaEnroll ??= {};
|
|
@@ -3546,7 +4196,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3546
4196
|
if (action && this.resolvePincodeAltAction(ctx, action) === "resend") {
|
|
3547
4197
|
if (ctx.pincode?.resendAllowedAt && ctx.pincode.resendAllowedAt > Date.now()) {
|
|
3548
4198
|
const remainingSec = Math.ceil((ctx.pincode.resendAllowedAt - Date.now()) / 1e3);
|
|
3549
|
-
throw this.throwPublic(ctx, pincodeWf, { formMessage:
|
|
4199
|
+
throw this.throwPublic(ctx, pincodeWf, { formMessage: this.msg("RESEND_WAIT", { seconds: remainingSec }) });
|
|
3550
4200
|
}
|
|
3551
4201
|
const recipient = isEmail ? ctx.channel?.email : ctx.channel?.phone;
|
|
3552
4202
|
const code = this.mintPin(ctx, this.opts.mfa.pincodeLength, this.opts.mfa.pincodeTtlMs);
|
|
@@ -3713,13 +4363,16 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3713
4363
|
const input = wf.resolveInput();
|
|
3714
4364
|
const mfa = ctx.mfa ??= {};
|
|
3715
4365
|
const picked = (mfa.enrolledMethods ?? []).find((m) => m.methodName === input.methodName);
|
|
3716
|
-
if (!picked) throw this.throwPublic(ctx, wf, { errors: { methodName: "
|
|
4366
|
+
if (!picked) throw this.throwPublic(ctx, wf, { errors: { methodName: this.msg("UNKNOWN_MFA_METHOD") } });
|
|
3717
4367
|
if (picked.kind === "sms" || picked.kind === "email") {
|
|
3718
4368
|
const cooldownUntil = ctx.pincode?.channelCooldowns?.[picked.kind];
|
|
3719
4369
|
if (cooldownUntil && Date.now() < cooldownUntil) {
|
|
3720
4370
|
const waitSec = Math.ceil((cooldownUntil - Date.now()) / 1e3);
|
|
3721
4371
|
const channel = picked.kind === "sms" ? "SMS" : "email";
|
|
3722
|
-
throw this.throwPublic(ctx, wf, { formMessage:
|
|
4372
|
+
throw this.throwPublic(ctx, wf, { formMessage: this.msg("RESEND_WAIT_CHANNEL", {
|
|
4373
|
+
seconds: waitSec,
|
|
4374
|
+
channel
|
|
4375
|
+
}) });
|
|
3723
4376
|
}
|
|
3724
4377
|
}
|
|
3725
4378
|
mfa.method = picked.kind;
|
|
@@ -3790,7 +4443,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3790
4443
|
if (outcome === "resend") {
|
|
3791
4444
|
if (ctx.pincode?.resendAllowedAt && ctx.pincode.resendAllowedAt > Date.now()) {
|
|
3792
4445
|
const remainingSec = Math.ceil((ctx.pincode.resendAllowedAt - Date.now()) / 1e3);
|
|
3793
|
-
throw this.throwPublic(ctx, wf, { formMessage:
|
|
4446
|
+
throw this.throwPublic(ctx, wf, { formMessage: this.msg("RESEND_WAIT", { seconds: remainingSec }) });
|
|
3794
4447
|
}
|
|
3795
4448
|
delete ctx.pin;
|
|
3796
4449
|
delete ctx.pinExpire;
|
|
@@ -3850,12 +4503,12 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3850
4503
|
if (ctx.deviceTrust?.enabled && ctx.deviceTrust?.optIn) (ctx.trust ??= {}).rememberDevice = Boolean(input.rememberDevice);
|
|
3851
4504
|
} catch (err) {
|
|
3852
4505
|
if (err instanceof UserAuthError) {
|
|
3853
|
-
if (err.type === "LOCKED") throw this.throwPublic(ctx, wf, { formMessage: "
|
|
3854
|
-
if (err.type === "INACTIVE") throw this.throwPublic(ctx, wf, { errors: { code: "
|
|
4506
|
+
if (err.type === "LOCKED") throw this.throwPublic(ctx, wf, { formMessage: this.msg("ACCOUNT_LOCKED") });
|
|
4507
|
+
if (err.type === "INACTIVE") throw this.throwPublic(ctx, wf, { errors: { code: this.msg("INVALID_CODE") } });
|
|
3855
4508
|
if (err.type === "MFA_NOT_CONFIGURED") throw new HttpError$1(400, "No TOTP MFA configured");
|
|
3856
4509
|
if (err.type === "MFA_INVALID") {
|
|
3857
|
-
if (err.details?.lockEnds !== void 0) throw this.throwPublic(ctx, wf, { formMessage: "
|
|
3858
|
-
throw this.throwPublic(ctx, wf, { errors: { code: "
|
|
4510
|
+
if (err.details?.lockEnds !== void 0) throw this.throwPublic(ctx, wf, { formMessage: this.msg("ACCOUNT_LOCKED") });
|
|
4511
|
+
throw this.throwPublic(ctx, wf, { errors: { code: this.msg("INVALID_CODE") } });
|
|
3859
4512
|
}
|
|
3860
4513
|
if (err.type === "CAS_EXHAUSTED") throw new HttpError$1(409, err.message);
|
|
3861
4514
|
}
|
|
@@ -3899,7 +4552,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3899
4552
|
return;
|
|
3900
4553
|
}
|
|
3901
4554
|
const picked = wf.resolveInput().method;
|
|
3902
|
-
if (!m.availableTransports.includes(picked)) throw this.throwPublic(ctx, wf, { errors: { method: "
|
|
4555
|
+
if (!m.availableTransports.includes(picked)) throw this.throwPublic(ctx, wf, { errors: { method: this.msg("UNKNOWN_METHOD") } });
|
|
3903
4556
|
m.method = picked;
|
|
3904
4557
|
}
|
|
3905
4558
|
return this.provisionTotpSecret(ctx);
|
|
@@ -4030,18 +4683,18 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4030
4683
|
const action = wf.resolveAction();
|
|
4031
4684
|
if (this.handleEnrollExit(ctx, action)) return void 0;
|
|
4032
4685
|
if (action === "resend") {
|
|
4033
|
-
if (m.method === "totp") throw this.throwPublic(ctx, wf, { formMessage: "
|
|
4686
|
+
if (m.method === "totp") throw this.throwPublic(ctx, wf, { formMessage: this.msg("TOTP_RESEND_NOT_APPLICABLE") });
|
|
4034
4687
|
const cooldown = ctx.pincode?.resendAllowedAt;
|
|
4035
4688
|
if (cooldown && Date.now() < cooldown) {
|
|
4036
4689
|
const waitSec = Math.ceil((cooldown - Date.now()) / 1e3);
|
|
4037
|
-
throw this.throwPublic(ctx, wf, { formMessage:
|
|
4690
|
+
throw this.throwPublic(ctx, wf, { formMessage: this.msg("RESEND_WAIT_ANOTHER", { seconds: waitSec }) });
|
|
4038
4691
|
}
|
|
4039
4692
|
await this.mintAndSendEnrollPincode(ctx, m.address);
|
|
4040
4693
|
return;
|
|
4041
4694
|
}
|
|
4042
4695
|
const input = wf.resolveInput();
|
|
4043
4696
|
if (m.method === "totp") {
|
|
4044
|
-
if (verifyTotpCode(m.secret, input.code) === null) throw this.throwPublic(ctx, wf, { errors: { code: "
|
|
4697
|
+
if (verifyTotpCode(m.secret, input.code) === null) throw this.throwPublic(ctx, wf, { errors: { code: this.msg("INVALID_CODE") } });
|
|
4045
4698
|
} else {
|
|
4046
4699
|
const pinErr = this.verifyPin(ctx, input.code);
|
|
4047
4700
|
if (pinErr) throw this.throwPublic(ctx, wf, { errors: pinErr });
|
|
@@ -4059,6 +4712,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4059
4712
|
*/
|
|
4060
4713
|
async confirmEnrolledFactor(ctx) {
|
|
4061
4714
|
this.requireSubject(ctx);
|
|
4715
|
+
if (ctx.accept) await this.assertInviteStillOpen(ctx);
|
|
4062
4716
|
const username = ctx.subject;
|
|
4063
4717
|
const m = ctx.mfaEnroll ??= {};
|
|
4064
4718
|
const methodName = m.method;
|
|
@@ -4235,7 +4889,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4235
4889
|
const cfg = ctx.sessionPolicy?.concurrencyLimit;
|
|
4236
4890
|
if (!cfg) return void 0;
|
|
4237
4891
|
const wf = this.useAtscriptWfPublic(ctx, this.opts.forms.concurrencyLimit);
|
|
4238
|
-
if (cfg.onLimit === "reject") throw this.throwPublic(ctx, wf, { formMessage: "
|
|
4892
|
+
if (cfg.onLimit === "reject") throw this.throwPublic(ctx, wf, { formMessage: this.msg("SESSION_LIMIT_REACHED") });
|
|
4239
4893
|
wf.resolveInput();
|
|
4240
4894
|
if (ctx.subject) await this.logoutOtherSessions(ctx.subject);
|
|
4241
4895
|
}
|
|
@@ -4254,6 +4908,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4254
4908
|
const group = ctx.consents ?? {};
|
|
4255
4909
|
const pending = group.pending ?? [];
|
|
4256
4910
|
if (pending.length === 0) return void 0;
|
|
4911
|
+
if (ctx.accept) await this.assertInviteStillOpen(ctx);
|
|
4257
4912
|
const accepted = new Set(group.accepted ?? []);
|
|
4258
4913
|
const at = group.decidedAt ?? Date.now();
|
|
4259
4914
|
const events = pending.map((p) => {
|
|
@@ -4269,15 +4924,20 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4269
4924
|
}
|
|
4270
4925
|
/**
|
|
4271
4926
|
* Revoke the user's existing sessions. Shared by recovery (gated upstream by
|
|
4272
|
-
* `ctx.postReset.revokeAllSessions`)
|
|
4273
|
-
* by `ctx.changePassword.revokeOtherSessions`)
|
|
4927
|
+
* `ctx.postReset.revokeAllSessions`), authenticated change-password (gated
|
|
4928
|
+
* by `ctx.changePassword.revokeOtherSessions`) and the forced password change
|
|
4929
|
+
* at login / invite (gated by `ctx.passwordChanged`).
|
|
4274
4930
|
*
|
|
4275
4931
|
* - Change-password runs in an authenticated context, so we KEEP the caller's
|
|
4276
|
-
* current
|
|
4932
|
+
* current session via `revokeOtherSessions(username, currentSessionId)` —
|
|
4277
4933
|
* OWASP "invalidate other sessions" without logging the user out of the tab
|
|
4278
|
-
* they just changed their password in.
|
|
4279
|
-
*
|
|
4280
|
-
*
|
|
4934
|
+
* they just changed their password in. `finish-change-password` then moves
|
|
4935
|
+
* that tab onto a fresh session and revokes the kept one (and covers stores
|
|
4936
|
+
* that cannot enumerate, where `revokeOtherSessions` is a no-op). If the
|
|
4937
|
+
* current session can't be resolved (no session id), fall back to revoking
|
|
4938
|
+
* everything (fail-secure).
|
|
4939
|
+
* - Recovery and the forced change are anonymous (no current session to
|
|
4940
|
+
* keep) → `revokeAllForUser`.
|
|
4281
4941
|
*/
|
|
4282
4942
|
async revokeSessions(ctx) {
|
|
4283
4943
|
if (!ctx.subject) return void 0;
|
|
@@ -4296,6 +4956,25 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4296
4956
|
await this.users.unlockAccount(ctx.subject);
|
|
4297
4957
|
}
|
|
4298
4958
|
/**
|
|
4959
|
+
* Login-only guard before the `record-login` funnel (and again before
|
|
4960
|
+
* `mint-authz-code`, past the consent pause): the account's
|
|
4961
|
+
* `password.lastChanged` must still be the one the `credentials` step
|
|
4962
|
+
* verified (`ctx.passwordStamp`). A run paused after the password check (MFA,
|
|
4963
|
+
* enrolment, consents …) and resumed after the password was changed
|
|
4964
|
+
* elsewhere finishes with an error instead of issuing tokens or minting an
|
|
4965
|
+
* authorization code. Skipped when this run changed the password itself.
|
|
4966
|
+
*/
|
|
4967
|
+
async checkPasswordUnchanged(ctx) {
|
|
4968
|
+
this.requireSubject(ctx);
|
|
4969
|
+
if (((await this.users.getUser(ctx.subject)).password.lastChanged ?? 0) !== ctx.passwordStamp) {
|
|
4970
|
+
ctx.aborted = true;
|
|
4971
|
+
finishWf({ message: {
|
|
4972
|
+
level: "error",
|
|
4973
|
+
text: this.msg("PASSWORD_CHANGED_SIGN_IN_AGAIN")
|
|
4974
|
+
} });
|
|
4975
|
+
}
|
|
4976
|
+
}
|
|
4977
|
+
/**
|
|
4299
4978
|
* The SINGLE login-completion funnel. Every flow that establishes an
|
|
4300
4979
|
* authenticated session routes through here — placed in each login schema
|
|
4301
4980
|
* right after the guards and BEFORE the delivery terminal (`issue` /
|
|
@@ -4380,7 +5059,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4380
5059
|
...cookies,
|
|
4381
5060
|
[name]: {
|
|
4382
5061
|
value,
|
|
4383
|
-
options: auth.cookieAttrs({ maxAge: ttlMs })
|
|
5062
|
+
options: auth.cookieAttrs({ maxAge: `${Math.max(0, Math.floor(ttlMs / 1e3))}s` })
|
|
4384
5063
|
}
|
|
4385
5064
|
};
|
|
4386
5065
|
};
|
|
@@ -4469,7 +5148,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4469
5148
|
if (!authz || !req) {
|
|
4470
5149
|
finishWf({ message: {
|
|
4471
5150
|
level: "error",
|
|
4472
|
-
text:
|
|
5151
|
+
text: this.msg("AUTHZ_EXPIRED")
|
|
4473
5152
|
} });
|
|
4474
5153
|
return;
|
|
4475
5154
|
}
|
|
@@ -4477,7 +5156,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4477
5156
|
await pending.delete(authz.handle);
|
|
4478
5157
|
finishWf({ message: {
|
|
4479
5158
|
level: "error",
|
|
4480
|
-
text:
|
|
5159
|
+
text: this.msg("AUTHZ_BROWSER_MISMATCH")
|
|
4481
5160
|
} });
|
|
4482
5161
|
return;
|
|
4483
5162
|
}
|
|
@@ -4533,7 +5212,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4533
5212
|
if (!handle || !req) {
|
|
4534
5213
|
finishWf({ message: {
|
|
4535
5214
|
level: "error",
|
|
4536
|
-
text:
|
|
5215
|
+
text: this.msg("AUTHZ_EXPIRED")
|
|
4537
5216
|
} });
|
|
4538
5217
|
return;
|
|
4539
5218
|
}
|
|
@@ -4541,7 +5220,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4541
5220
|
await pending.delete(handle);
|
|
4542
5221
|
finishWf({ message: {
|
|
4543
5222
|
level: "error",
|
|
4544
|
-
text:
|
|
5223
|
+
text: this.msg("AUTHZ_FAILED")
|
|
4545
5224
|
} });
|
|
4546
5225
|
return;
|
|
4547
5226
|
}
|
|
@@ -4620,12 +5299,12 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4620
5299
|
if (stillLocked) finishWf({
|
|
4621
5300
|
message: {
|
|
4622
5301
|
level: "warn",
|
|
4623
|
-
text:
|
|
5302
|
+
text: this.msg("PASSWORD_UPDATED_STILL_LOCKED")
|
|
4624
5303
|
},
|
|
4625
5304
|
next: {
|
|
4626
5305
|
trigger: "manual",
|
|
4627
5306
|
primary: {
|
|
4628
|
-
label: "
|
|
5307
|
+
label: this.msg("BACK_TO_SIGN_IN"),
|
|
4629
5308
|
action: {
|
|
4630
5309
|
type: "redirect",
|
|
4631
5310
|
target,
|
|
@@ -4637,7 +5316,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4637
5316
|
else finishWf({
|
|
4638
5317
|
message: {
|
|
4639
5318
|
level: "success",
|
|
4640
|
-
text:
|
|
5319
|
+
text: this.msg("PASSWORD_UPDATED_REDIRECTING")
|
|
4641
5320
|
},
|
|
4642
5321
|
next: {
|
|
4643
5322
|
trigger: "auto",
|
|
@@ -4647,7 +5326,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4647
5326
|
target,
|
|
4648
5327
|
reason: "reset-success"
|
|
4649
5328
|
},
|
|
4650
|
-
skipButton: { label: "
|
|
5329
|
+
skipButton: { label: this.msg("GO_NOW") }
|
|
4651
5330
|
}
|
|
4652
5331
|
});
|
|
4653
5332
|
(ctx.completion ??= {}).redirectUrl = target;
|
|
@@ -4698,7 +5377,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4698
5377
|
ctx.autoLogin = true;
|
|
4699
5378
|
if (!policy.allowSignup) finishWf({ message: {
|
|
4700
5379
|
level: "info",
|
|
4701
|
-
text:
|
|
5380
|
+
text: this.msg("SIGNUP_DISABLED")
|
|
4702
5381
|
} });
|
|
4703
5382
|
};
|
|
4704
5383
|
const result = this.resolveSignupPolicy(ctx);
|
|
@@ -4769,7 +5448,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4769
5448
|
finishWf({
|
|
4770
5449
|
message: {
|
|
4771
5450
|
level: "info",
|
|
4772
|
-
text:
|
|
5451
|
+
text: this.msg("ALREADY_HAVE_ACCOUNT")
|
|
4773
5452
|
},
|
|
4774
5453
|
next: {
|
|
4775
5454
|
trigger: "immediate",
|
|
@@ -4851,7 +5530,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4851
5530
|
finishWf({
|
|
4852
5531
|
message: {
|
|
4853
5532
|
level: "success",
|
|
4854
|
-
text:
|
|
5533
|
+
text: this.msg("ACCOUNT_LINKED")
|
|
4855
5534
|
},
|
|
4856
5535
|
next: {
|
|
4857
5536
|
trigger: "immediate",
|
|
@@ -5066,7 +5745,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
5066
5745
|
const cooldown = pending.resendAllowedAt;
|
|
5067
5746
|
if (cooldown && Date.now() < cooldown) {
|
|
5068
5747
|
const waitSec = Math.ceil((cooldown - Date.now()) / 1e3);
|
|
5069
|
-
throw this.throwPublic(ctx, wf, { formMessage:
|
|
5748
|
+
throw this.throwPublic(ctx, wf, { formMessage: this.msg("RESEND_WAIT_ANOTHER", { seconds: waitSec }) });
|
|
5070
5749
|
}
|
|
5071
5750
|
const sentTo = await this.deliverPendingLinkPin(candidate, pending);
|
|
5072
5751
|
if (sentTo === null) {
|
|
@@ -5083,8 +5762,8 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
5083
5762
|
} else try {
|
|
5084
5763
|
await this.users.login(candidate.username, input.password ?? "", this.lockoutOverride(ctx));
|
|
5085
5764
|
} catch (err) {
|
|
5086
|
-
if (err instanceof UserAuthError && err.type === "LOCKED") throw this.throwPublic(ctx, wf, { formMessage: "
|
|
5087
|
-
throw this.throwPublic(ctx, wf, { errors: { password: "
|
|
5765
|
+
if (err instanceof UserAuthError && err.type === "LOCKED") throw this.throwPublic(ctx, wf, { formMessage: this.msg("ACCOUNT_LOCKED") });
|
|
5766
|
+
throw this.throwPublic(ctx, wf, { errors: { password: this.msg("INVALID_PASSWORD") } });
|
|
5088
5767
|
}
|
|
5089
5768
|
if (this.isAccountBlocked(candidate)) {
|
|
5090
5769
|
delete ctx.pendingLink;
|
|
@@ -5219,7 +5898,7 @@ __decorate([
|
|
|
5219
5898
|
__decorateParam(0, WorkflowParam("context")),
|
|
5220
5899
|
__decorateMetadata("design:type", Function),
|
|
5221
5900
|
__decorateMetadata("design:paramtypes", [Object]),
|
|
5222
|
-
__decorateMetadata("design:returntype",
|
|
5901
|
+
__decorateMetadata("design:returntype", Promise)
|
|
5223
5902
|
], AuthWorkflow.prototype, "initInviteAdmin", null);
|
|
5224
5903
|
__decorate([
|
|
5225
5904
|
Step("init-invite-accept"),
|
|
@@ -5437,6 +6116,15 @@ __decorate([
|
|
|
5437
6116
|
__decorateMetadata("design:paramtypes", [Object]),
|
|
5438
6117
|
__decorateMetadata("design:returntype", Promise)
|
|
5439
6118
|
], AuthWorkflow.prototype, "buildUserExtras", null);
|
|
6119
|
+
__decorate([
|
|
6120
|
+
Step("assert-invite-created"),
|
|
6121
|
+
ArbacResource("auth.invite"),
|
|
6122
|
+
ArbacAction("start"),
|
|
6123
|
+
__decorateParam(0, WorkflowParam("context")),
|
|
6124
|
+
__decorateMetadata("design:type", Function),
|
|
6125
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
6126
|
+
__decorateMetadata("design:returntype", void 0)
|
|
6127
|
+
], AuthWorkflow.prototype, "assertInviteCreated", null);
|
|
5440
6128
|
__decorate([
|
|
5441
6129
|
Step("create-user"),
|
|
5442
6130
|
ArbacResource("auth.invite"),
|
|
@@ -5463,6 +6151,14 @@ __decorate([
|
|
|
5463
6151
|
__decorateMetadata("design:paramtypes", [Object]),
|
|
5464
6152
|
__decorateMetadata("design:returntype", Promise)
|
|
5465
6153
|
], AuthWorkflow.prototype, "checkPendingInvitation", null);
|
|
6154
|
+
__decorate([
|
|
6155
|
+
Step("choose-username"),
|
|
6156
|
+
Public(),
|
|
6157
|
+
__decorateParam(0, WorkflowParam("context")),
|
|
6158
|
+
__decorateMetadata("design:type", Function),
|
|
6159
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
6160
|
+
__decorateMetadata("design:returntype", Promise)
|
|
6161
|
+
], AuthWorkflow.prototype, "chooseUsername", null);
|
|
5466
6162
|
__decorate([
|
|
5467
6163
|
Step("idempotent-redirect"),
|
|
5468
6164
|
Public(),
|
|
@@ -5795,6 +6491,14 @@ __decorate([
|
|
|
5795
6491
|
__decorateMetadata("design:paramtypes", [Object]),
|
|
5796
6492
|
__decorateMetadata("design:returntype", Promise)
|
|
5797
6493
|
], AuthWorkflow.prototype, "unlockAccount", null);
|
|
6494
|
+
__decorate([
|
|
6495
|
+
Step("check-password-unchanged"),
|
|
6496
|
+
Public(),
|
|
6497
|
+
__decorateParam(0, WorkflowParam("context")),
|
|
6498
|
+
__decorateMetadata("design:type", Function),
|
|
6499
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
6500
|
+
__decorateMetadata("design:returntype", Promise)
|
|
6501
|
+
], AuthWorkflow.prototype, "checkPasswordUnchanged", null);
|
|
5798
6502
|
__decorate([
|
|
5799
6503
|
Step("record-login"),
|
|
5800
6504
|
Public(),
|
|
@@ -6026,6 +6730,10 @@ __decorate([
|
|
|
6026
6730
|
condition: (ctx) => !!ctx.enrollment?.ensurePhone && !!ctx.channel?.phone && !ctx.channel?.phoneConfirmed
|
|
6027
6731
|
},
|
|
6028
6732
|
...mfaLoopSchema,
|
|
6733
|
+
{
|
|
6734
|
+
id: "revoke-sessions",
|
|
6735
|
+
condition: (ctx) => !!ctx.passwordChanged && !ctx.aborted
|
|
6736
|
+
},
|
|
6029
6737
|
{
|
|
6030
6738
|
id: "device-trust",
|
|
6031
6739
|
condition: (ctx) => !!ctx.deviceTrust?.enabled && !!ctx.otp?.verified && !!ctx.trust?.newDevice && (!ctx.deviceTrust?.optIn || !!ctx.trust?.rememberDevice)
|
|
@@ -6047,6 +6755,11 @@ __decorate([
|
|
|
6047
6755
|
}]
|
|
6048
6756
|
},
|
|
6049
6757
|
{ break: (ctx) => !!ctx.aborted },
|
|
6758
|
+
{
|
|
6759
|
+
id: "check-password-unchanged",
|
|
6760
|
+
condition: (ctx) => ctx.passwordStamp !== void 0 && !ctx.passwordChanged
|
|
6761
|
+
},
|
|
6762
|
+
{ break: (ctx) => !!ctx.aborted },
|
|
6050
6763
|
{
|
|
6051
6764
|
id: "record-login",
|
|
6052
6765
|
condition: (ctx) => !!ctx.subject && !ctx.authz?.silent
|
|
@@ -6067,6 +6780,11 @@ __decorate([
|
|
|
6067
6780
|
id: "authz-consent",
|
|
6068
6781
|
condition: (ctx) => !!ctx.authz
|
|
6069
6782
|
},
|
|
6783
|
+
{
|
|
6784
|
+
id: "check-password-unchanged",
|
|
6785
|
+
condition: (ctx) => ctx.authz?.approved === true && ctx.passwordStamp !== void 0 && !ctx.passwordChanged
|
|
6786
|
+
},
|
|
6787
|
+
{ break: (ctx) => !!ctx.aborted },
|
|
6070
6788
|
{
|
|
6071
6789
|
id: "mint-authz-code",
|
|
6072
6790
|
condition: (ctx) => ctx.authz?.approved === true
|
|
@@ -6102,6 +6820,10 @@ __decorate([
|
|
|
6102
6820
|
id: "create-user",
|
|
6103
6821
|
condition: (ctx) => !!(ctx.email && !ctx.subject && !!ctx.admin?.userExtras)
|
|
6104
6822
|
},
|
|
6823
|
+
{
|
|
6824
|
+
id: "assert-invite-created",
|
|
6825
|
+
condition: (ctx) => !!ctx.email && !ctx.subject
|
|
6826
|
+
},
|
|
6105
6827
|
{
|
|
6106
6828
|
id: "send-email",
|
|
6107
6829
|
condition: (ctx) => !!ctx.subject
|
|
@@ -6116,6 +6838,11 @@ __decorate([
|
|
|
6116
6838
|
id: "idempotent-redirect",
|
|
6117
6839
|
condition: (ctx) => !!ctx.accept?.alreadyAccepted
|
|
6118
6840
|
},
|
|
6841
|
+
{ break: (ctx) => !!ctx.accept?.alreadyAccepted },
|
|
6842
|
+
{
|
|
6843
|
+
id: "choose-username",
|
|
6844
|
+
condition: (ctx) => !!ctx.accept?.chooseUsername && !ctx.accept?.usernameChosen
|
|
6845
|
+
},
|
|
6119
6846
|
{ id: "prepare-consents" },
|
|
6120
6847
|
{ id: "prepare-semantic-flags" },
|
|
6121
6848
|
...passwordPhaseSchema,
|
|
@@ -6329,6 +7056,10 @@ const CHANGE_PASSWORD_WORKFLOW = "auth/change-password/flow";
|
|
|
6329
7056
|
* `/auth/trigger`.
|
|
6330
7057
|
*/
|
|
6331
7058
|
const ADD_MFA_WORKFLOW = "auth/add-mfa/flow";
|
|
7059
|
+
/** The post-redemption route's single "not found" answer. */
|
|
7060
|
+
function inviteNotFound() {
|
|
7061
|
+
return new HttpError$1(404, "Invite not found");
|
|
7062
|
+
}
|
|
6332
7063
|
/** Prefer an explicit body field, fall back to the refresh cookie when enabled. */
|
|
6333
7064
|
function resolveRefreshToken(auth, body) {
|
|
6334
7065
|
if (typeof body?.refreshToken === "string") return body.refreshToken;
|
|
@@ -6380,16 +7111,18 @@ let AuthController = class AuthController {
|
|
|
6380
7111
|
const auth = useAuth();
|
|
6381
7112
|
const refreshToken = resolveRefreshToken(auth, body);
|
|
6382
7113
|
if (!refreshToken) throw new HttpError$1(401, "Missing refresh token");
|
|
7114
|
+
const fromBody = typeof body?.refreshToken === "string";
|
|
6383
7115
|
let issue;
|
|
6384
7116
|
try {
|
|
6385
7117
|
issue = await this.auth.refresh(refreshToken);
|
|
6386
7118
|
} catch (err) {
|
|
6387
|
-
if (err instanceof AuthError) throw
|
|
6388
|
-
|
|
7119
|
+
if (!(err instanceof AuthError)) throw err;
|
|
7120
|
+
if (!fromBody) auth.clearCookies();
|
|
7121
|
+
throw new HttpError$1(401, "Invalid refresh token");
|
|
6389
7122
|
}
|
|
6390
7123
|
auth.writeCookies(issue);
|
|
6391
7124
|
const validated = await this.auth.validate(issue.accessToken);
|
|
6392
|
-
return auth.buildLoginResponse(validated?.userId ?? "", issue);
|
|
7125
|
+
return auth.buildLoginResponse(validated?.userId ?? "", issue, fromBody ? { exposeTokens: true } : void 0);
|
|
6393
7126
|
}
|
|
6394
7127
|
status() {
|
|
6395
7128
|
const auth = useAuth().getAuthContext();
|
|
@@ -6432,29 +7165,41 @@ let AuthController = class AuthController {
|
|
|
6432
7165
|
* but the user-id baked into the magic-link URL by `buildMagicLinkUrl(…, {
|
|
6433
7166
|
* userId })` lets the SPA resolve the "already accepted" condition itself.
|
|
6434
7167
|
*
|
|
6435
|
-
* `@Public()` — invitees aren't signed in at this point.
|
|
7168
|
+
* `@Public()` — invitees aren't signed in at this point. Rate limited
|
|
7169
|
+
* (`30/5m` per IP, enforced when `rateLimitInterceptors` are installed); an
|
|
7170
|
+
* unknown id and a still-pending invite get the same 404.
|
|
6436
7171
|
*
|
|
6437
7172
|
* Defaults for `loginUrl` / `alreadyAcceptedRedirectUrl` mirror the unified
|
|
6438
7173
|
* `AuthWorkflow` defaults (`/login` / `/login`). Subclasses override
|
|
6439
7174
|
* `resolveInvitePostRedemption()` to read live workflow opts.
|
|
6440
7175
|
*/
|
|
6441
7176
|
async invitePostRedemption(uid) {
|
|
7177
|
+
if (!this.invitePostRedemptionEnabled()) throw inviteNotFound();
|
|
6442
7178
|
if (!uid) throw new HttpError$1(400, "Missing uid query parameter");
|
|
6443
7179
|
if (!this.users) throw new HttpError$1(500, "UserService not wired — cannot resolve post-redemption state");
|
|
6444
7180
|
let user;
|
|
6445
7181
|
try {
|
|
6446
7182
|
user = await this.users.getUser(uid);
|
|
6447
7183
|
} catch (err) {
|
|
6448
|
-
if (err instanceof UserAuthError && err.type === "NOT_FOUND") throw
|
|
7184
|
+
if (err instanceof UserAuthError && err.type === "NOT_FOUND") throw inviteNotFound();
|
|
6449
7185
|
throw err;
|
|
6450
7186
|
}
|
|
6451
|
-
if (user.account?.pendingInvitation) throw
|
|
7187
|
+
if (user.account?.pendingInvitation) throw inviteNotFound();
|
|
6452
7188
|
return {
|
|
6453
7189
|
finished: true,
|
|
6454
7190
|
...buildInviteAlreadyAcceptedEnvelope(this.resolveInvitePostRedemption())
|
|
6455
7191
|
};
|
|
6456
7192
|
}
|
|
6457
7193
|
/**
|
|
7194
|
+
* Whether `GET auth/invite/post-redemption` is served. Default `true`.
|
|
7195
|
+
* Override to return `false` when the app does not use magic-link invites —
|
|
7196
|
+
* the route then answers 404 for every id (a subclass cannot unregister an
|
|
7197
|
+
* inherited route).
|
|
7198
|
+
*/
|
|
7199
|
+
invitePostRedemptionEnabled() {
|
|
7200
|
+
return true;
|
|
7201
|
+
}
|
|
7202
|
+
/**
|
|
6458
7203
|
* URLs used by `invitePostRedemption`. Defaults mirror the unified
|
|
6459
7204
|
* `AuthWorkflow` resolved opts so subclasses that customize either of
|
|
6460
7205
|
* those options can override here to keep the side route in sync.
|
|
@@ -6526,6 +7271,7 @@ __decorate([
|
|
|
6526
7271
|
__decorate([
|
|
6527
7272
|
Get("invite/post-redemption"),
|
|
6528
7273
|
Public(),
|
|
7274
|
+
RateLimit("30/5m"),
|
|
6529
7275
|
__decorateParam(0, Query("uid")),
|
|
6530
7276
|
__decorateMetadata("design:type", Function),
|
|
6531
7277
|
__decorateMetadata("design:paramtypes", [Object]),
|
|
@@ -6630,190 +7376,6 @@ SessionsController = __decorate([
|
|
|
6630
7376
|
__decorateMetadata("design:paramtypes", [typeof AuthCredential === "undefined" ? Object : AuthCredential, typeof SessionEnricherProvider === "undefined" ? Object : SessionEnricherProvider])
|
|
6631
7377
|
], SessionsController);
|
|
6632
7378
|
//#endregion
|
|
6633
|
-
//#region src/rate-limit/composables.ts
|
|
6634
|
-
/**
|
|
6635
|
-
* Internal: the decision for this event, written by `rateLimitInterceptors`.
|
|
6636
|
-
* Its presence also serves as the "already evaluated" marker that prevents
|
|
6637
|
-
* double counting when the interceptor pair is registered more than once
|
|
6638
|
-
* (global + `@Intercept`) — moost runs `before` hooks sequentially, so a
|
|
6639
|
-
* duplicate instance always observes the first one's write.
|
|
6640
|
-
*/
|
|
6641
|
-
const rateLimitDecisionKey = key("aooth.rateLimit.decision");
|
|
6642
|
-
/**
|
|
6643
|
-
* Internal: named rate-limit subjects for this event — subject kind
|
|
6644
|
-
* (`'user'`, `'tenant'`, …) → resolved caller identity, written via
|
|
6645
|
-
* {@link setRateLimitSubject} and read by the post-guard rate-limit phase.
|
|
6646
|
-
*/
|
|
6647
|
-
const rateLimitSubjectsKey = key("aooth.rateLimit.subjects");
|
|
6648
|
-
/**
|
|
6649
|
-
* Supply the rate-limit subject for a named key strategy — the seam for
|
|
6650
|
-
* custom IAMs / tenant resolvers. Call from GUARD-priority (or earlier)
|
|
6651
|
-
* code; the value is used VERBATIM as the counter subject (include your own
|
|
6652
|
-
* prefix, e.g. `iam:<sub>`) and always wins over the built-in `user` /
|
|
6653
|
-
* `session` derivations. Full contract: docs `/moost/rate-limit`.
|
|
6654
|
-
*/
|
|
6655
|
-
function setRateLimitSubject(kind, subject, ctx = current()) {
|
|
6656
|
-
const subjects = ctx.has(rateLimitSubjectsKey) ? ctx.get(rateLimitSubjectsKey) : {};
|
|
6657
|
-
subjects[kind] = subject;
|
|
6658
|
-
ctx.set(rateLimitSubjectsKey, subjects);
|
|
6659
|
-
}
|
|
6660
|
-
/** Read a named rate-limit subject set for this event (or `undefined`). */
|
|
6661
|
-
function getRateLimitSubject(kind, ctx = current()) {
|
|
6662
|
-
return ctx.has(rateLimitSubjectsKey) ? ctx.get(rateLimitSubjectsKey)[kind] : void 0;
|
|
6663
|
-
}
|
|
6664
|
-
/**
|
|
6665
|
-
* Read the current event's rate-limit state. A plain function (not a cached
|
|
6666
|
-
* wook) — it's a single slot read, and workflow child events inherit the
|
|
6667
|
-
* HTTP parent's slot transparently.
|
|
6668
|
-
*/
|
|
6669
|
-
function useRateLimit(ctx = current()) {
|
|
6670
|
-
return { decision: ctx.has(rateLimitDecisionKey) ? ctx.get(rateLimitDecisionKey) : null };
|
|
6671
|
-
}
|
|
6672
|
-
//#endregion
|
|
6673
|
-
//#region src/rate-limit/interceptor.ts
|
|
6674
|
-
/**
|
|
6675
|
-
* Global interceptor PAIR enforcing `@RateLimit` metadata (RL.spec.md §5.2)
|
|
6676
|
-
* — register with spread:
|
|
6677
|
-
*
|
|
6678
|
-
* ```ts
|
|
6679
|
-
* app.applyGlobalInterceptors(
|
|
6680
|
-
* authGuardInterceptor({ ... }),
|
|
6681
|
-
* ...rateLimitInterceptors({ limiter, trustProxy: true }),
|
|
6682
|
-
* )
|
|
6683
|
-
* ```
|
|
6684
|
-
*
|
|
6685
|
-
* Two phases, because the primary target is public endpoints and
|
|
6686
|
-
* `authGuardInterceptor` is NOT free there — with any `Authorization`
|
|
6687
|
-
* header present it runs full credential validation before tolerating the
|
|
6688
|
-
* failure on `@Public()` routes:
|
|
6689
|
-
*
|
|
6690
|
-
* - `BEFORE_GUARD` phase owns routes whose effective key strategy is
|
|
6691
|
-
* `'ip'` or a custom resolver — floods are rejected before any
|
|
6692
|
-
* token/credential work.
|
|
6693
|
-
* - `AFTER_GUARD` phase owns `'user'` / `'auto'` keyed routes — those need
|
|
6694
|
-
* the auth context `useAuth()` reads, and by definition target
|
|
6695
|
-
* authenticated traffic where the guard must run anyway.
|
|
6696
|
-
*
|
|
6697
|
-
* Ownership is static per route (from metadata/options), so exactly one
|
|
6698
|
-
* phase evaluates each event; the decision event-slot additionally guards
|
|
6699
|
-
* against double counting when the pair is also attached per-controller
|
|
6700
|
-
* (see {@link RateLimited}).
|
|
6701
|
-
*
|
|
6702
|
-
* On rejection: draft `RateLimit-*` headers + `Retry-After` are written to
|
|
6703
|
-
* the accumulated response (they survive the throw — wooks renders the error
|
|
6704
|
-
* onto the same `HttpResponse`), then `HttpError(429, message)` is thrown.
|
|
6705
|
-
*/
|
|
6706
|
-
function rateLimitInterceptors(opts) {
|
|
6707
|
-
const defaultRules = opts?.rules?.map((r) => parseRateLimitRule(r));
|
|
6708
|
-
const limiter = opts?.limiter ?? new RateLimiter$1();
|
|
6709
|
-
const emitHeaders = opts?.headers ?? true;
|
|
6710
|
-
const ipOpts = { trustProxy: opts?.trustProxy ?? false };
|
|
6711
|
-
const routeConfigs = /* @__PURE__ */ new WeakMap();
|
|
6712
|
-
const resolveRouteConfig = (cc) => {
|
|
6713
|
-
const ctor = cc.getController().constructor;
|
|
6714
|
-
const method = String(cc.getMethod());
|
|
6715
|
-
let byMethod = routeConfigs.get(ctor);
|
|
6716
|
-
if (!byMethod) {
|
|
6717
|
-
byMethod = /* @__PURE__ */ new Map();
|
|
6718
|
-
routeConfigs.set(ctor, byMethod);
|
|
6719
|
-
}
|
|
6720
|
-
const cached = byMethod.get(method);
|
|
6721
|
-
if (cached !== void 0) return cached;
|
|
6722
|
-
const cMeta = cc.getControllerMeta();
|
|
6723
|
-
const mMeta = cc.getMethodMeta();
|
|
6724
|
-
let config = null;
|
|
6725
|
-
const disabled = mMeta?.rateLimitDisabled ?? cMeta?.rateLimitDisabled ?? false;
|
|
6726
|
-
const rules = mMeta?.rateLimitRules ?? cMeta?.rateLimitRules ?? defaultRules;
|
|
6727
|
-
if (!disabled && rules && rules.length > 0) {
|
|
6728
|
-
const metaOpts = mMeta?.rateLimitOptions ?? cMeta?.rateLimitOptions;
|
|
6729
|
-
const rawKey = metaOpts?.key ?? opts?.key ?? "ip";
|
|
6730
|
-
const keyStrategy = rawKey === "auto" ? "user" : rawKey;
|
|
6731
|
-
config = {
|
|
6732
|
-
rules,
|
|
6733
|
-
keyStrategy,
|
|
6734
|
-
postGuardKeyed: typeof keyStrategy === "string" && keyStrategy !== "ip",
|
|
6735
|
-
scope: metaOpts?.id ?? `${ctor.name}.${method}`,
|
|
6736
|
-
...(metaOpts?.message ?? opts?.message) !== void 0 && { defaultMessage: metaOpts?.message ?? opts?.message },
|
|
6737
|
-
policyHeader: rules.map((p) => `${p.limit};w=${Math.max(1, Math.round(p.window / 1e3))}`).join(", ")
|
|
6738
|
-
};
|
|
6739
|
-
}
|
|
6740
|
-
byMethod.set(method, config);
|
|
6741
|
-
return config;
|
|
6742
|
-
};
|
|
6743
|
-
const evaluate = async (phase) => {
|
|
6744
|
-
const ctx = current();
|
|
6745
|
-
if (ctx.get(eventTypeKey) !== "http") return;
|
|
6746
|
-
if (ctx.has(rateLimitDecisionKey)) return;
|
|
6747
|
-
const config = resolveRouteConfig(useControllerContext(ctx));
|
|
6748
|
-
if (!config) return;
|
|
6749
|
-
if (config.postGuardKeyed !== (phase === "post")) return;
|
|
6750
|
-
const subject = await resolveSubject(config.keyStrategy, ipOpts, ctx);
|
|
6751
|
-
const decision = await limiter.check(config.scope, subject, config.rules, { ...config.defaultMessage !== void 0 && { defaultMessage: config.defaultMessage } });
|
|
6752
|
-
ctx.set(rateLimitDecisionKey, decision);
|
|
6753
|
-
const response = useResponse(ctx);
|
|
6754
|
-
if (emitHeaders) {
|
|
6755
|
-
response.setHeader("ratelimit-limit", String(decision.limit));
|
|
6756
|
-
response.setHeader("ratelimit-remaining", String(decision.remaining));
|
|
6757
|
-
response.setHeader("ratelimit-reset", String(Math.ceil(decision.resetAfterMs / 1e3)));
|
|
6758
|
-
response.setHeader("ratelimit-policy", config.policyHeader);
|
|
6759
|
-
}
|
|
6760
|
-
if (!decision.allowed) {
|
|
6761
|
-
response.setHeader("retry-after", String(Math.ceil(decision.resetAfterMs / 1e3)));
|
|
6762
|
-
throw new HttpError(429, decision.message ?? "Too many requests");
|
|
6763
|
-
}
|
|
6764
|
-
};
|
|
6765
|
-
return [defineBeforeInterceptor(() => evaluate("pre"), TInterceptorPriority.BEFORE_GUARD), defineBeforeInterceptor(() => evaluate("post"), TInterceptorPriority.AFTER_GUARD)];
|
|
6766
|
-
}
|
|
6767
|
-
async function resolveSubject(strategy, ipOpts, ctx) {
|
|
6768
|
-
if (typeof strategy === "function") return await strategy();
|
|
6769
|
-
if (strategy !== "ip") {
|
|
6770
|
-
const subject = getRateLimitSubject(strategy, ctx);
|
|
6771
|
-
if (subject !== void 0) return subject;
|
|
6772
|
-
const auth = strategy === "user" || strategy === "session" ? useAuth(ctx).getAuthContext() : null;
|
|
6773
|
-
if (strategy === "user" && auth?.userId !== void 0) return `u:${auth.userId}`;
|
|
6774
|
-
if (strategy === "session" && auth?.sessionId !== void 0) return `s:${auth.sessionId}`;
|
|
6775
|
-
}
|
|
6776
|
-
return `ip:${useRequest(ctx).getIp(ipOpts)}`;
|
|
6777
|
-
}
|
|
6778
|
-
//#endregion
|
|
6779
|
-
//#region src/rate-limit/mate.ts
|
|
6780
|
-
function getRateLimitMate() {
|
|
6781
|
-
return getMoostMate();
|
|
6782
|
-
}
|
|
6783
|
-
//#endregion
|
|
6784
|
-
//#region src/rate-limit/decorator.ts
|
|
6785
|
-
function RateLimit(...args) {
|
|
6786
|
-
const mate = getRateLimitMate();
|
|
6787
|
-
if (args.length === 1 && args[0] === false) return mate.decorate("rateLimitDisabled", true);
|
|
6788
|
-
const inputs = [...args];
|
|
6789
|
-
let options;
|
|
6790
|
-
const last = inputs[inputs.length - 1];
|
|
6791
|
-
if (typeof last === "object" && last !== null && !("limit" in last)) options = inputs.pop();
|
|
6792
|
-
if (inputs.length === 0) throw new Error("@RateLimit requires at least one rule (or the literal `false` to opt out)");
|
|
6793
|
-
const rules = inputs.map((r) => parseRateLimitRule(r));
|
|
6794
|
-
return mate.decorate((meta) => {
|
|
6795
|
-
meta.rateLimitRules = rules;
|
|
6796
|
-
if (options) meta.rateLimitOptions = options;
|
|
6797
|
-
return meta;
|
|
6798
|
-
});
|
|
6799
|
-
}
|
|
6800
|
-
/**
|
|
6801
|
-
* Decorator-factory sugar for attaching the `rateLimitInterceptors(opts)`
|
|
6802
|
-
* PAIR to a specific controller or method instead of globally — the
|
|
6803
|
-
* `AuthGuarded` counterpart. Attaching the pair (not one phase) matters:
|
|
6804
|
-
* dropping the pre-guard def loses flood protection for ip-keyed routes,
|
|
6805
|
-
* dropping the post-guard def silently disables `key: 'user'` routes.
|
|
6806
|
-
*/
|
|
6807
|
-
function RateLimited(opts) {
|
|
6808
|
-
const [pre, post] = rateLimitInterceptors(opts);
|
|
6809
|
-
const interceptPre = Intercept(pre);
|
|
6810
|
-
const interceptPost = Intercept(post);
|
|
6811
|
-
return ((target, key, descriptor) => {
|
|
6812
|
-
interceptPre(target, key, descriptor);
|
|
6813
|
-
interceptPost(target, key, descriptor);
|
|
6814
|
-
});
|
|
6815
|
-
}
|
|
6816
|
-
//#endregion
|
|
6817
7379
|
//#region src/oauth/oauth-tokens.ts
|
|
6818
7380
|
/**
|
|
6819
7381
|
* Explicit string DI token for the ABSTRACT `FederatedIdentityStore`.
|
|
@@ -7536,4 +8098,4 @@ function createAuthEmailOutlet(deps) {
|
|
|
7536
8098
|
});
|
|
7537
8099
|
}
|
|
7538
8100
|
//#endregion
|
|
7539
|
-
export { ADD_MFA_WORKFLOW, 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, 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, deriveWfStateSecret, generateMagicLinkToken, getAuthMate, getRateLimitMate, getRateLimitSubject, haversineKm, humanizeUserAgent, isSafeRelativeRedirect, oauthCsrfCookieAttrs, parseInviteRoles, rateLimitInterceptors, resolveOAuthRedirect, setRateLimitSubject, stripReservedUserKeys, useAuth, useRateLimit };
|
|
8101
|
+
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 };
|