@jini-ai/user-management 0.7.3-next.2 → 0.7.3-next.3
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/README.md +55 -2
- package/dist/admin/adapters/memory.js +4 -4
- package/dist/admin-http/auth/auth-request.d.ts +112 -0
- package/dist/admin-http/auth/auth-request.js +32 -0
- package/dist/admin-http/auth/boot-redemption.d.ts +9 -0
- package/dist/admin-http/auth/boot-redemption.js +17 -0
- package/dist/admin-http/auth/boot-session.d.ts +30 -0
- package/dist/admin-http/auth/boot-session.js +40 -0
- package/dist/admin-http/auth/current-user.d.ts +28 -0
- package/dist/admin-http/auth/current-user.js +34 -0
- package/dist/admin-http/auth/index.d.ts +17 -0
- package/dist/admin-http/auth/index.js +9 -0
- package/dist/admin-http/auth/local-boot-session.d.ts +9 -0
- package/dist/admin-http/auth/local-boot-session.js +30 -0
- package/dist/admin-http/auth/logout.d.ts +10 -0
- package/dist/admin-http/auth/logout.js +17 -0
- package/dist/admin-http/auth/mfa-login.d.ts +30 -0
- package/dist/admin-http/auth/mfa-login.js +43 -0
- package/dist/admin-http/auth/password-login.d.ts +35 -0
- package/dist/admin-http/auth/password-login.js +52 -0
- package/dist/admin-http/auth/password-status.d.ts +34 -0
- package/dist/admin-http/auth/password-status.js +42 -0
- package/dist/admin-http/http/api-keys.d.ts +45 -0
- package/dist/admin-http/http/api-keys.js +28 -0
- package/dist/admin-http/http/users.d.ts +71 -0
- package/dist/admin-http/http/users.js +42 -0
- package/dist/admin-http/owner/mfa-deps.d.ts +41 -0
- package/dist/admin-http/owner/mfa-deps.js +26 -0
- package/dist/admin-http/owner/mfa-routes.d.ts +72 -0
- package/dist/admin-http/owner/mfa-routes.js +105 -0
- package/dist/admin-http/owner/passkey-admission.d.ts +46 -0
- package/dist/admin-http/owner/passkey-admission.js +23 -0
- package/dist/admin-http/owner/passkey-route-deps.d.ts +53 -0
- package/dist/admin-http/owner/passkey-route-deps.js +33 -0
- package/dist/admin-http/owner/passkey-routes.d.ts +146 -0
- package/dist/admin-http/owner/passkey-routes.js +98 -0
- package/dist/admin-http/owner/recovery-routes.d.ts +71 -0
- package/dist/admin-http/owner/recovery-routes.js +112 -0
- package/dist/admin-http/routes/api-keys/create-principal.d.ts +26 -0
- package/dist/admin-http/routes/api-keys/create-principal.js +37 -0
- package/dist/admin-http/routes/api-keys/issue.d.ts +32 -0
- package/dist/admin-http/routes/api-keys/issue.js +38 -0
- package/dist/admin-http/routes/api-keys/revoke.d.ts +26 -0
- package/dist/admin-http/routes/api-keys/revoke.js +31 -0
- package/dist/admin-http/routes/api-keys/shared.d.ts +46 -0
- package/dist/admin-http/routes/api-keys/shared.js +38 -0
- package/dist/admin-http/routes/users/access-shared.d.ts +103 -0
- package/dist/admin-http/routes/users/access-shared.js +85 -0
- package/dist/admin-http/routes/users/assign-role.d.ts +24 -0
- package/dist/admin-http/routes/users/assign-role.js +30 -0
- package/dist/admin-http/routes/users/attach-policy.d.ts +25 -0
- package/dist/admin-http/routes/users/attach-policy.js +31 -0
- package/dist/admin-http/routes/users/create-policy.d.ts +19 -0
- package/dist/admin-http/routes/users/create-policy.js +28 -0
- package/dist/admin-http/routes/users/create-role.d.ts +15 -0
- package/dist/admin-http/routes/users/create-role.js +21 -0
- package/dist/admin-http/routes/users/create.d.ts +32 -0
- package/dist/admin-http/routes/users/create.js +67 -0
- package/dist/admin-http/routes/users/delete-policy.d.ts +16 -0
- package/dist/admin-http/routes/users/delete-policy.js +24 -0
- package/dist/admin-http/routes/users/delete-role.d.ts +16 -0
- package/dist/admin-http/routes/users/delete-role.js +24 -0
- package/dist/admin-http/routes/users/delete.d.ts +35 -0
- package/dist/admin-http/routes/users/delete.js +35 -0
- package/dist/admin-http/routes/users/disable.d.ts +31 -0
- package/dist/admin-http/routes/users/disable.js +38 -0
- package/dist/admin-http/routes/users/enable.d.ts +32 -0
- package/dist/admin-http/routes/users/enable.js +45 -0
- package/dist/admin-http/routes/users/list-policies.d.ts +18 -0
- package/dist/admin-http/routes/users/list-policies.js +20 -0
- package/dist/admin-http/routes/users/list-policy-permissions.d.ts +28 -0
- package/dist/admin-http/routes/users/list-policy-permissions.js +30 -0
- package/dist/admin-http/routes/users/list-roles.d.ts +18 -0
- package/dist/admin-http/routes/users/list-roles.js +20 -0
- package/dist/admin-http/routes/users/list.d.ts +40 -0
- package/dist/admin-http/routes/users/list.js +82 -0
- package/dist/admin-http/routes/users/remove-policy-permission.d.ts +48 -0
- package/dist/admin-http/routes/users/remove-policy-permission.js +62 -0
- package/dist/admin-http/routes/users/reset-password.d.ts +33 -0
- package/dist/admin-http/routes/users/reset-password.js +52 -0
- package/dist/admin-http/routes/users/shared.d.ts +124 -0
- package/dist/admin-http/routes/users/shared.js +93 -0
- package/dist/admin-http/routes/users/update-policy.d.ts +25 -0
- package/dist/admin-http/routes/users/update-policy.js +30 -0
- package/dist/admin-http/routes/users/update-role.d.ts +23 -0
- package/dist/admin-http/routes/users/update-role.js +29 -0
- package/dist/admin-http/routes/users/update.d.ts +35 -0
- package/dist/admin-http/routes/users/update.js +78 -0
- package/dist/admin-http/routes/users/write-policy-permission.d.ts +31 -0
- package/dist/admin-http/routes/users/write-policy-permission.js +45 -0
- package/dist/core/ports.d.ts +22 -3
- package/dist/core/types.d.ts +17 -5
- package/dist/core/types.js +12 -0
- package/dist/identity/api-key-secret.d.ts +68 -0
- package/dist/identity/api-key-secret.js +229 -0
- package/dist/identity/api-key-service.d.ts +144 -0
- package/dist/identity/api-key-service.js +389 -0
- package/dist/identity/api-key-types.d.ts +79 -0
- package/dist/identity/api-key-types.js +2 -0
- package/dist/identity/boot-session-token.d.ts +18 -0
- package/dist/identity/boot-session-token.js +92 -0
- package/dist/identity/builtin-role-grants.d.ts +120 -0
- package/dist/identity/builtin-role-grants.js +88 -0
- package/dist/identity/delete-user-service.d.ts +195 -0
- package/dist/identity/delete-user-service.js +275 -0
- package/dist/identity/owner-reset-env.d.ts +37 -0
- package/dist/identity/owner-reset-env.js +38 -0
- package/dist/identity/permission-grants.d.ts +31 -0
- package/dist/identity/permission-grants.js +12 -0
- package/dist/identity/permission-list-tool.d.ts +35 -0
- package/dist/identity/permission-list-tool.js +47 -0
- package/dist/identity/repo.authentication.d.ts +57 -0
- package/dist/identity/repo.authentication.js +153 -0
- package/dist/identity/repo.authorization.d.ts +82 -0
- package/dist/identity/repo.authorization.js +203 -0
- package/dist/identity/repo.d.ts +87 -0
- package/dist/identity/repo.js +167 -0
- package/dist/identity/repo.memory.d.ts +31 -0
- package/dist/identity/repo.memory.js +37 -0
- package/dist/identity/role-manage-permission.d.ts +34 -0
- package/dist/identity/role-manage-permission.js +39 -0
- package/dist/identity/site-key-permission.d.ts +66 -0
- package/dist/identity/site-key-permission.js +92 -0
- package/dist/identity/sql/kernel-user-purge.d.ts +19 -0
- package/dist/identity/sql/kernel-user-purge.js +34 -0
- package/dist/identity/sql/kernel-user-trash-store.d.ts +15 -0
- package/dist/identity/sql/kernel-user-trash-store.js +41 -0
- package/dist/identity/sql/user-trash-adapter.d.ts +87 -0
- package/dist/identity/sql/user-trash-adapter.js +124 -0
- package/dist/identity/tool-registrations.d.ts +100 -0
- package/dist/identity/tool-registrations.js +257 -0
- package/dist/identity/user-manage-permission.d.ts +8 -0
- package/dist/identity/user-manage-permission.js +8 -0
- package/dist/identity/user-purge-types.d.ts +85 -0
- package/dist/identity/user-purge-types.js +17 -0
- package/dist/identity/user-purge.d.ts +69 -0
- package/dist/identity/user-purge.js +46 -0
- package/dist/identity/username-change-ports.d.ts +15 -0
- package/dist/identity/username-change-ports.js +22 -0
- package/dist/mail/site/capture-clear.d.ts +58 -0
- package/dist/mail/site/capture-clear.js +21 -0
- package/dist/mail/status/agent-tools.d.ts +65 -0
- package/dist/mail/status/agent-tools.js +22 -0
- package/dist/mail/status/delivery-agent-tools.d.ts +206 -0
- package/dist/mail/status/delivery-agent-tools.js +63 -0
- package/dist/mail/status/delivery-tool-registrations.d.ts +216 -0
- package/dist/mail/status/delivery-tool-registrations.js +110 -0
- package/dist/mail/status/domain-deps.d.ts +25 -0
- package/dist/mail/status/domain-deps.js +23 -0
- package/dist/mail/status/permissions.d.ts +43 -0
- package/dist/mail/status/permissions.js +45 -0
- package/dist/mail/status/provider-agent-tools.d.ts +38 -0
- package/dist/mail/status/provider-agent-tools.js +17 -0
- package/dist/mail/status/provider-operations.d.ts +166 -0
- package/dist/mail/status/provider-operations.js +121 -0
- package/dist/mail/status/provider-tool-registrations.d.ts +65 -0
- package/dist/mail/status/provider-tool-registrations.js +106 -0
- package/dist/mail/status/tool-registrations.d.ts +152 -0
- package/dist/mail/status/tool-registrations.js +112 -0
- package/dist/member-login/credentials.d.ts +40 -0
- package/dist/member-login/credentials.js +26 -0
- package/dist/member-login/link-service.d.ts +66 -0
- package/dist/member-login/link-service.js +141 -0
- package/dist/member-login/oidc-login.d.ts +132 -0
- package/dist/member-login/oidc-login.js +206 -0
- package/dist/member-login/oidc-request.d.ts +80 -0
- package/dist/member-login/oidc-request.js +86 -0
- package/dist/member-login/providers.d.ts +79 -0
- package/dist/member-login/providers.js +41 -0
- package/dist/member-login/ready-providers.d.ts +17 -0
- package/dist/member-login/ready-providers.js +11 -0
- package/dist/member-login/unlink-identity.d.ts +26 -0
- package/dist/member-login/unlink-identity.js +59 -0
- package/dist/members/access-resolver.d.ts +107 -0
- package/dist/members/access-resolver.js +231 -0
- package/dist/members/agent-tools.d.ts +14 -0
- package/dist/members/agent-tools.js +139 -0
- package/dist/members/auth-mail.d.ts +27 -0
- package/dist/members/auth-mail.js +21 -0
- package/dist/members/capability-card.d.ts +18 -0
- package/dist/members/capability-card.js +27 -0
- package/dist/members/consent-service.d.ts +115 -0
- package/dist/members/consent-service.js +179 -0
- package/dist/members/member-admin-writes.d.ts +73 -0
- package/dist/members/member-admin-writes.js +149 -0
- package/dist/members/member-challenge-request.d.ts +59 -0
- package/dist/members/member-challenge-request.js +145 -0
- package/dist/members/member-challenge.d.ts +37 -0
- package/dist/members/member-challenge.js +84 -0
- package/dist/members/member-credentials.d.ts +35 -0
- package/dist/members/member-credentials.js +57 -0
- package/dist/members/member-sign-in.d.ts +44 -0
- package/dist/members/member-sign-in.js +130 -0
- package/dist/members/member-validation.d.ts +5 -0
- package/dist/members/member-validation.js +13 -0
- package/dist/members/password-auth.d.ts +55 -0
- package/dist/members/password-auth.js +177 -0
- package/dist/members/ports.d.ts +455 -0
- package/dist/members/ports.js +21 -0
- package/dist/members/public-member-auth-response.d.ts +68 -0
- package/dist/members/public-member-auth-response.js +45 -0
- package/dist/members/public-member-response.d.ts +25 -0
- package/dist/members/public-member-response.js +15 -0
- package/dist/members/repo.d.ts +199 -0
- package/dist/members/repo.js +324 -0
- package/dist/members/repo.memory.d.ts +276 -0
- package/dist/members/repo.memory.js +395 -0
- package/dist/members/repo.rows.d.ts +153 -0
- package/dist/members/repo.rows.js +250 -0
- package/dist/members/repo.sessions.d.ts +80 -0
- package/dist/members/repo.sessions.js +166 -0
- package/dist/members/repo.sql.d.ts +9 -0
- package/dist/members/repo.sql.js +11 -0
- package/dist/members/subscriber-directory.d.ts +85 -0
- package/dist/members/subscriber-directory.js +70 -0
- package/dist/members/tool-registrations.d.ts +143 -0
- package/dist/members/tool-registrations.js +247 -0
- package/dist/members/trash-member.d.ts +24 -0
- package/dist/members/trash-member.js +24 -0
- package/dist/members/types.d.ts +321 -0
- package/dist/members/types.js +34 -0
- package/dist/members/write-service.d.ts +17 -0
- package/dist/members/write-service.js +15 -0
- package/dist/newsletter/agent-tools.d.ts +20 -0
- package/dist/newsletter/agent-tools.js +236 -0
- package/dist/newsletter/campaign-write-service.d.ts +92 -0
- package/dist/newsletter/campaign-write-service.js +190 -0
- package/dist/newsletter/campaign.d.ts +53 -0
- package/dist/newsletter/campaign.js +95 -0
- package/dist/newsletter/confirmation.d.ts +75 -0
- package/dist/newsletter/confirmation.js +142 -0
- package/dist/newsletter/data-module-manifest.d.ts +68 -0
- package/dist/newsletter/data-module-manifest.js +126 -0
- package/dist/newsletter/delivery/tool-registrations.d.ts +67 -0
- package/dist/newsletter/delivery/tool-registrations.js +229 -0
- package/dist/newsletter/errors.d.ts +93 -0
- package/dist/newsletter/errors.js +93 -0
- package/dist/newsletter/hooks.d.ts +59 -0
- package/dist/newsletter/hooks.js +49 -0
- package/dist/newsletter/http-error-responses.d.ts +17 -0
- package/dist/newsletter/http-error-responses.js +96 -0
- package/dist/newsletter/launch-gate.d.ts +62 -0
- package/dist/newsletter/launch-gate.js +29 -0
- package/dist/newsletter/lists.d.ts +60 -0
- package/dist/newsletter/lists.js +83 -0
- package/dist/newsletter/ports.d.ts +278 -0
- package/dist/newsletter/ports.js +2 -0
- package/dist/newsletter/repo-sends.d.ts +82 -0
- package/dist/newsletter/repo-sends.js +178 -0
- package/dist/newsletter/repo-subscribers.d.ts +82 -0
- package/dist/newsletter/repo-subscribers.js +193 -0
- package/dist/newsletter/repo.d.ts +61 -0
- package/dist/newsletter/repo.js +147 -0
- package/dist/newsletter/repo.memory.d.ts +201 -0
- package/dist/newsletter/repo.memory.js +250 -0
- package/dist/newsletter/repo.rows.d.ts +221 -0
- package/dist/newsletter/repo.rows.js +260 -0
- package/dist/newsletter/send-pipeline.d.ts +236 -0
- package/dist/newsletter/send-pipeline.js +514 -0
- package/dist/newsletter/subscriptions.d.ts +87 -0
- package/dist/newsletter/subscriptions.js +119 -0
- package/dist/newsletter/tool-registrations.d.ts +89 -0
- package/dist/newsletter/tool-registrations.deps.d.ts +9 -0
- package/dist/newsletter/tool-registrations.deps.js +9 -0
- package/dist/newsletter/tool-registrations.js +133 -0
- package/dist/newsletter/tool-registrations.read.d.ts +76 -0
- package/dist/newsletter/tool-registrations.read.js +140 -0
- package/dist/newsletter/tool-registrations.write.d.ts +54 -0
- package/dist/newsletter/tool-registrations.write.js +229 -0
- package/dist/newsletter/types.d.ts +279 -0
- package/dist/newsletter/types.js +23 -0
- package/dist/newsletter/unsubscribe.d.ts +41 -0
- package/dist/newsletter/unsubscribe.js +100 -0
- package/dist/project-keys/attached-vault.d.ts +23 -0
- package/dist/project-keys/attached-vault.js +65 -0
- package/dist/project-keys/create-vault.d.ts +17 -0
- package/dist/project-keys/create-vault.js +29 -0
- package/dist/project-keys/service.d.ts +133 -0
- package/dist/project-keys/service.js +128 -0
- package/dist/project-keys/site-references.d.ts +30 -0
- package/dist/project-keys/site-references.js +63 -0
- package/dist/project-keys/site-sealer.d.ts +28 -0
- package/dist/project-keys/site-sealer.js +64 -0
- package/dist/project-keys/sql/attachments.d.ts +33 -0
- package/dist/project-keys/sql/attachments.js +55 -0
- package/dist/project-keys/tools.d.ts +86 -0
- package/dist/project-keys/tools.js +66 -0
- package/dist/public-http/routes/mail/feedback.d.ts +44 -0
- package/dist/public-http/routes/mail/feedback.js +17 -0
- package/dist/public-http/routes/newsletter/confirm.d.ts +38 -0
- package/dist/public-http/routes/newsletter/confirm.js +33 -0
- package/dist/public-http/routes/newsletter/page.d.ts +29 -0
- package/dist/public-http/routes/newsletter/page.js +34 -0
- package/dist/public-http/routes/newsletter/unsubscribe.d.ts +33 -0
- package/dist/public-http/routes/newsletter/unsubscribe.js +35 -0
- package/dist/react/auth/Passkeys.d.ts +2 -34
- package/dist/react/auth/RecoveryCodesCard.d.ts +27 -0
- package/dist/react/auth/RecoveryCodesCard.hooks.d.ts +67 -0
- package/dist/react/auth/RecoveryCodesCard.hooks.js +38 -0
- package/dist/react/auth/RecoveryCodesCard.js +56 -0
- package/dist/react/auth/TotpSettings.d.ts +2 -23
- package/dist/react/auth/local-owner-signin.d.ts +40 -0
- package/dist/react/auth/local-owner-signin.js +25 -0
- package/dist/react/auth/owner-mfa-api.d.ts +10 -0
- package/dist/react/auth/owner-mfa-api.js +17 -0
- package/dist/react/auth/owner-passkey-api.d.ts +11 -0
- package/dist/react/auth/owner-passkey-api.js +17 -0
- package/dist/react/auth/owner-recovery-api.d.ts +51 -0
- package/dist/react/auth/owner-recovery-api.js +29 -0
- package/dist/react/auth/owner-request.d.ts +7 -0
- package/dist/react/auth/owner-request.js +2 -0
- package/dist/react/index.d.ts +10 -0
- package/dist/react/index.js +6 -0
- package/dist/react/mail/Email.d.ts +20 -0
- package/dist/react/mail/Email.js +143 -0
- package/dist/react/mail/EmailProviderTab.d.ts +34 -0
- package/dist/react/mail/EmailProviderTab.js +132 -0
- package/dist/react/mail/EmailSegments.d.ts +24 -0
- package/dist/react/mail/EmailSegments.js +15 -0
- package/dist/react/mail/EmailTemplateEditor.d.ts +146 -0
- package/dist/react/mail/EmailTemplateEditor.js +116 -0
- package/dist/react/mail/email-view.types.d.ts +236 -0
- package/dist/react/mail/email-view.types.js +2 -0
- package/dist/react/members/Members.d.ts +5 -3
- package/dist/react/members/Members.js +3 -3
- package/dist/react/members/api/members-api.d.ts +37 -0
- package/dist/react/members/api/members-api.js +16 -0
- package/dist/react/members/hooks/use-members.hooks.js +2 -1
- package/dist/react/members/members-i18n.d.ts +23 -0
- package/dist/react/members/members-i18n.js +25 -0
- package/dist/react/members/members-i18n.locales-a.d.ts +4 -0
- package/dist/react/members/members-i18n.locales-a.js +294 -0
- package/dist/react/members/members-i18n.locales-b.d.ts +4 -0
- package/dist/react/members/members-i18n.locales-b.js +265 -0
- package/dist/react/models.d.ts +1 -49
- package/dist/react/ports.d.ts +3 -143
- package/dist/react/roles/api/roles-api.d.ts +74 -0
- package/dist/react/roles/api/roles-api.js +22 -0
- package/dist/react/testing.js +18 -9
- package/dist/react/users/UsersPanel.d.ts +30 -0
- package/dist/react/users/UsersPanel.hooks.d.ts +8 -0
- package/dist/react/users/UsersPanel.hooks.js +9 -0
- package/dist/react/users/UsersPanel.js +9 -0
- package/dist/react/users/api/users-api.d.ts +65 -0
- package/dist/react/users/api/users-api.js +46 -0
- package/dist/react/users/hooks/use-localized-users.hooks.d.ts +43 -0
- package/dist/react/users/hooks/use-localized-users.hooks.js +15 -0
- package/dist/react/users/hooks/use-users-state.hooks.d.ts +18 -18
- package/dist/react/users/password-reset-notice.d.ts +8 -0
- package/dist/react/users/password-reset-notice.js +36 -0
- package/dist/server/admin-crud-service.d.ts +4 -10
- package/dist/server/admin-crud-service.js +20 -6
- package/dist/server/agent-tool-registrations.js +20 -5
- package/dist/server/agent-tools.js +16 -3
- package/dist/server/auth-challenge.d.ts +1 -1
- package/dist/server/auth-service.js +2 -1
- package/dist/server/grant-service.d.ts +1 -0
- package/dist/server/grant-service.js +7 -4
- package/dist/server/mfa/passkey-service.d.ts +2 -2
- package/dist/server/mfa/passkey-service.js +1 -1
- package/dist/server/mfa/service.js +6 -4
- package/dist/server/repo.memory.d.ts +30 -2
- package/dist/server/repo.memory.js +58 -4
- package/dist/server/seed.js +3 -3
- package/dist/server/sql/assignments.d.ts +90 -0
- package/dist/server/sql/assignments.js +128 -0
- package/dist/server/sql/index.d.ts +6 -0
- package/dist/server/sql/index.js +5 -0
- package/dist/server/sql/kernel.d.ts +9 -0
- package/dist/server/sql/kernel.js +2 -0
- package/dist/server/sql/mfa.d.ts +36 -0
- package/dist/server/sql/mfa.js +51 -0
- package/dist/server/sql/passkeys.d.ts +25 -0
- package/dist/server/sql/passkeys.js +33 -0
- package/dist/server/sql/recovery-codes.d.ts +22 -0
- package/dist/server/sql/recovery-codes.js +32 -0
- package/package.json +909 -11
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineJsonRoute, ok } from '@jini-ai/core/contracts/server';
|
|
2
|
+
import { AuthInvalidCredentialsError } from '../../core/types.js';
|
|
3
|
+
import { bodyRecord, refuse, requireAuthRequest } from './auth-request.js';
|
|
4
|
+
/**
|
|
5
|
+
* Coerced exactly as the original route did: any value becomes its string form, absence becomes "".
|
|
6
|
+
* Some valid JSON values (`{"toString":1}`) throw here, so this runs inside the handler's error
|
|
7
|
+
* boundary and after the limiter: a denied request always gets its exact 429.
|
|
8
|
+
*/
|
|
9
|
+
function credentialFields({ body }) {
|
|
10
|
+
return { username: String(body.username ?? ''), password: String(body.password ?? '') };
|
|
11
|
+
}
|
|
12
|
+
/** Wrong credentials are a deliberate 401; every other failure is the host's to report. */
|
|
13
|
+
async function refusingInvalidCredentials(run) {
|
|
14
|
+
try {
|
|
15
|
+
return await run();
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error instanceof AuthInvalidCredentialsError)
|
|
19
|
+
refuse({ status: 401, body: { error: 'invalid username or password', code: 'UNAUTHENTICATED' } });
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function passwordLogin({ input, deps, auth }) {
|
|
24
|
+
await deps.identityReady;
|
|
25
|
+
const rate = await auth.rateLimit.check();
|
|
26
|
+
if (!rate.allowed) {
|
|
27
|
+
auth.retryAfter(rate.retryAfterSeconds);
|
|
28
|
+
refuse({ status: 429, body: { error: 'too many login attempts', code: 'RATE_LIMIT_EXCEEDED', details: { retryAfterSeconds: rate.retryAfterSeconds } } });
|
|
29
|
+
}
|
|
30
|
+
const { username, password } = credentialFields(input);
|
|
31
|
+
const signIn = deps.mfaStore ? deps.beginOwnerLogin : deps.login;
|
|
32
|
+
const result = await signIn({ input: { workspaceId: deps.workspaceId, username, password } }, auth.sessionOptions());
|
|
33
|
+
// Cache-Control is set only once the credentials succeeded; the 401 and 429 answers never carry it.
|
|
34
|
+
auth.noStore();
|
|
35
|
+
if ('mfaRequired' in result)
|
|
36
|
+
return result;
|
|
37
|
+
const { principal, session, rawToken } = result;
|
|
38
|
+
// Credentials succeeded; revoke both superseded bearers before clearing/replacing cookies.
|
|
39
|
+
await auth.revokeSessions();
|
|
40
|
+
auth.cookies.replaceSession({ rawToken, expiresAtIso: session.expiresAt });
|
|
41
|
+
auth.signedIn({ principalId: principal.id });
|
|
42
|
+
return { user: { id: principal.id, username } };
|
|
43
|
+
}
|
|
44
|
+
/** `POST /api/admin/v1/auth/login`: password sign-in, or the start of an owner MFA challenge. */
|
|
45
|
+
export const passwordLoginRoute = defineJsonRoute({
|
|
46
|
+
method: 'post',
|
|
47
|
+
path: '/api/admin/v1/auth/login',
|
|
48
|
+
// Total: the body is carried through; coercion happens in the handler after the limiter.
|
|
49
|
+
parse: raw => ok({ value: { body: bodyRecord({ body: raw.body }) } }),
|
|
50
|
+
handle: async ({ input, deps, context }) => ok({ value: await refusingInvalidCredentials(() => passwordLogin({ input, deps, auth: requireAuthRequest({ context }) })) }),
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=password-login.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type CurrentPrincipalAuth } from './auth-request.js';
|
|
2
|
+
export interface PasswordStatusRouteDeps {
|
|
3
|
+
readonly workspaceId: string;
|
|
4
|
+
readonly findUserByPrincipalId: (required: {
|
|
5
|
+
workspaceId: string;
|
|
6
|
+
principalId: string;
|
|
7
|
+
}) => Promise<{
|
|
8
|
+
readonly passwordHash: string;
|
|
9
|
+
} | null | undefined>;
|
|
10
|
+
readonly verifyPassword: (required: {
|
|
11
|
+
hash: string;
|
|
12
|
+
password: string;
|
|
13
|
+
}) => Promise<boolean>;
|
|
14
|
+
/** The host's seeded owner password; the banner warns while the caller's own row still verifies against it. */
|
|
15
|
+
readonly defaultOwnerPassword: string;
|
|
16
|
+
}
|
|
17
|
+
/** `GET /api/admin/v1/auth/me/password-status`, one per registration.
|
|
18
|
+
*
|
|
19
|
+
* Tells the DASHBOARD (not deployment-overview, which is owner-only and `system.read`-gated)
|
|
20
|
+
* whether the SIGNED-IN CALLER's own stored credential still verifies against the default owner
|
|
21
|
+
* password. No extra permission is needed — it's a check against your own row, so it can't be used
|
|
22
|
+
* to probe anyone else's password. Deliberately a separate route from `/auth/me` rather than a
|
|
23
|
+
* field on it: that route runs on every admin boot, and only the dashboard needs the ~tens-of-ms
|
|
24
|
+
* argon2id verify this adds.
|
|
25
|
+
*
|
|
26
|
+
* Results are memoized by the stored hash: argon2id is deliberately expensive, and a signed-in
|
|
27
|
+
* session could otherwise call this in a loop. A hash is salted per write, so any password change
|
|
28
|
+
* produces a new key and is re-verified — the cache can never report a stale answer. Capped and
|
|
29
|
+
* cleared wholesale; it only holds hashes already in the DB and booleans.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createPasswordStatusRoute(_required?: Record<string, never>, _optional?: Record<string, never>): import("@jini-ai/core/contracts/server").JsonRouteSpec<Record<string, never>, {
|
|
32
|
+
usesDefaultPassword: boolean;
|
|
33
|
+
}, PasswordStatusRouteDeps, CurrentPrincipalAuth>;
|
|
34
|
+
//# sourceMappingURL=password-status.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { defineJsonRoute, ok } from '@jini-ai/core/contracts/server';
|
|
2
|
+
import { requireAuthRequest } from './auth-request.js';
|
|
3
|
+
import { signedInPrincipal } from './current-user.js';
|
|
4
|
+
/** `GET /api/admin/v1/auth/me/password-status`, one per registration.
|
|
5
|
+
*
|
|
6
|
+
* Tells the DASHBOARD (not deployment-overview, which is owner-only and `system.read`-gated)
|
|
7
|
+
* whether the SIGNED-IN CALLER's own stored credential still verifies against the default owner
|
|
8
|
+
* password. No extra permission is needed — it's a check against your own row, so it can't be used
|
|
9
|
+
* to probe anyone else's password. Deliberately a separate route from `/auth/me` rather than a
|
|
10
|
+
* field on it: that route runs on every admin boot, and only the dashboard needs the ~tens-of-ms
|
|
11
|
+
* argon2id verify this adds.
|
|
12
|
+
*
|
|
13
|
+
* Results are memoized by the stored hash: argon2id is deliberately expensive, and a signed-in
|
|
14
|
+
* session could otherwise call this in a loop. A hash is salted per write, so any password change
|
|
15
|
+
* produces a new key and is re-verified — the cache can never report a stale answer. Capped and
|
|
16
|
+
* cleared wholesale; it only holds hashes already in the DB and booleans.
|
|
17
|
+
*/
|
|
18
|
+
export function createPasswordStatusRoute(_required = {}, _optional = {}) {
|
|
19
|
+
const defaultPasswordByHash = new Map();
|
|
20
|
+
const usesDefaultPasswordFor = async ({ passwordHash, deps }) => {
|
|
21
|
+
const cached = defaultPasswordByHash.get(passwordHash);
|
|
22
|
+
if (cached !== undefined)
|
|
23
|
+
return cached;
|
|
24
|
+
const result = await deps.verifyPassword({ hash: passwordHash, password: deps.defaultOwnerPassword });
|
|
25
|
+
if (defaultPasswordByHash.size >= 256)
|
|
26
|
+
defaultPasswordByHash.clear();
|
|
27
|
+
defaultPasswordByHash.set(passwordHash, result);
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
return defineJsonRoute({
|
|
31
|
+
method: 'get',
|
|
32
|
+
path: '/api/admin/v1/auth/me/password-status',
|
|
33
|
+
parse: () => ok({ value: {} }),
|
|
34
|
+
handle: async ({ deps, context }) => {
|
|
35
|
+
const principal = await signedInPrincipal({ auth: requireAuthRequest({ context }) });
|
|
36
|
+
const userRow = await deps.findUserByPrincipalId({ workspaceId: deps.workspaceId, principalId: principal.id });
|
|
37
|
+
const usesDefaultPassword = userRow ? await usesDefaultPasswordFor({ passwordHash: userRow.passwordHash, deps }) : false;
|
|
38
|
+
return ok({ value: { usesDefaultPassword } });
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=password-status.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PrincipalRecord } from "../../core/types.js";
|
|
2
|
+
import type { ApiKeyRecord } from "../../identity/api-key-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* @file Admin-facing api-key response DTOs (mirrors `@jini-ai/user-management/admin-http/http/users`'s pattern).
|
|
5
|
+
*
|
|
6
|
+
* Purpose:
|
|
7
|
+
* The one place that decides what an api-key row may show a client. `ApiKeyRecord.keyHash` has no
|
|
8
|
+
* field on any shape here, so there is nothing to forward by accident (INV-05) — the same
|
|
9
|
+
* structural defence `AdminUserResponse` uses against `UserRecord.passwordHash`.
|
|
10
|
+
*
|
|
11
|
+
* `rawKey` is the deliberate exception, and it is NOT read off a record: `toApiKeyIssueResponse`
|
|
12
|
+
* takes it as a separate argument, because the only value that ever carries it is `issueApiKey`'s
|
|
13
|
+
* in-memory return, never a row. A second call for the same key cannot re-emit it.
|
|
14
|
+
*/
|
|
15
|
+
/** Admin-facing shape of a principal minted by `APIKEY_PRINCIPAL_CREATE`. */
|
|
16
|
+
export interface AdminApiKeyPrincipalResponse {
|
|
17
|
+
id: string;
|
|
18
|
+
kind: "api_key";
|
|
19
|
+
status: PrincipalRecord["status"];
|
|
20
|
+
workspaceId: string;
|
|
21
|
+
displayName: string;
|
|
22
|
+
}
|
|
23
|
+
/** Admin-facing shape of a freshly issued key — the ONLY shape carrying `rawKey`. */
|
|
24
|
+
export interface AdminApiKeyIssueResponse {
|
|
25
|
+
id: string;
|
|
26
|
+
/** Shown exactly once, at issuance. Only the hash is persisted. */
|
|
27
|
+
rawKey: string;
|
|
28
|
+
principalId: string;
|
|
29
|
+
label: string;
|
|
30
|
+
expiresAt: string | null;
|
|
31
|
+
}
|
|
32
|
+
/** Serialize the minted machine principal. @complexity O(1). @overallScore 100 */
|
|
33
|
+
export declare function toApiKeyPrincipalResponse(principal: PrincipalRecord): AdminApiKeyPrincipalResponse;
|
|
34
|
+
/**
|
|
35
|
+
* Serialize an issued key together with its one-time raw value.
|
|
36
|
+
*
|
|
37
|
+
* @param required.rawKey - passed in separately, never sourced from `apiKey` — see the file header.
|
|
38
|
+
* @complexity O(1).
|
|
39
|
+
* @overallScore 100
|
|
40
|
+
*/
|
|
41
|
+
export declare function toApiKeyIssueResponse(required: {
|
|
42
|
+
apiKey: ApiKeyRecord;
|
|
43
|
+
rawKey: string;
|
|
44
|
+
}): AdminApiKeyIssueResponse;
|
|
45
|
+
//# sourceMappingURL=api-keys.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Serialize the minted machine principal. @complexity O(1). @overallScore 100 */
|
|
2
|
+
export function toApiKeyPrincipalResponse(principal) {
|
|
3
|
+
return {
|
|
4
|
+
id: principal.id,
|
|
5
|
+
kind: "api_key",
|
|
6
|
+
status: principal.status,
|
|
7
|
+
workspaceId: principal.workspaceId,
|
|
8
|
+
displayName: principal.displayName,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Serialize an issued key together with its one-time raw value.
|
|
13
|
+
*
|
|
14
|
+
* @param required.rawKey - passed in separately, never sourced from `apiKey` — see the file header.
|
|
15
|
+
* @complexity O(1).
|
|
16
|
+
* @overallScore 100
|
|
17
|
+
*/
|
|
18
|
+
export function toApiKeyIssueResponse(required) {
|
|
19
|
+
const { apiKey, rawKey } = required;
|
|
20
|
+
return {
|
|
21
|
+
id: apiKey.id,
|
|
22
|
+
rawKey,
|
|
23
|
+
principalId: apiKey.principalId,
|
|
24
|
+
label: apiKey.label,
|
|
25
|
+
expiresAt: apiKey.expiresAt ?? null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=api-keys.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { PolicyRecord, PrincipalRecord, RoleRecord, UserRecord } from "../../core/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @file Admin-facing user/role/policy response DTOs (same split as the admin members DTO helper).
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* Maps internal identity records to what the admin API/UI may see.
|
|
7
|
+
* Deliberately excludes `UserRecord.passwordHash` (INV-05: raw/hashed
|
|
8
|
+
* secrets never leave the server) — `AdminUserResponse` has no field for it,
|
|
9
|
+
* so there is nothing to accidentally forward. Role/policy assignments are
|
|
10
|
+
* returned as bare id arrays (`roleIds`/`policyIds`) rather than resolved
|
|
11
|
+
* names: the admin UI already fetches the full roles/policies lists to
|
|
12
|
+
* populate its pickers, so resolving names here would be a redundant N+1
|
|
13
|
+
* `findById` fan-out per user for data the client already has.
|
|
14
|
+
*/
|
|
15
|
+
/** Admin-facing shape of a user (principal + credential row, grants as id references).
|
|
16
|
+
* Optional fields admit `undefined` because Jini compiles with `exactOptionalPropertyTypes`; JSON drops
|
|
17
|
+
* an `undefined` field, so the wire body is unchanged from the host original. */
|
|
18
|
+
export interface AdminUserResponse {
|
|
19
|
+
principalId: string;
|
|
20
|
+
workspaceId: string;
|
|
21
|
+
username: string;
|
|
22
|
+
email?: string | undefined;
|
|
23
|
+
status: PrincipalRecord["status"];
|
|
24
|
+
createdAt: string;
|
|
25
|
+
lastLoginAt?: string | undefined;
|
|
26
|
+
roleIds: string[];
|
|
27
|
+
policyIds: string[];
|
|
28
|
+
/** Editor basis for the profile fields: send it back as `expectedVersion` on PATCH. */
|
|
29
|
+
version: number;
|
|
30
|
+
}
|
|
31
|
+
/** Admin-facing shape of a role. */
|
|
32
|
+
export interface AdminRoleResponse {
|
|
33
|
+
id: string;
|
|
34
|
+
workspaceId: string;
|
|
35
|
+
name: string;
|
|
36
|
+
isBuiltin: boolean;
|
|
37
|
+
/** Editor basis: send it back as `expectedVersion` on PATCH. */
|
|
38
|
+
version: number;
|
|
39
|
+
}
|
|
40
|
+
/** Admin-facing shape of a policy. */
|
|
41
|
+
export interface AdminPolicyResponse {
|
|
42
|
+
id: string;
|
|
43
|
+
workspaceId: string;
|
|
44
|
+
name: string;
|
|
45
|
+
description?: string | undefined;
|
|
46
|
+
isBuiltin: boolean;
|
|
47
|
+
isFrozen: boolean;
|
|
48
|
+
/** Editor basis: send it back as `expectedVersion` on PATCH. */
|
|
49
|
+
version: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Serialize a `(PrincipalRecord, UserRecord)` pair plus its grant id lists to
|
|
53
|
+
* `AdminUserResponse`. Both records must share the same `principalId`
|
|
54
|
+
* (CREATE_USER's atomicity guarantee, see `grant-service.ts`) — this
|
|
55
|
+
* function does not itself re-validate that pairing, it trusts the caller
|
|
56
|
+
* fetched them together.
|
|
57
|
+
*
|
|
58
|
+
* @complexity O(1).
|
|
59
|
+
* @overallScore 100
|
|
60
|
+
*/
|
|
61
|
+
export declare function toAdminUserResponse(required: {
|
|
62
|
+
principal: PrincipalRecord;
|
|
63
|
+
user: UserRecord;
|
|
64
|
+
roleIds: string[];
|
|
65
|
+
policyIds: string[];
|
|
66
|
+
}): AdminUserResponse;
|
|
67
|
+
/** Serialize a `RoleRecord` to `AdminRoleResponse`. @complexity O(1). @overallScore 100 */
|
|
68
|
+
export declare function toAdminRoleResponse(role: RoleRecord): AdminRoleResponse;
|
|
69
|
+
/** Serialize a `PolicyRecord` to `AdminPolicyResponse`. @complexity O(1). @overallScore 100 */
|
|
70
|
+
export declare function toAdminPolicyResponse(policy: PolicyRecord): AdminPolicyResponse;
|
|
71
|
+
//# sourceMappingURL=users.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialize a `(PrincipalRecord, UserRecord)` pair plus its grant id lists to
|
|
3
|
+
* `AdminUserResponse`. Both records must share the same `principalId`
|
|
4
|
+
* (CREATE_USER's atomicity guarantee, see `grant-service.ts`) — this
|
|
5
|
+
* function does not itself re-validate that pairing, it trusts the caller
|
|
6
|
+
* fetched them together.
|
|
7
|
+
*
|
|
8
|
+
* @complexity O(1).
|
|
9
|
+
* @overallScore 100
|
|
10
|
+
*/
|
|
11
|
+
export function toAdminUserResponse(required) {
|
|
12
|
+
const { principal, user, roleIds, policyIds } = required;
|
|
13
|
+
return {
|
|
14
|
+
principalId: principal.id,
|
|
15
|
+
workspaceId: principal.workspaceId,
|
|
16
|
+
username: user.username,
|
|
17
|
+
email: user.email,
|
|
18
|
+
status: principal.status,
|
|
19
|
+
createdAt: principal.createdAt,
|
|
20
|
+
lastLoginAt: user.lastLoginAt,
|
|
21
|
+
roleIds,
|
|
22
|
+
policyIds,
|
|
23
|
+
version: user.version,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Serialize a `RoleRecord` to `AdminRoleResponse`. @complexity O(1). @overallScore 100 */
|
|
27
|
+
export function toAdminRoleResponse(role) {
|
|
28
|
+
return { id: role.id, workspaceId: role.workspaceId, name: role.name, isBuiltin: role.isBuiltin, version: role.version };
|
|
29
|
+
}
|
|
30
|
+
/** Serialize a `PolicyRecord` to `AdminPolicyResponse`. @complexity O(1). @overallScore 100 */
|
|
31
|
+
export function toAdminPolicyResponse(policy) {
|
|
32
|
+
return {
|
|
33
|
+
id: policy.id,
|
|
34
|
+
workspaceId: policy.workspaceId,
|
|
35
|
+
name: policy.name,
|
|
36
|
+
description: policy.description,
|
|
37
|
+
isBuiltin: policy.isBuiltin,
|
|
38
|
+
isFrozen: policy.isFrozen,
|
|
39
|
+
version: policy.version,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=users.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Composes the owner MFA service deps (`OwnerMfaDeps`) from a host's late-bound bag: identity
|
|
3
|
+
* bootstrap, MFA storage, the seeded owner and the host's existing secret sealer/keyring. Shared by
|
|
4
|
+
* the owner sign-in, enrollment, passkey and recovery flows, so every one of them binds the same
|
|
5
|
+
* server-selected owner and the same sealing ports.
|
|
6
|
+
*/
|
|
7
|
+
import type { AuthServiceDeps } from '../../server/auth-service.js';
|
|
8
|
+
import type { MfaStore, OwnerMfaDeps, TotpPort } from '../../server/mfa/ports.js';
|
|
9
|
+
import type { createSealedMfaSecrets } from '../../server/mfa/secret-adapter.js';
|
|
10
|
+
type SealingKeyring = Parameters<typeof createSealedMfaSecrets>[0]['keyring'];
|
|
11
|
+
type SealingSealer<Envelope> = Parameters<typeof createSealedMfaSecrets<Envelope>>[0]['sealer'];
|
|
12
|
+
/**
|
|
13
|
+
* What the host exposes. Read as properties at the moment of use (a host may pass getters over its
|
|
14
|
+
* own mutable deps): storage after identity bootstrap, the sealing pair on every seal/open.
|
|
15
|
+
*/
|
|
16
|
+
export interface OwnerMfaSource<Envelope = unknown> {
|
|
17
|
+
readonly identityReady: PromiseLike<unknown>;
|
|
18
|
+
readonly mfaStore: MfaStore | null | undefined;
|
|
19
|
+
readonly ownerPrincipalId: string | PromiseLike<string>;
|
|
20
|
+
readonly secretSealer: SealingSealer<Envelope> | undefined;
|
|
21
|
+
readonly secretKeyring: SealingKeyring | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** The host's identity service deps; called once, after storage is known to exist. */
|
|
24
|
+
export type OwnerAuthServiceDepsFn = () => AuthServiceDeps;
|
|
25
|
+
/** What `composeOwnerMfaDeps` reads: the host bag plus the collaborators it injects. */
|
|
26
|
+
export interface ComposeOwnerMfaDepsArgs<Envelope> {
|
|
27
|
+
deps: OwnerMfaSource<Envelope>;
|
|
28
|
+
authServiceDeps: OwnerAuthServiceDepsFn;
|
|
29
|
+
/** A fresh TOTP adapter for this composition (`createOtplibTotp` from `./server`). */
|
|
30
|
+
totp: TotpPort;
|
|
31
|
+
/** The sealing adapter factory (`createSealedMfaSecrets` from `./server`). */
|
|
32
|
+
sealedSecrets: typeof createSealedMfaSecrets;
|
|
33
|
+
}
|
|
34
|
+
/** Bind server-selected owner and existing sealing ports; never accept scope from a request.
|
|
35
|
+
* Sealing capability is checked on use so launcher sign-in can issue a pending proof without
|
|
36
|
+
* touching a secret. Missing ports refuse verification, never grant an owner session.
|
|
37
|
+
* @complexity O(1) composition, waiting for the existing seed promise; no added polling.
|
|
38
|
+
*/
|
|
39
|
+
export declare function composeOwnerMfaDeps<Envelope>({ deps, authServiceDeps, totp, sealedSecrets }: ComposeOwnerMfaDepsArgs<Envelope>, _options?: Record<string, never>): Promise<OwnerMfaDeps>;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=mfa-deps.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Bind server-selected owner and existing sealing ports; never accept scope from a request.
|
|
2
|
+
* Sealing capability is checked on use so launcher sign-in can issue a pending proof without
|
|
3
|
+
* touching a secret. Missing ports refuse verification, never grant an owner session.
|
|
4
|
+
* @complexity O(1) composition, waiting for the existing seed promise; no added polling.
|
|
5
|
+
*/
|
|
6
|
+
export async function composeOwnerMfaDeps({ deps, authServiceDeps, totp, sealedSecrets }, _options = {}) {
|
|
7
|
+
await deps.identityReady;
|
|
8
|
+
const store = deps.mfaStore;
|
|
9
|
+
if (!store)
|
|
10
|
+
throw new Error('Owner authenticator storage is unavailable');
|
|
11
|
+
const sealingPorts = () => {
|
|
12
|
+
const sealer = deps.secretSealer;
|
|
13
|
+
const keyring = deps.secretKeyring;
|
|
14
|
+
// A half-configured pair is never used: both ports come from the same site key.
|
|
15
|
+
if (!sealer || !keyring)
|
|
16
|
+
throw new Error('The site key is unavailable for owner authenticator verification');
|
|
17
|
+
return { sealer, keyring };
|
|
18
|
+
};
|
|
19
|
+
const secrets = sealedSecrets({
|
|
20
|
+
get sealer() { return sealingPorts().sealer; },
|
|
21
|
+
get keyring() { return sealingPorts().keyring; },
|
|
22
|
+
}, {});
|
|
23
|
+
return { auth: authServiceDeps(), store,
|
|
24
|
+
seededOwnerPrincipalId: await deps.ownerPrincipalId, totp, secrets };
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=mfa-deps.js.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Owner authenticator (TOTP) management routes as server-neutral raw specs (K1 §9.3): enroll,
|
|
3
|
+
* confirm, remove and the explicit status read. They run BEFORE the host's admin session gate, so each
|
|
4
|
+
* action admits its own owner session: JSON body + same-site origin, then the caller's session must be
|
|
5
|
+
* the seeded owner, then the host's rate limit — all before any factor or secret is touched. Every
|
|
6
|
+
* request-bound fact (credential, content type, site origin, client rate key) is a per-request host
|
|
7
|
+
* port; the service functions and the MFA composition are injected (they are node code).
|
|
8
|
+
*/
|
|
9
|
+
import type { JsonRouteAuthorize, RateLimitResult, RawRouteInputContext } from '@jini-ai/core/contracts/server';
|
|
10
|
+
import type { MfaStore, MfaScope, OwnerMfaDeps } from '../../server/mfa/ports.js';
|
|
11
|
+
import type { beginOwnerEnrollment, confirmOwnerEnrollment, removeOwnerFactor } from '../../server/mfa/service.js';
|
|
12
|
+
/** The caller the host's own credential check resolved, or none. */
|
|
13
|
+
export interface OwnerMfaRouteCaller {
|
|
14
|
+
readonly principal: {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
};
|
|
17
|
+
readonly kind: string;
|
|
18
|
+
}
|
|
19
|
+
/** The owner MFA service operations (`@jini-ai/user-management/server`), injected by the host. */
|
|
20
|
+
export interface OwnerMfaServices {
|
|
21
|
+
readonly beginOwnerEnrollment: typeof beginOwnerEnrollment;
|
|
22
|
+
readonly confirmOwnerEnrollment: typeof confirmOwnerEnrollment;
|
|
23
|
+
readonly removeOwnerFactor: typeof removeOwnerFactor;
|
|
24
|
+
}
|
|
25
|
+
/** Per request (the host binds the request-bound ports for each request; fields are read at use). */
|
|
26
|
+
export interface OwnerMfaRouteDeps {
|
|
27
|
+
readonly workspaceId: string;
|
|
28
|
+
readonly ownerPrincipalId: string | PromiseLike<string>;
|
|
29
|
+
readonly mfaStore: Pick<MfaStore, 'factor'> | null | undefined;
|
|
30
|
+
/** The authenticator-app issuer shown beside the account label. */
|
|
31
|
+
readonly issuer: string;
|
|
32
|
+
/** This request's credential (session, API key, ...), or null. */
|
|
33
|
+
authenticate(): Promise<OwnerMfaRouteCaller | null>;
|
|
34
|
+
/** Whether this request carries a JSON body (the host framework's content-type match). */
|
|
35
|
+
isJsonRequest(): boolean;
|
|
36
|
+
/** The site's own browser origin for this request. */
|
|
37
|
+
siteOrigin(): string;
|
|
38
|
+
/** One attempt against the host's limiter, keyed by this request's client. */
|
|
39
|
+
checkRateLimit(): Promise<RateLimitResult>;
|
|
40
|
+
/** The composed owner MFA deps (`composeOwnerMfaDeps`), built only after admission. */
|
|
41
|
+
ownerMfaDeps(): Promise<OwnerMfaDeps>;
|
|
42
|
+
findUserByPrincipalId(required: MfaScope): Promise<{
|
|
43
|
+
username?: string;
|
|
44
|
+
} | null | undefined>;
|
|
45
|
+
readonly services: OwnerMfaServices;
|
|
46
|
+
}
|
|
47
|
+
type HandleArgs = {
|
|
48
|
+
readonly raw: RawRouteInputContext;
|
|
49
|
+
readonly deps: OwnerMfaRouteDeps;
|
|
50
|
+
readonly context: undefined;
|
|
51
|
+
readonly authorize: JsonRouteAuthorize;
|
|
52
|
+
};
|
|
53
|
+
/** The server-neutral raw route, structurally an http-kit `RawRouteSpec`. */
|
|
54
|
+
export interface OwnerMfaRoute {
|
|
55
|
+
readonly method: 'get' | 'post';
|
|
56
|
+
readonly path: string;
|
|
57
|
+
readonly bufferedReply: true;
|
|
58
|
+
readonly responseHeaders: Readonly<Record<string, string>>;
|
|
59
|
+
readonly readHeaders: readonly string[];
|
|
60
|
+
handle(required: HandleArgs, optional: {
|
|
61
|
+
readonly signal: AbortSignal;
|
|
62
|
+
}): Promise<Response>;
|
|
63
|
+
}
|
|
64
|
+
export declare const ownerMfaEnrollRoute: OwnerMfaRoute;
|
|
65
|
+
export declare const ownerMfaConfirmRoute: OwnerMfaRoute;
|
|
66
|
+
export declare const ownerMfaRemoveRoute: OwnerMfaRoute;
|
|
67
|
+
/** Status is explicit, not polled. No secret or pending proof is returned by status.
|
|
68
|
+
* @complexity One indexed factor lookup on explicit load, for the owner session only.
|
|
69
|
+
*/
|
|
70
|
+
export declare const ownerMfaStatusRoute: OwnerMfaRoute;
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=mfa-routes.d.ts.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { IdentityValidationError, OwnerRequiredError } from '../../core/types.js';
|
|
2
|
+
const ROOT = '/api/admin/v1/auth/mfa';
|
|
3
|
+
/** Every outcome, including refusals and the host's redacted failure, is non-cacheable. */
|
|
4
|
+
const RESPONSE_HEADERS = Object.freeze({ 'Cache-Control': 'no-store' });
|
|
5
|
+
const READ_HEADERS = Object.freeze(['sec-fetch-site', 'origin']);
|
|
6
|
+
/** `res.json(body)`'s bytes and type. @complexity O(n) in the body. */
|
|
7
|
+
function jsonReply({ status, body, headers = {} }, _optional = {}) {
|
|
8
|
+
return new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json; charset=utf-8', ...headers } });
|
|
9
|
+
}
|
|
10
|
+
/** Only known domain refusals reach the browser; storage exceptions never disclose secrets.
|
|
11
|
+
* Anything else is rethrown to the host's failure writer (its redacted 500 and incident report).
|
|
12
|
+
* @complexity O(1), one response, no request input logged.
|
|
13
|
+
*/
|
|
14
|
+
function refusal({ error }, _optional = {}) {
|
|
15
|
+
const expected = error instanceof IdentityValidationError || error instanceof OwnerRequiredError;
|
|
16
|
+
if (!expected)
|
|
17
|
+
throw error;
|
|
18
|
+
const status = error instanceof OwnerRequiredError ? 403 : 400;
|
|
19
|
+
return jsonReply({ status, body: { error: error.message, code: 'MFA_REFUSED', details: { operation: 'owner-authenticator' } } });
|
|
20
|
+
}
|
|
21
|
+
/** Match the existing recovery origin policy before accepting an explicit JSON action. */
|
|
22
|
+
function acceptsRequest({ raw, deps }, _optional = {}) {
|
|
23
|
+
if (!deps.isJsonRequest() || raw.headers?.['sec-fetch-site'] === 'cross-site')
|
|
24
|
+
return false;
|
|
25
|
+
const origin = raw.headers?.origin;
|
|
26
|
+
return !origin || origin === deps.siteOrigin();
|
|
27
|
+
}
|
|
28
|
+
/** Reject cross-origin or machine credentials before any secret lookup. O(1), bounded headers.
|
|
29
|
+
* @returns The owner id, or the refusal to answer. A non-owner throws `OwnerRequiredError`. */
|
|
30
|
+
async function admit({ raw, deps }, _optional = {}) {
|
|
31
|
+
if (!acceptsRequest({ raw, deps })) {
|
|
32
|
+
return jsonReply({ status: 403, body: { error: 'Open this site’s security settings and submit the authenticator action there.', code: 'MFA_ORIGIN_REFUSED' } });
|
|
33
|
+
}
|
|
34
|
+
const caller = await deps.authenticate();
|
|
35
|
+
const ownerId = await deps.ownerPrincipalId;
|
|
36
|
+
if (caller?.kind !== 'session' || caller.principal.id !== ownerId) {
|
|
37
|
+
throw new OwnerRequiredError({ message: 'Sign in as the site owner to change this authenticator.' });
|
|
38
|
+
}
|
|
39
|
+
const rate = await deps.checkRateLimit();
|
|
40
|
+
if (rate.allowed)
|
|
41
|
+
return ownerId;
|
|
42
|
+
return jsonReply({ status: 429, headers: { 'Retry-After': String(rate.retryAfterSeconds) },
|
|
43
|
+
body: { error: 'Too many authenticator attempts. Wait a minute and try again.', code: 'RATE_LIMIT_EXCEEDED' } });
|
|
44
|
+
}
|
|
45
|
+
/** Read only scalar text from the JSON boundary; malformed values are refused by the service. */
|
|
46
|
+
function bodyText({ body, key }, _optional = {}) {
|
|
47
|
+
const value = body?.[key];
|
|
48
|
+
return typeof value === 'string' ? value : '';
|
|
49
|
+
}
|
|
50
|
+
/** Explicit owner action only; the service owns password/factor proof and atomic state changes.
|
|
51
|
+
* @complexity O(1) admission and bounded factor I/O, plus existing owner session revocation.
|
|
52
|
+
*/
|
|
53
|
+
async function act({ raw, deps, action }, _optional = {}) {
|
|
54
|
+
const ownerId = await admit({ raw, deps });
|
|
55
|
+
if (typeof ownerId !== 'string')
|
|
56
|
+
return ownerId;
|
|
57
|
+
const mfa = await deps.ownerMfaDeps();
|
|
58
|
+
const input = { workspaceId: deps.workspaceId, principalId: ownerId,
|
|
59
|
+
password: bodyText({ body: raw.body, key: 'password' }), code: bodyText({ body: raw.body, key: 'code' }) };
|
|
60
|
+
if (action === 'enroll') {
|
|
61
|
+
const user = await deps.findUserByPrincipalId(input);
|
|
62
|
+
const enrollment = await deps.services.beginOwnerEnrollment({ deps: mfa, input: { ...input, label: user?.username ?? 'Owner', issuer: deps.issuer } }, {});
|
|
63
|
+
return jsonReply({ status: 200, body: enrollment });
|
|
64
|
+
}
|
|
65
|
+
if (action === 'confirm')
|
|
66
|
+
await deps.services.confirmOwnerEnrollment({ deps: mfa, input: { ...input, pendingToken: bodyText({ body: raw.body, key: 'pendingToken' }) } }, {});
|
|
67
|
+
else
|
|
68
|
+
await deps.services.removeOwnerFactor({ deps: mfa, input }, {});
|
|
69
|
+
return new Response(null, { status: 204 });
|
|
70
|
+
}
|
|
71
|
+
/** One management action route. @complexity O(1). */
|
|
72
|
+
function actionRoute({ action }, _optional = {}) {
|
|
73
|
+
return {
|
|
74
|
+
method: 'post', path: `${ROOT}/${action}`, bufferedReply: true, responseHeaders: RESPONSE_HEADERS, readHeaders: READ_HEADERS,
|
|
75
|
+
handle: async ({ raw, deps }) => {
|
|
76
|
+
try {
|
|
77
|
+
return await act({ raw, deps, action });
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
return refusal({ error });
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export const ownerMfaEnrollRoute = actionRoute({ action: 'enroll' });
|
|
86
|
+
export const ownerMfaConfirmRoute = actionRoute({ action: 'confirm' });
|
|
87
|
+
export const ownerMfaRemoveRoute = actionRoute({ action: 'remove' });
|
|
88
|
+
/** Status is explicit, not polled. No secret or pending proof is returned by status.
|
|
89
|
+
* @complexity One indexed factor lookup on explicit load, for the owner session only.
|
|
90
|
+
*/
|
|
91
|
+
export const ownerMfaStatusRoute = {
|
|
92
|
+
method: 'get', path: ROOT, bufferedReply: true, responseHeaders: RESPONSE_HEADERS, readHeaders: READ_HEADERS,
|
|
93
|
+
handle: async ({ deps }) => {
|
|
94
|
+
try {
|
|
95
|
+
const caller = await deps.authenticate();
|
|
96
|
+
const isOwner = caller?.kind === 'session' && caller.principal.id === await deps.ownerPrincipalId;
|
|
97
|
+
const factor = isOwner ? await deps.mfaStore?.factor({ workspaceId: deps.workspaceId, principalId: caller.principal.id }) : null;
|
|
98
|
+
return jsonReply({ status: 200, body: { isOwner, available: isOwner && !!deps.mfaStore, enrolled: !!factor } });
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return refusal({ error });
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=mfa-routes.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { bindOwnerPasskeyRoutes } from './passkey-routes.js';
|
|
2
|
+
export declare function createOwnerPasskeyAdmission<Request, Response, Host>({ required, host, req, res }: {
|
|
3
|
+
required: Parameters<typeof bindOwnerPasskeyRoutes<Request, Response, Host>>[0];
|
|
4
|
+
host: Host;
|
|
5
|
+
req: Request;
|
|
6
|
+
res: Response;
|
|
7
|
+
}, _optional?: Record<string, never>): {
|
|
8
|
+
workspaceId: string;
|
|
9
|
+
passkeyDeps: () => Promise<import("../../server/index.js").OwnerPasskeyDeps>;
|
|
10
|
+
authenticate: () => Promise<{
|
|
11
|
+
principal: {
|
|
12
|
+
id: string;
|
|
13
|
+
};
|
|
14
|
+
kind: string;
|
|
15
|
+
} | null>;
|
|
16
|
+
ownerPrincipalId: () => Promise<string>;
|
|
17
|
+
isJson: () => boolean;
|
|
18
|
+
fetchSite: () => string | undefined;
|
|
19
|
+
origin: () => string | undefined;
|
|
20
|
+
body: () => Record<string, unknown>;
|
|
21
|
+
byteCount: () => number;
|
|
22
|
+
rate: () => Promise<{
|
|
23
|
+
allowed: boolean;
|
|
24
|
+
retryAfterSeconds?: number;
|
|
25
|
+
}>;
|
|
26
|
+
noStore: () => void;
|
|
27
|
+
retryAfter: (value: string) => void;
|
|
28
|
+
json: (value: unknown, status?: number) => void;
|
|
29
|
+
empty: () => void;
|
|
30
|
+
failure: (error: unknown) => void;
|
|
31
|
+
signedIn: (result: Parameters<Parameters<typeof bindOwnerPasskeyRoutes<Request, Response, Host>>[0]["signedIn"]>[0]["result"]) => Promise<void>;
|
|
32
|
+
services: {
|
|
33
|
+
beginOwnerPasskeyEnrollment: typeof import("../../server/index.js").beginOwnerPasskeyEnrollment;
|
|
34
|
+
confirmOwnerPasskeyEnrollment: typeof import("../../server/index.js").confirmOwnerPasskeyEnrollment;
|
|
35
|
+
beginOwnerPasskeyLogin: typeof import("../../server/index.js").beginOwnerPasskeyLogin;
|
|
36
|
+
completeOwnerPasskeyLogin: (required: Parameters<typeof import("../../server/index.js").completeOwnerPasskeyLogin>[0]) => ReturnType<typeof import("../../server/index.js").completeOwnerPasskeyLogin>;
|
|
37
|
+
removeOwnerPasskey: typeof import("../../server/index.js").removeOwnerPasskey;
|
|
38
|
+
};
|
|
39
|
+
copy: {
|
|
40
|
+
ownerRequired: string;
|
|
41
|
+
origin: string;
|
|
42
|
+
tooLarge: string;
|
|
43
|
+
rate: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=passkey-admission.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function createOwnerPasskeyAdmission({ required, host, req, res }, _optional = {}) {
|
|
2
|
+
return {
|
|
3
|
+
workspaceId: required.workspaceId({ host }),
|
|
4
|
+
passkeyDeps: () => required.resolveOwnerPasskeyRouteDeps({
|
|
5
|
+
store: () => required.store({ host }), mfa: () => required.mfa({ host }), webauthn: required.webauthn,
|
|
6
|
+
get site() { return required.site({ host, req }); }, unavailableMessage: required.unavailableMessage,
|
|
7
|
+
}),
|
|
8
|
+
authenticate: () => required.authenticate({ host, req }),
|
|
9
|
+
ownerPrincipalId: () => required.ownerPrincipalId({ host }),
|
|
10
|
+
isJson: () => required.isJson({ req }),
|
|
11
|
+
fetchSite: () => required.header({ req, name: 'sec-fetch-site' }),
|
|
12
|
+
origin: () => required.header({ req, name: 'origin' }),
|
|
13
|
+
body: () => required.body({ req }), byteCount: () => required.byteCount({ req }),
|
|
14
|
+
rate: () => required.rate({ host, req }), noStore: () => required.noStore({ res }),
|
|
15
|
+
retryAfter: (value) => required.retryAfter({ res, value }),
|
|
16
|
+
json: (value, status) => required.json({ res, value, ...(status === undefined ? {} : { status }) }),
|
|
17
|
+
empty: () => required.empty({ res }),
|
|
18
|
+
failure: (error) => required.answerOwnerPasskeyFailure({ error, json: (value, status) => required.json({ res, value, status }), incident: (error, options) => required.incident({ res, error, options }), operation: required.operation, incidentOptions: required.incidentOptions }),
|
|
19
|
+
signedIn: (result) => required.signedIn({ host, req, res, result }),
|
|
20
|
+
services: required.services, copy: required.copy,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=passkey-admission.js.map
|