@jini-ai/user-management 0.6.19 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/core/types.d.ts +5 -0
  3. package/dist/react/auth/Login.js +5 -3
  4. package/dist/react/auth/Passkeys.d.ts +54 -0
  5. package/dist/react/auth/Passkeys.js +77 -0
  6. package/dist/react/auth/TotpSettings.d.ts +32 -0
  7. package/dist/react/auth/TotpSettings.js +93 -0
  8. package/dist/react/auth/hooks/use-login.hooks.d.ts +6 -0
  9. package/dist/react/auth/hooks/use-login.hooks.js +22 -3
  10. package/dist/react/auth/passkey-browser.d.ts +9 -0
  11. package/dist/react/auth/passkey-browser.js +19 -0
  12. package/dist/react/index.d.ts +5 -0
  13. package/dist/react/index.js +3 -0
  14. package/dist/react/ports.d.ts +9 -0
  15. package/dist/server/admin-crud-service.js +2 -0
  16. package/dist/server/auth-service.d.ts +19 -1
  17. package/dist/server/auth-service.js +20 -10
  18. package/dist/server/index.d.ts +11 -0
  19. package/dist/server/index.js +11 -0
  20. package/dist/server/login-providers.d.ts +15 -0
  21. package/dist/server/login-providers.js +67 -0
  22. package/dist/server/login-types.d.ts +41 -0
  23. package/dist/server/login-types.js +10 -0
  24. package/dist/server/mfa/passkey-adapter.d.ts +6 -0
  25. package/dist/server/mfa/passkey-adapter.js +35 -0
  26. package/dist/server/mfa/passkey-ports.d.ts +57 -0
  27. package/dist/server/mfa/passkey-ports.js +2 -0
  28. package/dist/server/mfa/passkey-service.d.ts +56 -0
  29. package/dist/server/mfa/passkey-service.js +156 -0
  30. package/dist/server/mfa/ports.d.ts +61 -0
  31. package/dist/server/mfa/ports.js +2 -0
  32. package/dist/server/mfa/secret-adapter.d.ts +26 -0
  33. package/dist/server/mfa/secret-adapter.js +12 -0
  34. package/dist/server/mfa/service.d.ts +77 -0
  35. package/dist/server/mfa/service.js +146 -0
  36. package/dist/server/mfa/totp-adapter.d.ts +6 -0
  37. package/dist/server/mfa/totp-adapter.js +18 -0
  38. package/dist/server/owner-reset-input.d.ts +23 -0
  39. package/dist/server/owner-reset-input.js +42 -0
  40. package/dist/server/recovery-codes.d.ts +62 -0
  41. package/dist/server/recovery-codes.js +95 -0
  42. package/package.json +24 -21
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Patch Changes
6
+
7
+ - fedca02: Add the entries `@jini-ai/agent-plugins/lifecycle/host-tools` and `@jini-ai/agent-plugins/lifecycle/mail`. `@jini-ai/user-management` declares `@jini-ai/oauth` as an optional peer. The new entries are empty for now; their contents arrive in later releases.
8
+ - Updated dependencies [8fe045b]
9
+ - Updated dependencies [41ff2ff]
10
+ - Updated dependencies [a266ba8]
11
+ - Updated dependencies [39cf677]
12
+ - Updated dependencies [27063ef]
13
+ - Updated dependencies [6ab1d81]
14
+ - Updated dependencies [699b478]
15
+ - Updated dependencies [1cf0306]
16
+ - Updated dependencies [39cf677]
17
+ - @jini-ai/core@0.7.0
18
+ - @jini-ai/ui@0.7.0
19
+ - @jini-ai/admin@0.7.0
20
+ - @jini-ai/agentic@0.7.0
21
+ - @jini-ai/ui-kit@0.7.0
22
+
23
+ ## 0.6.22
24
+
25
+ - Owner recovery: hashed single-use recovery codes, atomic reset and revoke, rate limited (`issueRecoveryCodes`, `recoverOwner`, `resetOwnerPassword`), and hidden password input for the reset command.
26
+
3
27
  ## 0.6.17
4
28
 
5
29
  ### Patch Changes
@@ -27,6 +27,11 @@ import type { ISODateTime, UUID } from "@jini-ai/core/primitives";
27
27
  export type PrincipalKind = "user" | "agent" | "api_key" | "system" | "member";
28
28
  /** Disable-only lifecycle — there is no hard-delete state. See docs/decisions/DR-001-identity-and-session-boundary.md. */
29
29
  export type PrincipalStatus = "active" | "disabled";
30
+ /** WebAuthn ceremony JSON shared by server issuance and browser execution. */
31
+ export type PasskeyOptions = {
32
+ challenge: string;
33
+ [key: string]: unknown;
34
+ };
30
35
  /**
31
36
  * Root identity row for every actor. `change_set.actorId` references
32
37
  * a principal by composite `(workspaceId, id)`.
@@ -1,11 +1,13 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useId } from "react";
3
3
  import { SecretInput } from "@jini-ai/ui";
4
4
  import { useLogin } from "./hooks/use-login.hooks.js";
5
5
  export function Login({ onLogin, port, translate, productName, initialUsername, useLoginHook = useLogin }) {
6
- const { username, setUsername, password, setPassword, error, busy, submit } = useLoginHook({ onLogin, port, translate }, { initialUsername });
6
+ const { username, setUsername, password, setPassword, error, busy, submit, mfa } = useLoginHook({ onLogin, port, translate }, { initialUsername });
7
7
  const t = translate;
8
8
  const passwordInputId = useId();
9
- return (_jsx("div", { className: "login-screen", children: _jsxs("form", { className: "login-card", onSubmit: submit, children: [_jsx("h1", { children: productName }), _jsx("p", { children: t("Sign in to your workspace") }), _jsxs("label", { children: [t("Username"), _jsx("input", { autoComplete: "username", value: username, onChange: (e) => setUsername(e.target.value), autoFocus: true })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: passwordInputId, children: t("Password") }), _jsx(SecretInput, { id: passwordInputId, label: t("Password"), toggleLabels: { show: t("Show password"), hide: t("Hide password") }, autoComplete: "current-password", value: password, onChange: (e) => setPassword(e.target.value) })] }), error ? _jsx("div", { className: "login-error", children: error }) : null, _jsx("button", { disabled: busy, children: busy ? t("Signing in…") : t("Sign in") })] }) }));
9
+ const readyLabel = mfa ? t("Verify code") : t("Sign in");
10
+ const submitLabel = busy ? t("Signing in…") : readyLabel;
11
+ return (_jsx("div", { className: "login-screen", children: _jsxs("form", { className: "login-card", onSubmit: submit, children: [_jsx("h1", { children: productName }), _jsx("p", { children: t("Sign in to your workspace") }), mfa ? _jsxs(_Fragment, { children: [_jsx("p", { children: t("Enter a fresh code from your authenticator app. After setup, wait for the next code.") }), _jsxs("label", { children: [t("Authenticator code"), _jsx("input", { autoComplete: "one-time-code", inputMode: "numeric", pattern: "[0-9]{6}", maxLength: 6, "data-agent-private": "", value: mfa.code, onChange: e => mfa.setCode(e.target.value), autoFocus: true })] })] }) : _jsxs(_Fragment, { children: [_jsxs("label", { children: [t("Username"), _jsx("input", { autoComplete: "username", value: username, onChange: (e) => setUsername(e.target.value), autoFocus: true })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: passwordInputId, children: t("Password") }), _jsx(SecretInput, { id: passwordInputId, label: t("Password"), toggleLabels: { show: t("Show password"), hide: t("Hide password") }, autoComplete: "current-password", value: password, onChange: (e) => setPassword(e.target.value) })] })] }), error ? _jsx("div", { className: "login-error", role: "alert", children: error }) : null, _jsx("button", { disabled: busy, children: submitLabel }), mfa ? _jsx("button", { type: "button", disabled: busy, onClick: mfa.cancel, children: t("Cancel") }) : null] }) }));
10
12
  }
11
13
  //# sourceMappingURL=Login.js.map
@@ -0,0 +1,54 @@
1
+ import type { Translate } from '@jini-ai/ui/panel-kit';
2
+ import type { PasskeyOptions } from '../../core/types.js';
3
+ import { runPasskeyCeremony } from './passkey-browser.js';
4
+ type Started = {
5
+ pendingToken: string;
6
+ options: PasskeyOptions;
7
+ };
8
+ type Finish = {
9
+ pendingToken: string;
10
+ response: unknown;
11
+ };
12
+ type Ceremony = typeof runPasskeyCeremony;
13
+ export interface PasskeySignInPort {
14
+ begin(input: {
15
+ pendingToken: string;
16
+ }): Promise<Started>;
17
+ complete(input: Finish): Promise<void>;
18
+ }
19
+ export interface PasskeySettingsPort {
20
+ status(): Promise<{
21
+ isOwner: boolean;
22
+ credentials: {
23
+ id: string;
24
+ }[];
25
+ }>;
26
+ enroll(input: {
27
+ password: string;
28
+ code: string;
29
+ }): Promise<Started>;
30
+ confirm(input: Finish): Promise<void>;
31
+ remove(input: {
32
+ id: string;
33
+ password: string;
34
+ code: string;
35
+ }): Promise<void>;
36
+ }
37
+ /** Explicit alternative to a TOTP code; password proof remains required. O(1), two single-send calls. */
38
+ export declare function PasskeySignIn({ port, pendingToken, onComplete, translate: t, ceremony }: {
39
+ port: PasskeySignInPort;
40
+ pendingToken: string;
41
+ onComplete: () => void | Promise<void>;
42
+ translate: Translate;
43
+ ceremony?: Ceremony;
44
+ }): import("react").JSX.Element;
45
+ /** Settings use the same owner password/TOTP management policy, with public credential ids only.
46
+ * @complexity O(n), n <= 5 credentials; one mount read and explicit single-send actions, no polling.
47
+ */
48
+ export declare function PasskeySettings({ port, translate: t, ceremony }: {
49
+ port: PasskeySettingsPort;
50
+ translate: Translate;
51
+ ceremony?: Ceremony;
52
+ }): import("react").JSX.Element | null;
53
+ export {};
54
+ //# sourceMappingURL=Passkeys.d.ts.map
@@ -0,0 +1,77 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { runPasskeyCeremony } from './passkey-browser.js';
4
+ /** Explicit alternative to a TOTP code; password proof remains required. O(1), two single-send calls. */
5
+ export function PasskeySignIn({ port, pendingToken, onComplete, translate: t, ceremony = runPasskeyCeremony }) {
6
+ const [busy, setBusy] = useState(false), [error, setError] = useState('');
7
+ const generation = useRef(0);
8
+ useEffect(() => () => { generation.current++; }, [pendingToken]);
9
+ async function signIn() {
10
+ const attempt = generation.current;
11
+ setBusy(true);
12
+ setError('');
13
+ try {
14
+ const started = await port.begin({ pendingToken });
15
+ if (attempt !== generation.current)
16
+ return;
17
+ const response = await ceremony({ kind: 'authenticate', options: started.options });
18
+ if (attempt !== generation.current)
19
+ return;
20
+ await port.complete({ pendingToken: started.pendingToken, response });
21
+ if (attempt === generation.current)
22
+ await onComplete();
23
+ }
24
+ catch (error) {
25
+ if (attempt === generation.current)
26
+ setError(error instanceof Error ? error.message : t('Passkey sign-in could not finish. Use your authenticator app or recovery code.'));
27
+ }
28
+ finally {
29
+ if (attempt === generation.current)
30
+ setBusy(false);
31
+ }
32
+ }
33
+ return _jsxs("div", { children: [_jsx("button", { type: "button", disabled: busy, onClick: signIn, children: t(busy ? 'Waiting for passkey…' : 'Use a passkey') }), error ? _jsx("p", { role: "alert", children: error }) : null] });
34
+ }
35
+ /** Settings use the same owner password/TOTP management policy, with public credential ids only.
36
+ * @complexity O(n), n <= 5 credentials; one mount read and explicit single-send actions, no polling.
37
+ */
38
+ export function PasskeySettings({ port, translate: t, ceremony = runPasskeyCeremony }) {
39
+ const [status, setStatus] = useState();
40
+ const [error, setError] = useState(''), [busy, setBusy] = useState(false);
41
+ const [password, setPassword] = useState(''), [code, setCode] = useState('');
42
+ useEffect(() => {
43
+ let active = true;
44
+ void port.status().then(value => { if (active)
45
+ setStatus(value); }).catch(error => {
46
+ if (active)
47
+ setError(error instanceof Error ? error.message : t('Passkey settings could not load. Reload this page to try again.'));
48
+ });
49
+ return () => { active = false; };
50
+ }, [port]);
51
+ async function action(id) {
52
+ setBusy(true);
53
+ setError('');
54
+ try {
55
+ if (id)
56
+ await port.remove({ id, password, code });
57
+ else {
58
+ const started = await port.enroll({ password, code });
59
+ const response = await ceremony({ kind: 'register', options: started.options });
60
+ await port.confirm({ pendingToken: started.pendingToken, response });
61
+ }
62
+ setStatus(await port.status());
63
+ }
64
+ catch (error) {
65
+ setError(error instanceof Error ? error.message : t('The passkey action could not finish. Try a new attempt.'));
66
+ }
67
+ finally {
68
+ setPassword('');
69
+ setCode('');
70
+ setBusy(false);
71
+ }
72
+ }
73
+ if (!status?.isOwner)
74
+ return error ? _jsx("p", { role: "alert", children: error }) : null;
75
+ return _jsxs("section", { className: "card", children: [_jsx("h3", { children: t('Passkeys') }), _jsx("p", { children: t('Use a passkey after your password instead of an authenticator code. Keep your authenticator app and recovery codes as a fallback.') }), _jsxs("label", { children: [t('Current owner password'), _jsx("input", { type: "password", autoComplete: "current-password", "data-agent-private": "", value: password, onChange: event => setPassword(event.target.value) })] }), _jsxs("label", { children: [t('Authenticator code'), _jsx("input", { inputMode: "numeric", autoComplete: "one-time-code", maxLength: 6, "data-agent-private": "", value: code, onChange: event => setCode(event.target.value) })] }), _jsx("button", { type: "button", disabled: busy || !password || !code || status.credentials.length >= 5, onClick: () => action(), children: t('Add passkey') }), _jsx("ul", { children: status.credentials.map((credential, index) => _jsxs("li", { children: [t('Passkey'), " ", index + 1, " ", _jsxs("button", { type: "button", disabled: busy || !password || !code, onClick: () => action(credential.id), children: [t('Remove passkey'), " ", index + 1] })] }, credential.id)) }), error ? _jsx("p", { role: "alert", children: error }) : null] });
76
+ }
77
+ //# sourceMappingURL=Passkeys.js.map
@@ -0,0 +1,32 @@
1
+ import type { Translate } from '@jini-ai/ui/panel-kit';
2
+ export interface TotpSettingsPort {
3
+ status(): Promise<{
4
+ isOwner: boolean;
5
+ available: boolean;
6
+ enrolled: boolean;
7
+ }>;
8
+ enroll(input: {
9
+ password: string;
10
+ code?: string;
11
+ }): Promise<{
12
+ pendingToken: string;
13
+ secret: string;
14
+ uri: string;
15
+ }>;
16
+ confirm(input: {
17
+ pendingToken: string;
18
+ code: string;
19
+ }): Promise<void>;
20
+ remove(input: {
21
+ password: string;
22
+ code: string;
23
+ }): Promise<void>;
24
+ }
25
+ /** Owner settings hold setup secrets only until confirmation/cancellation or unmount.
26
+ * @complexity O(1): one bounded status read on mount and one request per explicit action; no polling.
27
+ */
28
+ export declare function TotpSettings({ port, translate: t }: {
29
+ port: TotpSettingsPort;
30
+ translate: Translate;
31
+ }): import("react").JSX.Element | null;
32
+ //# sourceMappingURL=TotpSettings.d.ts.map
@@ -0,0 +1,93 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useState } from 'react';
3
+ import { SecretInput } from '@jini-ai/ui';
4
+ /** Owner settings hold setup secrets only until confirmation/cancellation or unmount.
5
+ * @complexity O(1): one bounded status read on mount and one request per explicit action; no polling.
6
+ */
7
+ export function TotpSettings({ port, translate: t }) {
8
+ const [status, setStatus] = useState();
9
+ const [error, setError] = useState('');
10
+ useEffect(() => {
11
+ let active = true;
12
+ void port.status().then(value => { if (active)
13
+ setStatus(value); }).catch(() => {
14
+ if (active)
15
+ setError(t('Authenticator settings could not load. Reload this page to try again.'));
16
+ });
17
+ return () => { active = false; };
18
+ }, [port]);
19
+ if (error)
20
+ return _jsx("p", { role: "alert", children: error });
21
+ if (!status?.isOwner || !status.available)
22
+ return null;
23
+ return _jsx(TotpSettingsForm, { port: port, enrolled: status.enrolled, t: t });
24
+ }
25
+ function TotpSettingsForm({ port, enrolled: initialEnrolled, t }) {
26
+ const [enrolled, setEnrolled] = useState(initialEnrolled), [setup, setSetup] = useState();
27
+ const [password, setPassword] = useState(''), [code, setCode] = useState('');
28
+ const [busy, setBusy] = useState(false), [error, setError] = useState(''), [message, setMessage] = useState('');
29
+ const passwordId = useId();
30
+ function clear() { setSetup(undefined); setPassword(''); setCode(''); setError(''); }
31
+ async function enroll(event) {
32
+ event.preventDefault();
33
+ setBusy(true);
34
+ setError('');
35
+ setMessage('');
36
+ try {
37
+ setSetup(await port.enroll({ password, ...(enrolled ? { code } : {}) }));
38
+ setCode('');
39
+ }
40
+ catch (error) {
41
+ setError(error instanceof Error ? error.message : t('Authenticator setup could not start. Try again.'));
42
+ }
43
+ finally {
44
+ setPassword('');
45
+ setBusy(false);
46
+ }
47
+ }
48
+ async function confirm(event) {
49
+ event.preventDefault();
50
+ if (!setup)
51
+ return;
52
+ setBusy(true);
53
+ setError('');
54
+ try {
55
+ await port.confirm({ pendingToken: setup.pendingToken, code });
56
+ clear();
57
+ setEnrolled(true);
58
+ setMessage(t('Authenticator enabled. Sign in again with the next code from your app.'));
59
+ }
60
+ catch (error) {
61
+ setError(error instanceof Error ? error.message : t('The code was not accepted. Enter a fresh authenticator code.'));
62
+ }
63
+ finally {
64
+ setBusy(false);
65
+ }
66
+ }
67
+ async function remove() {
68
+ setBusy(true);
69
+ setError('');
70
+ setMessage('');
71
+ try {
72
+ await port.remove({ password, code });
73
+ clear();
74
+ setEnrolled(false);
75
+ setMessage(t('Authenticator removed. Sign in again.'));
76
+ }
77
+ catch (error) {
78
+ setError(error instanceof Error ? error.message : t('The authenticator could not be removed. Check your password and code.'));
79
+ }
80
+ finally {
81
+ setPassword('');
82
+ setCode('');
83
+ setBusy(false);
84
+ }
85
+ }
86
+ return _jsxs("section", { className: "card", children: [_jsx("h3", { children: t('Authenticator app') }), _jsx("p", { children: t(enrolled ? 'Your authenticator code is required at every sign-in, including desktop.' : 'Add an authenticator app to require a code when signing in as the owner.') }), setup ? _jsxs("form", { onSubmit: confirm, children: [_jsx("p", { children: t('Add this setup key to your authenticator app, then enter its six-digit code. Keep the key private.') }), _jsx("code", { "data-agent-private": "", children: setup.secret }), _jsx(CodeInput, { code: code, setCode: setCode, t: t }), _jsx("button", { disabled: busy, children: t('Confirm authenticator') }), _jsx("button", { type: "button", disabled: busy, onClick: clear, children: t('Cancel') })] }) : _jsxs("form", { onSubmit: enroll, children: [_jsx("label", { htmlFor: passwordId, children: t('Current owner password') }), _jsx(SecretInput, { id: passwordId, label: t('Current owner password'), autoComplete: "current-password", "data-agent-private": "", value: password, onChange: event => setPassword(event.target.value) }), _jsx(CodeInput, { code: code, setCode: setCode, t: t, visible: enrolled }), _jsx("button", { disabled: busy || !password, children: t(enrolled ? 'Replace authenticator' : 'Set up authenticator') }), enrolled ? _jsx("button", { type: "button", disabled: busy || !password || !code, onClick: remove, children: t('Remove authenticator') }) : null] }), error ? _jsx("p", { role: "alert", children: error }) : null, message ? _jsx("p", { role: "status", children: message }) : null] });
87
+ }
88
+ function CodeInput({ code, setCode, t, visible = true }) {
89
+ if (!visible)
90
+ return null;
91
+ return _jsxs("label", { children: [t('Authenticator code'), _jsx("input", { autoComplete: "one-time-code", inputMode: "numeric", pattern: "[0-9]{6}", maxLength: 6, "data-agent-private": "", value: code, onChange: event => setCode(event.target.value) })] });
92
+ }
93
+ //# sourceMappingURL=TotpSettings.js.map
@@ -10,6 +10,12 @@ export interface LoginOptions {
10
10
  initialUsername?: string | undefined;
11
11
  }
12
12
  export interface LoginController {
13
+ mfa?: {
14
+ pendingToken: string;
15
+ code: string;
16
+ setCode: (code: string) => void;
17
+ cancel: () => void;
18
+ };
13
19
  username: string;
14
20
  setUsername: (username: string) => void;
15
21
  password: string;
@@ -4,13 +4,31 @@ export function useLogin({ onLogin, port, translate }, { initialUsername = "" }
4
4
  const [password, setPassword] = useState("");
5
5
  const [error, setError] = useState(null);
6
6
  const [busy, setBusy] = useState(false);
7
+ const [pendingToken, setPendingToken] = useState(null);
8
+ const [code, setCode] = useState("");
9
+ function cancel() { setPendingToken(null); setCode(""); setPassword(""); setError(null); }
10
+ async function authenticate() {
11
+ if (!pendingToken)
12
+ return port.login({ username, password });
13
+ if (!port.completeMfa)
14
+ throw new Error(translate("Authenticator sign-in is unavailable. Cancel and try again."));
15
+ return port.completeMfa({ pendingToken, code });
16
+ }
7
17
  async function submit(e) {
8
18
  e.preventDefault();
9
19
  setBusy(true);
10
20
  setError(null);
11
21
  try {
12
- const { user } = await port.login({ username, password });
13
- onLogin(user);
22
+ const result = await authenticate();
23
+ if ("mfaRequired" in result) {
24
+ setPendingToken(result.pendingToken);
25
+ setPassword("");
26
+ setCode("");
27
+ }
28
+ else {
29
+ cancel();
30
+ onLogin(result.user);
31
+ }
14
32
  }
15
33
  catch (err) {
16
34
  setError(err instanceof Error ? err.message : translate("login failed"));
@@ -19,6 +37,7 @@ export function useLogin({ onLogin, port, translate }, { initialUsername = "" }
19
37
  setBusy(false);
20
38
  }
21
39
  }
22
- return { username, setUsername, password, setPassword, error, busy, submit };
40
+ return { username, setUsername, password, setPassword, error, busy, submit,
41
+ ...(pendingToken ? { mfa: { pendingToken, code, setCode, cancel } } : {}) };
23
42
  }
24
43
  //# sourceMappingURL=use-login.hooks.js.map
@@ -0,0 +1,9 @@
1
+ import type { PasskeyOptions } from '../../core/types.js';
2
+ /** Load the browser protocol adapter only after an explicit passkey action.
3
+ * @complexity O(b), bounded WebAuthn JSON; one browser ceremony, no network or polling.
4
+ */
5
+ export declare function runPasskeyCeremony({ kind, options }: {
6
+ kind: 'register' | 'authenticate';
7
+ options: PasskeyOptions;
8
+ }, _options?: Record<string, never>): Promise<unknown>;
9
+ //# sourceMappingURL=passkey-browser.d.ts.map
@@ -0,0 +1,19 @@
1
+ /** Load the browser protocol adapter only after an explicit passkey action.
2
+ * @complexity O(b), bounded WebAuthn JSON; one browser ceremony, no network or polling.
3
+ */
4
+ export async function runPasskeyCeremony({ kind, options }, _options = {}) {
5
+ const browser = await import('@simplewebauthn/browser');
6
+ if (!browser.browserSupportsWebAuthn())
7
+ throw new Error('Passkeys are unavailable in this browser. Use your authenticator app or recovery code.');
8
+ try {
9
+ if (kind === 'register')
10
+ return await browser.startRegistration({ optionsJSON: options });
11
+ return await browser.startAuthentication({ optionsJSON: options });
12
+ }
13
+ catch (error) {
14
+ if (error?.name === 'NotAllowedError')
15
+ throw new Error('The passkey prompt was cancelled or timed out. Try again, or use your authenticator app.');
16
+ throw new Error('This browser could not complete the passkey prompt. Try again, or use your authenticator app or recovery code.');
17
+ }
18
+ }
19
+ //# sourceMappingURL=passkey-browser.js.map
@@ -22,4 +22,9 @@ export { userAccountCapabilities, isOwnerAccount, grantOptionLabel, formatGrantL
22
22
  export type { UserAccountCapabilities, UserRowMenuHandlers } from './users/rules.js';
23
23
  export { emptyRowState, memberRowMenuItems, describeMembersError } from './members/rules.js';
24
24
  export type { RowActionState, MemberRowMenuHandlers } from './members/rules.js';
25
+ export { TotpSettings } from './auth/TotpSettings.js';
26
+ export type { TotpSettingsPort } from './auth/TotpSettings.js';
27
+ export { PasskeySignIn, PasskeySettings } from './auth/Passkeys.js';
28
+ export type { PasskeySignInPort, PasskeySettingsPort } from './auth/Passkeys.js';
29
+ export { runPasskeyCeremony } from './auth/passkey-browser.js';
25
30
  //# sourceMappingURL=index.d.ts.map
@@ -10,4 +10,7 @@ export { useChangeUsername } from './users/hooks/use-change-username.hooks.js';
10
10
  export { ChangeUsernameDialog } from './users/ChangeUsernameDialog.js';
11
11
  export { userAccountCapabilities, isOwnerAccount, grantOptionLabel, formatGrantLabel, userRowMenuItems, describeUsersError } from './users/rules.js';
12
12
  export { emptyRowState, memberRowMenuItems, describeMembersError } from './members/rules.js';
13
+ export { TotpSettings } from './auth/TotpSettings.js';
14
+ export { PasskeySignIn, PasskeySettings } from './auth/Passkeys.js';
15
+ export { runPasskeyCeremony } from './auth/passkey-browser.js';
13
16
  //# sourceMappingURL=index.js.map
@@ -5,6 +5,15 @@ export interface LoginPort {
5
5
  password: string;
6
6
  }): Promise<{
7
7
  user: AdminUser;
8
+ } | {
9
+ mfaRequired: true;
10
+ pendingToken: string;
11
+ }>;
12
+ completeMfa?(input: {
13
+ pendingToken: string;
14
+ code: string;
15
+ }): Promise<{
16
+ user: AdminUser;
8
17
  }>;
9
18
  }
10
19
  export interface UsersPort {
@@ -320,6 +320,8 @@ export async function resetUserPassword(required) {
320
320
  const passwordHash = await deps.hasher.hash({ password: input.password });
321
321
  const updated = { ...target, passwordHash };
322
322
  await deps.repos.users.save(updated);
323
+ // Password changes invalidate old first-factor proofs while preserving the enrolled factor.
324
+ await deps.mfaStore?.clearPending({ workspaceId: input.workspaceId, principalId: input.principalId });
323
325
  const sessions = await deps.repos.sessions.listByPrincipalId({
324
326
  workspaceId: input.workspaceId,
325
327
  principalId: input.principalId,
@@ -2,8 +2,9 @@ import { type UserManagementMessages } from "./messages.js";
2
2
  import type { SessionTokenPort, UsernameChangePort } from "../core/runtime-ports.js";
3
3
  import type { Clock, IdGenerator, ISODateTime, UUID } from "@jini-ai/core/primitives";
4
4
  import type { IdentityRepos, PasswordHasherPort } from "../core/ports.js";
5
- import { type PrincipalRecord, type SessionRecord } from "../core/types.js";
5
+ import { type PrincipalRecord, type SessionRecord, type UserRecord } from "../core/types.js";
6
6
  export interface AuthServiceDeps {
7
+ mfaStore?: import("./mfa/ports.js").MfaStore;
7
8
  repos: IdentityRepos;
8
9
  hasher: PasswordHasherPort;
9
10
  clock: Clock;
@@ -39,6 +40,23 @@ export declare function createSessionForPrincipal(required: {
39
40
  session: SessionRecord;
40
41
  rawToken: string;
41
42
  }>;
43
+ /**
44
+ * The credential checks of `login`, in their fixed order: blank input is refused before any lookup,
45
+ * and the (slow) hash verify runs only once a live principal is found. Every refusal throws the same
46
+ * `AuthInvalidCredentialsError` message — no user-enumeration signal.
47
+ */
48
+ export declare function verifyCredentials(required: {
49
+ deps: AuthServiceDeps;
50
+ input: {
51
+ workspaceId: UUID;
52
+ username: string;
53
+ password: string;
54
+ };
55
+ invalidCredentialsMessage: string;
56
+ }, _options?: Record<string, never>): Promise<{
57
+ userRow: UserRecord;
58
+ principal: PrincipalRecord;
59
+ }>;
42
60
  /**
43
61
  * Verify `username`+`password` for an `active` principal and mint a session
44
62
  * Constant-shaped failure: a nonexistent username, a
@@ -1,7 +1,8 @@
1
+ import { inIdentityTransaction } from "./identity-transaction.js";
1
2
  import { defaultUserManagementMessages } from "./messages.js";
2
3
  import { nowIso as kernelNowIso } from "@jini-ai/core/primitives";
3
4
  import { resolveEffectivePermissions } from "./authorize.js";
4
- import { AuthInvalidCredentialsError } from "../core/types.js";
5
+ import { AuthInvalidCredentialsError, IdentityValidationError } from "../core/types.js";
5
6
  import { normalizeUsername } from "./username.js";
6
7
  /**
7
8
  * @file Login / logout / session validation (state.spec `LOGIN`/`LOGOUT`).
@@ -75,7 +76,7 @@ function isActivePrincipal(principal) {
75
76
  * and the (slow) hash verify runs only once a live principal is found. Every refusal throws the same
76
77
  * `AuthInvalidCredentialsError` message — no user-enumeration signal.
77
78
  */
78
- async function verifyCredentials(required) {
79
+ export async function verifyCredentials(required, _options = {}) {
79
80
  const { deps, input, invalidCredentialsMessage } = required;
80
81
  const refuse = () => new AuthInvalidCredentialsError({ message: invalidCredentialsMessage });
81
82
  const username = normalizeUsername({ raw: input.username });
@@ -108,14 +109,23 @@ async function verifyCredentials(required) {
108
109
  */
109
110
  export async function login(required, optional = {}) {
110
111
  const { deps } = required;
111
- const input = { ...required.input, ...optional };
112
- const invalidCredentialsMessage = (optional.messages ?? defaultUserManagementMessages).invalidCredentials;
113
- const { userRow, principal } = await verifyCredentials({ deps, input, invalidCredentialsMessage });
114
- const { session, rawToken } = await createSessionForPrincipal({ deps, input: { workspaceId: input.workspaceId, principalId: principal.id } }, { ip: input.ip, userAgent: input.userAgent, sessionTtlMs: optional.sessionTtlMs, messages: optional.messages });
115
- // Reuses the session's own `createdAt` rather than a second `kernelNowIso({ clock: clock })` call — both are
116
- // meant to be the same instant, and reading one avoids two clock reads ever disagreeing.
117
- await deps.repos.users.save({ ...userRow, lastLoginAt: session.createdAt });
118
- return { principal, session, rawToken };
112
+ const execute = async () => {
113
+ const input = { ...required.input, ...optional };
114
+ const invalidCredentialsMessage = (optional.messages ?? defaultUserManagementMessages).invalidCredentials;
115
+ const { userRow, principal } = await verifyCredentials({ deps, input, invalidCredentialsMessage });
116
+ if (await deps.mfaStore?.factor({ workspaceId: input.workspaceId, principalId: principal.id })) {
117
+ throw new IdentityValidationError({ message: "This owner requires an authenticator code. Use the two-step sign-in flow to continue." });
118
+ }
119
+ const { session, rawToken } = await createSessionForPrincipal({ deps, input: { workspaceId: input.workspaceId, principalId: principal.id } }, { ip: input.ip, userAgent: input.userAgent, sessionTtlMs: optional.sessionTtlMs, messages: optional.messages });
120
+ // Reuses the session's own `createdAt` rather than a second `kernelNowIso({ clock: clock })` call — both are
121
+ // meant to be the same instant, and reading one avoids two clock reads ever disagreeing.
122
+ await deps.repos.users.save({ ...userRow, lastLoginAt: session.createdAt });
123
+ return { principal, session, rawToken };
124
+ };
125
+ // MFA guard and mint must serialize with activation, which revokes all earlier sessions.
126
+ return deps.mfaStore
127
+ ? inIdentityTransaction({ transactions: deps.repos.transactions, workspaceId: required.input.workspaceId, execute })
128
+ : execute();
119
129
  }
120
130
  /**
121
131
  * Resolve a session cookie's raw token to its principal, applying every
@@ -16,4 +16,15 @@ export * from "./session-tokens.js";
16
16
  export * from "./auth-challenge.js";
17
17
  export { buildIdentityRegistrations, identityDerivedRisk, type IdentityToolDeps } from "./agent-tool-registrations.js";
18
18
  export { defaultUserManagementMessages, type UserManagementMessages } from "./messages.js";
19
+ export { resolveOwnerResetTarget, issueRecoveryCodes, recoverOwner, resetOwnerPassword, type RecoveryCodeStore, type OwnerRecoveryDeps } from './recovery-codes.js';
20
+ export { readHiddenPassword, ownerResetPassword } from './owner-reset-input.js';
21
+ export * from './mfa/ports.js';
22
+ export * from './mfa/service.js';
23
+ export * from './mfa/totp-adapter.js';
24
+ export * from './mfa/secret-adapter.js';
25
+ export * from './mfa/passkey-ports.js';
26
+ export * from './mfa/passkey-service.js';
27
+ export * from './mfa/passkey-adapter.js';
28
+ export { parseLoginProviders } from './login-providers.js';
29
+ export { MemberLoginError, type LoginProvider, type LoginProviderPreset, type MemberLoginOutcomeCode, type VerifiedLoginIdentity, } from './login-types.js';
19
30
  //# sourceMappingURL=index.d.ts.map
@@ -18,4 +18,15 @@ export * from "./session-tokens.js";
18
18
  export * from "./auth-challenge.js";
19
19
  export { buildIdentityRegistrations, identityDerivedRisk } from "./agent-tool-registrations.js";
20
20
  export { defaultUserManagementMessages } from "./messages.js";
21
+ export { resolveOwnerResetTarget, issueRecoveryCodes, recoverOwner, resetOwnerPassword } from './recovery-codes.js';
22
+ export { readHiddenPassword, ownerResetPassword } from './owner-reset-input.js';
23
+ export * from './mfa/ports.js';
24
+ export * from './mfa/service.js';
25
+ export * from './mfa/totp-adapter.js';
26
+ export * from './mfa/secret-adapter.js';
27
+ export * from './mfa/passkey-ports.js';
28
+ export * from './mfa/passkey-service.js';
29
+ export * from './mfa/passkey-adapter.js';
30
+ export { parseLoginProviders } from './login-providers.js';
31
+ export { MemberLoginError, } from './login-types.js';
21
32
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,15 @@
1
+ /** Pure parser for a plugin's member login-provider preset file. Loading, admission and pinning stay with the host. */
2
+ import { type LoginProviderPreset } from "./login-types.js";
3
+ /** Parse a bounded v1 preset file. Failure exposes a fixed code, never raw plugin JSON.
4
+ * @complexity O(bytes + p), bounded to 32 KiB and eight providers per package.
5
+ */
6
+ export declare function parseLoginProviders(required: {
7
+ raw: string;
8
+ }, _options?: Record<string, never>): {
9
+ ok: true;
10
+ descriptors: readonly LoginProviderPreset[];
11
+ } | {
12
+ ok: false;
13
+ reason: string;
14
+ };
15
+ //# sourceMappingURL=login-providers.d.ts.map