@fabrika/iam 0.0.0-stage → 0.9.0-dev.26
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/fabrika.config.ts +267 -0
- package/migrations/0001_init.sql +316 -0
- package/migrations/0002_oauth.sql +38 -0
- package/migrations/0003_contract_apps.sql +11 -0
- package/migrations/0004_membership.sql +93 -0
- package/migrations/0005_workloads.sql +23 -0
- package/migrations/0006_membership_transport_keys.sql +16 -0
- package/migrations/0007_member_directory.sql +7 -0
- package/migrations/0008_durable_audit.sql +28 -0
- package/migrations/0009_member_lookups.sql +7 -0
- package/migrations/0010_workload_issues.sql +6 -0
- package/migrations/0011_app_presentation.sql +15 -0
- package/migrations/0012_external_principals.sql +10 -0
- package/migrations/0013_app_mail_templates.sql +14 -0
- package/migrations/0014_invitation_wording.sql +8 -0
- package/migrations/0015_app_schema_revisions.sql +15 -0
- package/migrations/0016_principal_grant_revision.sql +9 -0
- package/migrations/0017_app_sign_ins.sql +12 -0
- package/migrations/0018_app_members.sql +13 -0
- package/migrations/0019_app_mail_html.sql +7 -0
- package/migrations/0020_public_workloads.sql +34 -0
- package/migrations/0021_installation_brand.sql +19 -0
- package/migrations/0022_password_policy.sql +12 -0
- package/migrations/0023_terminals.sql +155 -0
- package/migrations/0024_app_terminals.sql +10 -0
- package/migrations/0025_terminal_completion.sql +10 -0
- package/migrations/0026_terminal_generation.sql +12 -0
- package/migrations/0027_application_exact_actions.sql +28 -0
- package/migrations/0028_oauth_client_assertions.sql +10 -0
- package/migrations/0029_role_via.sql +6 -0
- package/migrations/0030_membership_role_via.sql +12 -0
- package/migrations/0031_person_locale.sql +11 -0
- package/migrations-postgres/0001_init.sql +331 -0
- package/migrations-postgres/0002_oauth.sql +36 -0
- package/migrations-postgres/0003_contract_apps.sql +8 -0
- package/migrations-postgres/0004_membership.sql +92 -0
- package/migrations-postgres/0005_workloads.sql +18 -0
- package/migrations-postgres/0006_membership_transport_keys.sql +12 -0
- package/migrations-postgres/0007_member_directory.sql +7 -0
- package/migrations-postgres/0008_durable_audit.sql +8 -0
- package/migrations-postgres/0009_member_lookups.sql +7 -0
- package/migrations-postgres/0010_workload_issues.sql +6 -0
- package/migrations-postgres/0011_app_presentation.sql +15 -0
- package/migrations-postgres/0012_external_principals.sql +10 -0
- package/migrations-postgres/0013_app_mail_templates.sql +14 -0
- package/migrations-postgres/0014_invitation_wording.sql +8 -0
- package/migrations-postgres/0015_app_schema_revisions.sql +15 -0
- package/migrations-postgres/0016_principal_grant_revision.sql +9 -0
- package/migrations-postgres/0017_app_sign_ins.sql +12 -0
- package/migrations-postgres/0018_app_members.sql +13 -0
- package/migrations-postgres/0019_app_mail_html.sql +7 -0
- package/migrations-postgres/0020_public_workloads.sql +9 -0
- package/migrations-postgres/0021_installation_brand.sql +19 -0
- package/migrations-postgres/0022_password_policy.sql +12 -0
- package/migrations-postgres/0023_terminals.sql +70 -0
- package/migrations-postgres/0024_app_terminals.sql +10 -0
- package/migrations-postgres/0025_terminal_completion.sql +10 -0
- package/migrations-postgres/0026_terminal_generation.sql +12 -0
- package/migrations-postgres/0027_application_exact_actions.sql +28 -0
- package/migrations-postgres/0028_oauth_client_assertions.sql +9 -0
- package/migrations-postgres/0029_role_via.sql +4 -0
- package/migrations-postgres/0030_membership_role_via.sql +7 -0
- package/migrations-postgres/0031_person_locale.sql +11 -0
- package/package.json +70 -5
- package/src/admin/access.ts +47 -0
- package/src/admin/api-keys.ts +280 -0
- package/src/admin/app-people.ts +209 -0
- package/src/admin/app-schema.ts +308 -0
- package/src/admin/audit.ts +81 -0
- package/src/admin/brand.ts +54 -0
- package/src/admin/connections.ts +48 -0
- package/src/admin/context.ts +70 -0
- package/src/admin/grant-support.ts +192 -0
- package/src/admin/grants.ts +189 -0
- package/src/admin/handlers.ts +102 -0
- package/src/admin/http.ts +24 -0
- package/src/admin/membership-keys.ts +38 -0
- package/src/admin/pagination.ts +28 -0
- package/src/admin/password-policy.ts +48 -0
- package/src/admin/passwords.ts +78 -0
- package/src/admin/policies.ts +136 -0
- package/src/admin/principals.ts +226 -0
- package/src/admin/router.ts +291 -0
- package/src/admin/rpc.ts +387 -0
- package/src/admin/sessions.ts +115 -0
- package/src/admin/share-links.ts +127 -0
- package/src/admin/terminals.ts +115 -0
- package/src/admin/user-admin.ts +76 -0
- package/src/admin/workloads.ts +85 -0
- package/src/app-presentation.ts +178 -0
- package/src/app.ts +158 -0
- package/src/auth/cookies.ts +64 -0
- package/src/auth/failure.ts +25 -0
- package/src/auth/handoff.ts +136 -0
- package/src/auth/http.ts +88 -0
- package/src/auth/invitations.ts +220 -0
- package/src/auth/known-device.ts +44 -0
- package/src/auth/login.ts +162 -0
- package/src/auth/oidc-flight.ts +91 -0
- package/src/auth/oidc.ts +148 -0
- package/src/auth/password.ts +416 -0
- package/src/auth/routes.ts +108 -0
- package/src/auth/sessions.ts +249 -0
- package/src/auth/terminals.ts +284 -0
- package/src/auth.ts +193 -0
- package/src/binding-identity.ts +25 -0
- package/src/bounded-body.ts +35 -0
- package/src/catalog/cs.ts +147 -0
- package/src/catalog/en.ts +148 -0
- package/src/catalog/index.ts +122 -0
- package/src/catalog/uk.ts +164 -0
- package/src/client-address.ts +39 -0
- package/src/common-passwords.ts +37 -0
- package/src/contract-rules.ts +80 -0
- package/src/cron.ts +54 -0
- package/src/db.ts +128 -0
- package/src/delegation.ts +100 -0
- package/src/device-http.ts +39 -0
- package/src/device.ts +269 -0
- package/src/email-identity.ts +2 -0
- package/src/env.ts +132 -0
- package/src/handoff.ts +175 -0
- package/src/html.ts +4 -0
- package/src/human-admission.ts +40 -0
- package/src/identification.ts +185 -0
- package/src/index.ts +292 -0
- package/src/installation-brand.ts +82 -0
- package/src/issue.ts +265 -0
- package/src/json.ts +30 -0
- package/src/log.ts +26 -0
- package/src/membership-http.ts +135 -0
- package/src/membership.ts +1210 -0
- package/src/messages.ts +44 -0
- package/src/narrow-permissions.ts +26 -0
- package/src/node/browser-identity.ts +69 -0
- package/src/node/migrate.ts +52 -0
- package/src/node/prune.ts +34 -0
- package/src/node/runtime.ts +221 -0
- package/src/node/server.ts +104 -0
- package/src/oauth-client-auth.ts +93 -0
- package/src/oauth-client.ts +145 -0
- package/src/oauth-config.ts +72 -0
- package/src/oauth-http.ts +262 -0
- package/src/oauth.ts +272 -0
- package/src/oidc.ts +260 -0
- package/src/origin.ts +29 -0
- package/src/password-crypto.ts +148 -0
- package/src/password-db.ts +419 -0
- package/src/password-minimum.ts +44 -0
- package/src/password-pages.ts +397 -0
- package/src/password-policy.ts +79 -0
- package/src/password-service.ts +67 -0
- package/src/person-locale.ts +103 -0
- package/src/proxy-proof.ts +36 -0
- package/src/relay-mail.ts +64 -0
- package/src/repositories/app-schema.ts +550 -0
- package/src/repositories/audit.ts +405 -0
- package/src/repositories/brand.ts +66 -0
- package/src/repositories/credentials.ts +331 -0
- package/src/repositories/device.ts +137 -0
- package/src/repositories/grants.ts +404 -0
- package/src/repositories/handoff.ts +103 -0
- package/src/repositories/membership-transport.ts +49 -0
- package/src/repositories/membership.ts +875 -0
- package/src/repositories/oauth.ts +122 -0
- package/src/repositories/password-policy.ts +44 -0
- package/src/repositories/principals.ts +358 -0
- package/src/repositories/sessions.ts +339 -0
- package/src/repositories/sql.ts +23 -0
- package/src/repositories/terminals.ts +346 -0
- package/src/repositories/workloads.ts +134 -0
- package/src/request-id.ts +46 -0
- package/src/resolve.ts +396 -0
- package/src/retention.ts +34 -0
- package/src/roles.ts +54 -0
- package/src/rpc-http.ts +333 -0
- package/src/rpc-inputs.ts +110 -0
- package/src/rpc.ts +440 -0
- package/src/secret.ts +45 -0
- package/src/service.ts +59 -0
- package/src/services.ts +199 -0
- package/src/signing.ts +260 -0
- package/src/stored-chain.ts +23 -0
- package/src/stored-permissions.ts +34 -0
- package/src/terminals.ts +15 -0
- package/src/tokens.ts +506 -0
- package/src/workload-token.ts +130 -0
- package/types/fabrika.config.d.ts +11 -0
- package/types/src/admin/access.d.ts +19 -0
- package/types/src/admin/api-keys.d.ts +26 -0
- package/types/src/admin/app-people.d.ts +8 -0
- package/types/src/admin/app-schema.d.ts +32 -0
- package/types/src/admin/audit.d.ts +10 -0
- package/types/src/admin/brand.d.ts +10 -0
- package/types/src/admin/connections.d.ts +5 -0
- package/types/src/admin/context.d.ts +46 -0
- package/types/src/admin/grant-support.d.ts +59 -0
- package/types/src/admin/grants.d.ts +8 -0
- package/types/src/admin/handlers.d.ts +82 -0
- package/types/src/admin/http.d.ts +9 -0
- package/types/src/admin/membership-keys.d.ts +8 -0
- package/types/src/admin/pagination.d.ts +5 -0
- package/types/src/admin/password-policy.d.ts +9 -0
- package/types/src/admin/passwords.d.ts +5 -0
- package/types/src/admin/policies.d.ts +15 -0
- package/types/src/admin/principals.d.ts +15 -0
- package/types/src/admin/router.d.ts +75 -0
- package/types/src/admin/rpc.d.ts +6 -0
- package/types/src/admin/sessions.d.ts +14 -0
- package/types/src/admin/share-links.d.ts +21 -0
- package/types/src/admin/terminals.d.ts +13 -0
- package/types/src/admin/user-admin.d.ts +30 -0
- package/types/src/admin/workloads.d.ts +5 -0
- package/types/src/app-presentation.d.ts +86 -0
- package/types/src/app.d.ts +62 -0
- package/types/src/auth/cookies.d.ts +29 -0
- package/types/src/auth/failure.d.ts +47 -0
- package/types/src/auth/handoff.d.ts +66 -0
- package/types/src/auth/http.d.ts +29 -0
- package/types/src/auth/invitations.d.ts +18 -0
- package/types/src/auth/known-device.d.ts +12 -0
- package/types/src/auth/login.d.ts +10 -0
- package/types/src/auth/oidc-flight.d.ts +39 -0
- package/types/src/auth/oidc.d.ts +7 -0
- package/types/src/auth/password.d.ts +7 -0
- package/types/src/auth/routes.d.ts +15 -0
- package/types/src/auth/sessions.d.ts +60 -0
- package/types/src/auth/terminals.d.ts +47 -0
- package/types/src/auth.d.ts +70 -0
- package/types/src/binding-identity.d.ts +12 -0
- package/types/src/bounded-body.d.ts +12 -0
- package/types/src/catalog/cs.d.ts +2 -0
- package/types/src/catalog/en.d.ts +2 -0
- package/types/src/catalog/index.d.ts +112 -0
- package/types/src/catalog/uk.d.ts +2 -0
- package/types/src/client-address.d.ts +31 -0
- package/types/src/common-passwords.d.ts +2 -0
- package/types/src/contract-rules.d.ts +25 -0
- package/types/src/cron.d.ts +15 -0
- package/types/src/db.d.ts +58 -0
- package/types/src/delegation.d.ts +38 -0
- package/types/src/device-http.d.ts +2 -0
- package/types/src/device.d.ts +11 -0
- package/types/src/email-identity.d.ts +1 -0
- package/types/src/env.d.ts +127 -0
- package/types/src/handoff.d.ts +57 -0
- package/types/src/html.d.ts +2 -0
- package/types/src/human-admission.d.ts +22 -0
- package/types/src/identification.d.ts +30 -0
- package/types/src/index.d.ts +62 -0
- package/types/src/installation-brand.d.ts +22 -0
- package/types/src/issue.d.ts +62 -0
- package/types/src/json.d.ts +15 -0
- package/types/src/log.d.ts +15 -0
- package/types/src/membership-http.d.ts +8 -0
- package/types/src/membership.d.ts +156 -0
- package/types/src/messages.d.ts +20 -0
- package/types/src/narrow-permissions.d.ts +7 -0
- package/types/src/node/browser-identity.d.ts +1 -0
- package/types/src/node/migrate.d.ts +4 -0
- package/types/src/node/prune.d.ts +1 -0
- package/types/src/node/runtime.d.ts +51 -0
- package/types/src/node/server.d.ts +5 -0
- package/types/src/oauth-client-auth.d.ts +26 -0
- package/types/src/oauth-client.d.ts +17 -0
- package/types/src/oauth-config.d.ts +16 -0
- package/types/src/oauth-http.d.ts +7 -0
- package/types/src/oauth.d.ts +51 -0
- package/types/src/oidc.d.ts +81 -0
- package/types/src/origin.d.ts +9 -0
- package/types/src/password-crypto.d.ts +37 -0
- package/types/src/password-db.d.ts +134 -0
- package/types/src/password-minimum.d.ts +23 -0
- package/types/src/password-pages.d.ts +143 -0
- package/types/src/password-policy.d.ts +19 -0
- package/types/src/password-service.d.ts +24 -0
- package/types/src/person-locale.d.ts +50 -0
- package/types/src/proxy-proof.d.ts +21 -0
- package/types/src/relay-mail.d.ts +25 -0
- package/types/src/repositories/app-schema.d.ts +244 -0
- package/types/src/repositories/audit.d.ts +187 -0
- package/types/src/repositories/brand.d.ts +41 -0
- package/types/src/repositories/credentials.d.ts +148 -0
- package/types/src/repositories/device.d.ts +50 -0
- package/types/src/repositories/grants.d.ts +177 -0
- package/types/src/repositories/handoff.d.ts +52 -0
- package/types/src/repositories/membership-transport.d.ts +31 -0
- package/types/src/repositories/membership.d.ts +273 -0
- package/types/src/repositories/oauth.d.ts +55 -0
- package/types/src/repositories/password-policy.d.ts +25 -0
- package/types/src/repositories/principals.d.ts +159 -0
- package/types/src/repositories/sessions.d.ts +150 -0
- package/types/src/repositories/sql.d.ts +13 -0
- package/types/src/repositories/terminals.d.ts +144 -0
- package/types/src/repositories/workloads.d.ts +61 -0
- package/types/src/request-id.d.ts +25 -0
- package/types/src/resolve.d.ts +118 -0
- package/types/src/retention.d.ts +18 -0
- package/types/src/roles.d.ts +34 -0
- package/types/src/rpc-http.d.ts +53 -0
- package/types/src/rpc-inputs.d.ts +707 -0
- package/types/src/rpc.d.ts +4 -0
- package/types/src/secret.d.ts +21 -0
- package/types/src/service.d.ts +19 -0
- package/types/src/services.d.ts +72 -0
- package/types/src/signing.d.ts +72 -0
- package/types/src/stored-chain.d.ts +6 -0
- package/types/src/stored-permissions.d.ts +12 -0
- package/types/src/terminals.d.ts +7 -0
- package/types/src/tokens.d.ts +113 -0
- package/types/src/workload-token.d.ts +7 -0
- package/README.md +0 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic OIDC relying-party client. IAM federates login to ANY OpenID Connect provider —
|
|
3
|
+
* Google, Auth0, Okta, Keycloak, Microsoft Entra, … — configured purely by env: an `issuer` URL plus
|
|
4
|
+
* a client id/secret. Endpoints are not hardcoded; they come from the provider's discovery document
|
|
5
|
+
* (`${issuer}/.well-known/openid-configuration`), so swapping IdP is a config change, not a code one.
|
|
6
|
+
*
|
|
7
|
+
* 1. `authorizationUrl()` — where the browser logs in (authorization-code + PKCE + state).
|
|
8
|
+
* 2. `exchangeCode()` — swap the returned code (+ PKCE verifier) for an id_token.
|
|
9
|
+
* 3. `verifyIdToken()` — verify it (signature via the discovered JWKS, issuer, audience) and
|
|
10
|
+
* read `sub` + `email`.
|
|
11
|
+
*
|
|
12
|
+
* The discovery document and the JWKS resolver are injectable (the same seam `JwtValidator` uses),
|
|
13
|
+
* so tests run the real protocol logic against a local key with no network. The HTTP route wiring
|
|
14
|
+
* (cookies, redirects) lives in the `auth` handlers; this module is the protocol.
|
|
15
|
+
*/
|
|
16
|
+
import { type JWTVerifyGetKey } from 'jose';
|
|
17
|
+
export interface OidcConfig {
|
|
18
|
+
/** The provider's issuer URL — the discovery base AND the `iss` an id_token must carry. */
|
|
19
|
+
issuer: string;
|
|
20
|
+
clientId: string;
|
|
21
|
+
clientSecret: string;
|
|
22
|
+
/** Absolute callback URL — `${ISSUER}/auth/callback`. Must be registered with the provider. */
|
|
23
|
+
redirectUri: string;
|
|
24
|
+
/** Space-separated scopes; defaults to `openid email profile` when empty. `openid` + `email` are required. */
|
|
25
|
+
scopes: string;
|
|
26
|
+
/** Reject a login whose `email_verified` is not true. Default true; an IdP that omits the claim needs false. */
|
|
27
|
+
requireVerifiedEmail: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** The verified upstream identity we resolve a principal from. */
|
|
30
|
+
export interface OidcIdentity {
|
|
31
|
+
/** The IdP `sub` — the stable upstream subject, stored as the principal's `external_id`. */
|
|
32
|
+
sub: string;
|
|
33
|
+
email: string;
|
|
34
|
+
}
|
|
35
|
+
/** The subset of the OIDC discovery document IAM needs. */
|
|
36
|
+
export interface OidcMetadata {
|
|
37
|
+
issuer: string;
|
|
38
|
+
authorizationEndpoint: string;
|
|
39
|
+
tokenEndpoint: string;
|
|
40
|
+
jwksUri: string;
|
|
41
|
+
}
|
|
42
|
+
/** Injectable seams for tests: a fixed discovery doc and/or a local JWKS resolver (no network). */
|
|
43
|
+
export interface OidcDeps {
|
|
44
|
+
metadata?: OidcMetadata;
|
|
45
|
+
jwks?: JWTVerifyGetKey;
|
|
46
|
+
}
|
|
47
|
+
/** A random URL-safe token (default 32 bytes / 256 bits) — PKCE verifier, state nonce, session id. */
|
|
48
|
+
export declare function randomToken(bytes?: number): string;
|
|
49
|
+
/** Generate a PKCE pair: a high-entropy `verifier` and its S256 `challenge`. */
|
|
50
|
+
export declare function generatePkce(): Promise<{
|
|
51
|
+
verifier: string;
|
|
52
|
+
challenge: string;
|
|
53
|
+
}>;
|
|
54
|
+
/** Derive an S256 challenge from a browser-held verifier. */
|
|
55
|
+
export declare function pkceChallenge(verifier: string): Promise<string>;
|
|
56
|
+
export declare class OidcClient {
|
|
57
|
+
private readonly config;
|
|
58
|
+
private readonly deps;
|
|
59
|
+
constructor(config: OidcConfig, deps?: OidcDeps);
|
|
60
|
+
/** Where to send the browser to log in. `state` is the CSRF token; `codeChallenge` is the PKCE S256. */
|
|
61
|
+
authorizationUrl(params: {
|
|
62
|
+
state: string;
|
|
63
|
+
codeChallenge: string;
|
|
64
|
+
}): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Exchange an authorization `code` (+ the PKCE `verifier`) for an id_token at the provider's
|
|
67
|
+
* token endpoint. Returns the raw id_token, or null on any failure (caller treats as auth failure).
|
|
68
|
+
*/
|
|
69
|
+
exchangeCode(code: string, codeVerifier: string): Promise<string | null>;
|
|
70
|
+
/** The x-www-form-urlencoded body for the code→token exchange (separated so it's unit-testable). */
|
|
71
|
+
tokenRequestBody(code: string, codeVerifier: string): URLSearchParams;
|
|
72
|
+
/**
|
|
73
|
+
* Verify an id_token (signature against the discovered JWKS, issuer, audience) and extract the
|
|
74
|
+
* identity. Honors `requireVerifiedEmail`. Returns null on any problem — never throws.
|
|
75
|
+
*/
|
|
76
|
+
verifyIdToken(idToken: string): Promise<OidcIdentity | null>;
|
|
77
|
+
private scopes;
|
|
78
|
+
/** The provider's discovery metadata — injected (tests), else fetched once per isolate and cached. */
|
|
79
|
+
metadata(): Promise<OidcMetadata>;
|
|
80
|
+
private jwksResolver;
|
|
81
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** One canonical spelling for an HTTP origin, shared by everything in IAM that compares one. */
|
|
2
|
+
/**
|
|
3
|
+
* Canonical origin: lower-cased scheme and host, explicit port only when non-default, no path. Both
|
|
4
|
+
* sides of a comparison go through here, so `https://App.example.com:443/` and
|
|
5
|
+
* `https://app.example.com` are the same origin and neither side has to remember which spelling was
|
|
6
|
+
* registered. Returns null for anything that is not an absolute http(s) URL, and for a host carrying
|
|
7
|
+
* a character a CSP source cannot hold (`CSP_SAFE_ORIGIN`).
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizeOrigin(value: string): string | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const PBKDF2_SHA256_ALGORITHM = "pbkdf2-sha256";
|
|
2
|
+
/** OWASP's PBKDF2-HMAC-SHA256 cost, which the Bun process uses. */
|
|
3
|
+
export declare const PBKDF2_SHA256_ITERATIONS = 600000;
|
|
4
|
+
/** Production Cloudflare Workers refuse PBKDF2 above this with `NotSupportedError`; workerd, miniflare and Bun do not. */
|
|
5
|
+
export declare const PBKDF2_SHA256_WORKERS_MAX_ITERATIONS = 100000;
|
|
6
|
+
export declare const PBKDF2_SHA256_SALT_BYTES = 16;
|
|
7
|
+
export declare const PBKDF2_SHA256_OUTPUT_BYTES = 32;
|
|
8
|
+
export interface StoredPasswordHash {
|
|
9
|
+
algorithm: string;
|
|
10
|
+
parameters: string;
|
|
11
|
+
salt: string;
|
|
12
|
+
passwordHash: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PasswordVerification {
|
|
15
|
+
valid: boolean;
|
|
16
|
+
needsRehash: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface PasswordHasher {
|
|
19
|
+
hash(password: string): Promise<StoredPasswordHash>;
|
|
20
|
+
verify(password: string, stored: StoredPasswordHash): Promise<PasswordVerification>;
|
|
21
|
+
}
|
|
22
|
+
/** The PBKDF2 cost a composition root picks for its runtime. */
|
|
23
|
+
export interface Pbkdf2Cost {
|
|
24
|
+
/** What `hash` derives with; a stored verifier with any other count is rehashed on login. */
|
|
25
|
+
readonly iterations: number;
|
|
26
|
+
/** The most this runtime's WebCrypto derives. A stored verifier above it cannot be checked here. */
|
|
27
|
+
readonly maxIterations: number;
|
|
28
|
+
}
|
|
29
|
+
export declare const BUN_PBKDF2_COST: Pbkdf2Cost;
|
|
30
|
+
export declare const WORKERS_PBKDF2_COST: Pbkdf2Cost;
|
|
31
|
+
export declare class WebCryptoPasswordHasher implements PasswordHasher {
|
|
32
|
+
private readonly cost;
|
|
33
|
+
private readonly current;
|
|
34
|
+
constructor(cost?: Pbkdf2Cost);
|
|
35
|
+
hash(password: string): Promise<StoredPasswordHash>;
|
|
36
|
+
verify(password: string, stored: StoredPasswordHash): Promise<PasswordVerification>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { type SqlDatabase } from '@fabrika/platform';
|
|
2
|
+
import type { StoredPasswordHash } from './password-crypto';
|
|
3
|
+
import { type AuditEventInput, AuditWriter } from './repositories/audit';
|
|
4
|
+
import { type PrincipalRow } from './repositories/principals';
|
|
5
|
+
export type PasswordActionPurpose = 'enrollment' | 'reset';
|
|
6
|
+
export type PasswordAccountState = 'disabled' | 'pending' | 'enabled';
|
|
7
|
+
export interface PasswordAccountRow {
|
|
8
|
+
principal_id: string;
|
|
9
|
+
state: PasswordAccountState;
|
|
10
|
+
created_at: number;
|
|
11
|
+
updated_at: number;
|
|
12
|
+
}
|
|
13
|
+
export interface PasswordCredentialRow {
|
|
14
|
+
principal_id: string;
|
|
15
|
+
algorithm: string;
|
|
16
|
+
parameters: string;
|
|
17
|
+
salt: string;
|
|
18
|
+
password_hash: string;
|
|
19
|
+
created_at: number;
|
|
20
|
+
updated_at: number;
|
|
21
|
+
}
|
|
22
|
+
export interface PasswordActionTokenRow {
|
|
23
|
+
id: string;
|
|
24
|
+
principal_id: string;
|
|
25
|
+
purpose: PasswordActionPurpose;
|
|
26
|
+
token_hash: string;
|
|
27
|
+
issued_by: string | null;
|
|
28
|
+
expires_at: number;
|
|
29
|
+
consumed_at: number | null;
|
|
30
|
+
consumption_id: string | null;
|
|
31
|
+
created_at: number;
|
|
32
|
+
/** The application the action keeps (`presentationFor`), or NULL for one on the installation itself. */
|
|
33
|
+
app: string | null;
|
|
34
|
+
/** The language its mail was written in, which the page its link opens speaks too; NULL before migration 0031. */
|
|
35
|
+
locale: string | null;
|
|
36
|
+
}
|
|
37
|
+
/** A new action token: only its hash is stored. */
|
|
38
|
+
export interface ActionTokenInput {
|
|
39
|
+
principalId: string;
|
|
40
|
+
purpose: PasswordActionPurpose;
|
|
41
|
+
tokenHash: string;
|
|
42
|
+
issuedBy?: string | null;
|
|
43
|
+
expiresAt: number;
|
|
44
|
+
app?: string | null;
|
|
45
|
+
locale?: string | null;
|
|
46
|
+
}
|
|
47
|
+
export interface PasswordLoginThrottleRow {
|
|
48
|
+
login_key_hash: string;
|
|
49
|
+
window_started_at: number;
|
|
50
|
+
attempt_count: number;
|
|
51
|
+
blocked_until: number | null;
|
|
52
|
+
updated_at: number;
|
|
53
|
+
}
|
|
54
|
+
export type PasswordLoginLookup = {
|
|
55
|
+
status: 'missing';
|
|
56
|
+
} | {
|
|
57
|
+
status: 'ambiguous';
|
|
58
|
+
} | {
|
|
59
|
+
status: 'found';
|
|
60
|
+
principal: PrincipalRow;
|
|
61
|
+
credential: PasswordCredentialRow;
|
|
62
|
+
};
|
|
63
|
+
export type PasswordActionUserLookup = {
|
|
64
|
+
status: 'missing';
|
|
65
|
+
} | {
|
|
66
|
+
status: 'ambiguous';
|
|
67
|
+
} | {
|
|
68
|
+
status: 'found';
|
|
69
|
+
principal: PrincipalRow;
|
|
70
|
+
account: PasswordAccountRow | null;
|
|
71
|
+
};
|
|
72
|
+
/** The issuance of an action, by an administrator or a recovery request: its record, and the enrollment opt-in it turns on. */
|
|
73
|
+
export interface ActionIssuance {
|
|
74
|
+
readonly audit: AuditEventInput;
|
|
75
|
+
readonly enableEnrollment: boolean;
|
|
76
|
+
}
|
|
77
|
+
export declare class PasswordRepository {
|
|
78
|
+
protected readonly db: SqlDatabase;
|
|
79
|
+
protected readonly writer: AuditWriter;
|
|
80
|
+
constructor(db: SqlDatabase, writer?: AuditWriter);
|
|
81
|
+
getAccount(principalId: string): Promise<PasswordAccountRow | null>;
|
|
82
|
+
/** Metadata only: a closed link may have been used, replaced or revoked. */
|
|
83
|
+
latestAction(principalId: string): Promise<Pick<PasswordActionTokenRow, 'purpose' | 'created_at' | 'expires_at' | 'consumed_at'> | null>;
|
|
84
|
+
/** Preserve the administrator's opt-in independently of enrollment token lifetime. */
|
|
85
|
+
enableEnrollment(principalId: string): Promise<void>;
|
|
86
|
+
private enableEnrollmentStatement;
|
|
87
|
+
getCredential(principalId: string): Promise<PasswordCredentialRow | null>;
|
|
88
|
+
/** Match login email case-insensitively, but fail closed when legacy case variants collide. */
|
|
89
|
+
lookupLogin(email: string): Promise<PasswordLoginLookup>;
|
|
90
|
+
/**
|
|
91
|
+
* Resolve enrollment/reset/bootstrap candidates by mailbox.
|
|
92
|
+
*
|
|
93
|
+
* Plain equality against the stored NORMALIZED mailbox, never `LOWER(email) = LOWER(?)`: SQLite's
|
|
94
|
+
* `LOWER()` folds ASCII only where Postgres's folds all of Unicode, so the engine used to decide
|
|
95
|
+
* whether `JOSÉ@x.cz` and `josé@x.cz` were one human. `LIMIT 2` stays as the fail-closed belt —
|
|
96
|
+
* the schema forbids two rows per mailbox, and if one ever appears this refuses rather than picks.
|
|
97
|
+
*/
|
|
98
|
+
lookupActionUser(email: string): Promise<PasswordActionUserLookup>;
|
|
99
|
+
/** Replace the password, activate the principal, revoke prior password sessions, and write `audit`, atomically. */
|
|
100
|
+
upsertCredential(principalId: string, password: StoredPasswordHash, audit?: AuditEventInput): Promise<void>;
|
|
101
|
+
/** Remove password login and revoke only sessions that originated from a password. */
|
|
102
|
+
disableCredential(principalId: string, audit?: AuditEventInput): Promise<void>;
|
|
103
|
+
revokePasswordSessions(principalId: string): Promise<number>;
|
|
104
|
+
private revokePasswordSessionsStatement;
|
|
105
|
+
/** Supersede active tokens for the same action, then persist only the new token hash. */
|
|
106
|
+
issueActionToken(input: ActionTokenInput, issuance?: ActionIssuance): Promise<string>;
|
|
107
|
+
private replaceActionToken;
|
|
108
|
+
/** Atomically mark one valid action token used and return it; concurrent consumers lose. */
|
|
109
|
+
consumeActionToken(tokenHash: string, purpose: PasswordActionPurpose): Promise<PasswordActionTokenRow | null>;
|
|
110
|
+
/** Validate a scanner-safe GET without consuming the token. */
|
|
111
|
+
inspectActionToken(tokenHash: string, purpose: PasswordActionPurpose): Promise<PasswordActionTokenRow | null>;
|
|
112
|
+
/**
|
|
113
|
+
* Consume an action token and replace the credential as one race-safe transaction, with `audit` written exactly when
|
|
114
|
+
* this call consumed the token.
|
|
115
|
+
*/
|
|
116
|
+
completeAction(input: {
|
|
117
|
+
tokenHash: string;
|
|
118
|
+
purpose: PasswordActionPurpose;
|
|
119
|
+
password: StoredPasswordHash;
|
|
120
|
+
}, audit?: AuditEventInput): Promise<{
|
|
121
|
+
principalId: string;
|
|
122
|
+
} | null>;
|
|
123
|
+
getLoginThrottle(loginKeyHash: string): Promise<PasswordLoginThrottleRow | null>;
|
|
124
|
+
/** Atomically record one failed login and establish a fixed-window block at the threshold. */
|
|
125
|
+
recordLoginFailure(input: {
|
|
126
|
+
loginKeyHash: string;
|
|
127
|
+
windowSeconds: number;
|
|
128
|
+
maxAttempts: number;
|
|
129
|
+
blockSeconds: number;
|
|
130
|
+
}): Promise<PasswordLoginThrottleRow>;
|
|
131
|
+
clearLoginFailures(loginKeyHash: string): Promise<void>;
|
|
132
|
+
pruneLoginThrottles(olderThan: number): Promise<number>;
|
|
133
|
+
pruneActionTokens(olderThan: number): Promise<number>;
|
|
134
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Pbkdf2Cost } from './password-crypto';
|
|
2
|
+
import type { PasswordPolicyRow } from './repositories/password-policy';
|
|
3
|
+
import type { Services } from './services';
|
|
4
|
+
/**
|
|
5
|
+
* The lowest minimum this runtime accepts. A short password survives a leaked database only as long as its verifier is
|
|
6
|
+
* expensive, so the floor is low only where `hash` derives with OWASP's PBKDF2 cost (the Bun process). A Worker derives
|
|
7
|
+
* a sixth of it (backlog 201) and keeps the default as its floor until it hashes with a stronger algorithm.
|
|
8
|
+
*/
|
|
9
|
+
export declare function passwordMinLengthFloor(cost: Pbkdf2Cost): number;
|
|
10
|
+
/** Why a minimum cannot be stored, in the words the administration API answers with; null when it can. */
|
|
11
|
+
export declare function minLengthProblem(minLength: number, floor: number): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* The minimum a stored row sets, checked again as the administration API checks it: no row is the default, and a row this
|
|
14
|
+
* runtime would not accept (one an installation on another runtime wrote, or a hand edit) is the default too, never a
|
|
15
|
+
* value below the floor.
|
|
16
|
+
*/
|
|
17
|
+
export declare function storedMinLength(row: PasswordPolicyRow | null, floor: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* The minimum every new password meets, read once per request. A read that fails throws, like every other read of the
|
|
20
|
+
* request it serves: falling back to the default would accept a shorter password than an installation that raised the
|
|
21
|
+
* minimum requires.
|
|
22
|
+
*/
|
|
23
|
+
export declare function passwordMinLength(services: Services): Promise<number>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { Locale } from '@fabrika/auth-core';
|
|
2
|
+
import type { InstallationBrand } from '@fabrika/proxy-core/brand';
|
|
3
|
+
import { type AppPresentation } from './app-presentation';
|
|
4
|
+
import type { AuthFailure } from './auth/failure';
|
|
5
|
+
import type { Handoff } from './auth/handoff';
|
|
6
|
+
import { type PageText } from './catalog';
|
|
7
|
+
import { type PasswordProblem } from './password-policy';
|
|
8
|
+
export declare function loginPage(input: {
|
|
9
|
+
readonly presentation: AppPresentation;
|
|
10
|
+
/** An address on IAM's own origin, or a handoff's destination; null lands on the installation's landing. */
|
|
11
|
+
readonly redirect: string | null;
|
|
12
|
+
readonly oidcEnabled: boolean;
|
|
13
|
+
readonly forgotEnabled: boolean;
|
|
14
|
+
/** The app this login is a handoff for (ADR-0022); absent for a plain IAM login. */
|
|
15
|
+
readonly app?: string;
|
|
16
|
+
readonly handoffState?: string;
|
|
17
|
+
readonly handoffChallenge?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The ORIGIN off IAM the submission answers its 302 with: the handoff destination's, or the console's
|
|
20
|
+
* for a login with no return address. Chromium applies `form-action` to the REDIRECT a submission
|
|
21
|
+
* answers with, not only to the action, so `'self'` alone silently blocks the 302 to
|
|
22
|
+
* `<app>/__fabrika/auth/callback` — the login succeeds, a code is issued and spent, and the browser
|
|
23
|
+
* never leaves this page. Measured in Chromium 149. The value is a REGISTERED return origin, never
|
|
24
|
+
* the request's, so widening the directive cannot widen where a browser may be sent.
|
|
25
|
+
*/
|
|
26
|
+
readonly redirectOrigin?: string;
|
|
27
|
+
readonly invalidCredentials?: boolean;
|
|
28
|
+
}): Response;
|
|
29
|
+
/** Where the account question posts its answer, with the handoff's fields and a `decision`. */
|
|
30
|
+
export declare const ACCOUNT_CHOICE_PATH = "/auth/login/account";
|
|
31
|
+
/**
|
|
32
|
+
* The question a handoff asks a browser already signed in here, before its login is used for an application it has
|
|
33
|
+
* not chosen yet. Both answers post the handoff back, and the POST reads it again: the form is a hint, never a
|
|
34
|
+
* permission. Continuing answers a 302 to the application's callback, so `form-action` admits `redirectOrigin`, the
|
|
35
|
+
* handoff's registered origin (`loginDestinationFields`).
|
|
36
|
+
*/
|
|
37
|
+
export declare function chooseAccountPage(input: {
|
|
38
|
+
readonly presentation: AppPresentation;
|
|
39
|
+
/** The signed-in principal's label. */
|
|
40
|
+
readonly label: string;
|
|
41
|
+
readonly handoff: Handoff;
|
|
42
|
+
readonly redirectOrigin?: string;
|
|
43
|
+
}): Response;
|
|
44
|
+
/**
|
|
45
|
+
* The recovery form, and the page its POST answers. The form posts back with the link's `?app=`, so the action it may
|
|
46
|
+
* issue keeps the application; the way back is the application's address when it has one, otherwise IAM's sign-in.
|
|
47
|
+
*/
|
|
48
|
+
export declare function forgotPasswordPage(input: {
|
|
49
|
+
readonly presentation: AppPresentation;
|
|
50
|
+
readonly sent?: boolean;
|
|
51
|
+
}): Response;
|
|
52
|
+
/**
|
|
53
|
+
* The page an action link opens. Its form posts back with the link's `?app=`, so a refusal speaks the same language;
|
|
54
|
+
* the completed action lands on `landingOrigin`, which `form-action` therefore admits.
|
|
55
|
+
*/
|
|
56
|
+
export declare function setPasswordPage(input: {
|
|
57
|
+
readonly presentation: AppPresentation;
|
|
58
|
+
/** Where the completed action lands off IAM (`actionLandingOrigin`); null for IAM's own sign-in page. */
|
|
59
|
+
readonly landingOrigin: string | null;
|
|
60
|
+
readonly token?: string;
|
|
61
|
+
readonly purpose: 'enrollment' | 'reset';
|
|
62
|
+
/** The installation's minimum (`passwordMinLength`), which the rule and a refusal state. */
|
|
63
|
+
readonly minLength: number;
|
|
64
|
+
readonly problem?: PasswordProblem;
|
|
65
|
+
}): Response;
|
|
66
|
+
/**
|
|
67
|
+
* The same-origin confirmation that `GET /auth/logout` renders. Signing out is a state change, so it
|
|
68
|
+
* only happens on a POST that passes the origin check; this keeps the link usable and lives here
|
|
69
|
+
* because `htmlPage` (and its CSP) is what every browser-facing IAM page is built from.
|
|
70
|
+
*/
|
|
71
|
+
export declare function logoutPage(input: {
|
|
72
|
+
/** An address on IAM's own origin; null signs out to the installation's landing. */
|
|
73
|
+
readonly redirect: string | null;
|
|
74
|
+
/** The console's origin when the sign-out lands there, which `form-action` therefore admits. */
|
|
75
|
+
readonly landingOrigin: string | null;
|
|
76
|
+
/** The installation's logo (`installationBrand`), or null for the fabrika mark. */
|
|
77
|
+
readonly brand: InstallationBrand | null;
|
|
78
|
+
/** The reader's language (`readerLocale`): the sign-out names no application. */
|
|
79
|
+
readonly locale: Locale;
|
|
80
|
+
}): Response;
|
|
81
|
+
/** Where an administrator enrols the browser it uses as a terminal (ADR-0067). */
|
|
82
|
+
export declare const TERMINAL_ENROL_PATH = "/auth/terminals/enroll";
|
|
83
|
+
/** The enrolment form. It names no application, so it speaks the reader's language (`readerLocale`). */
|
|
84
|
+
export declare function terminalEnrolPage(input: {
|
|
85
|
+
readonly brand: InstallationBrand | null;
|
|
86
|
+
readonly locale: Locale;
|
|
87
|
+
readonly labelProblem?: boolean;
|
|
88
|
+
}): Response;
|
|
89
|
+
/** What an enrolled browser shows: the administrator is signed out and the terminal is named. */
|
|
90
|
+
export declare function terminalEnrolledPage(label: string, brand: InstallationBrand | null, locale: Locale): Response;
|
|
91
|
+
/** A refused browser-facing auth request, in the request's language and with its status. */
|
|
92
|
+
export declare function authFailurePage(presentation: AppPresentation, failure: AuthFailure, status: number): Response;
|
|
93
|
+
export declare function invalidActionPage(presentation: AppPresentation): Response;
|
|
94
|
+
/**
|
|
95
|
+
* The page an invitation link opens. The one-time token rides in the fragment and the script copies it into the form,
|
|
96
|
+
* which posts back with the link's `?app=`; an accepted invitation lands on the application's registered origin, which
|
|
97
|
+
* `form-action` therefore admits.
|
|
98
|
+
*/
|
|
99
|
+
export declare function invitationPage(presentation: AppPresentation): Response;
|
|
100
|
+
/**
|
|
101
|
+
* The answer to accepting an invitation that creates its principal: choose the password of the new account. The token
|
|
102
|
+
* rides in the form as on `setPasswordPage`, and the form posts back to the invitation with the application's `?app=`;
|
|
103
|
+
* the accepted invitation lands on `landingOrigin`, which `form-action` therefore admits.
|
|
104
|
+
*/
|
|
105
|
+
export declare function invitationPasswordPage(input: {
|
|
106
|
+
readonly presentation: AppPresentation;
|
|
107
|
+
/** Where the new account lands off IAM (`actionLandingOrigin`); null for IAM's own sign-in page. */
|
|
108
|
+
readonly landingOrigin: string | null;
|
|
109
|
+
readonly token: string;
|
|
110
|
+
/** The invited mailbox, which the new account signs in with. */
|
|
111
|
+
readonly address: string;
|
|
112
|
+
/** The installation's minimum (`passwordMinLength`), which the rule and a refusal state. */
|
|
113
|
+
readonly minLength: number;
|
|
114
|
+
readonly problem?: PasswordProblem;
|
|
115
|
+
}): Response;
|
|
116
|
+
/** An outcome of accepting an invitation. `signIn` adds the way back for a browser with no session here. */
|
|
117
|
+
export declare function invitationOutcomePage(input: {
|
|
118
|
+
readonly presentation: AppPresentation;
|
|
119
|
+
readonly title: (text: PageText['invitation']) => string;
|
|
120
|
+
readonly text: (text: PageText['invitation']) => string;
|
|
121
|
+
readonly status: number;
|
|
122
|
+
readonly signIn?: string;
|
|
123
|
+
/** IAM's sign-out page, which asks before it signs out. */
|
|
124
|
+
readonly signOut?: string;
|
|
125
|
+
}): Response;
|
|
126
|
+
/**
|
|
127
|
+
* `formActionOrigin` widens `form-action` by exactly one origin: the login page's handoff destination, or the
|
|
128
|
+
* registered origin an action or an invitation page lands on. It must already be an origin (scheme + host + optional
|
|
129
|
+
* port) that `normalizeOrigin` admitted, which refuses every character that would end or widen the directive; the
|
|
130
|
+
* registry stores only its output, and `presentationFor` checks a stored origin again.
|
|
131
|
+
*
|
|
132
|
+
* `brand` is required, so no page forgets the installation's logo; null draws the fabrika mark. The logo is an `<img>`
|
|
133
|
+
* of a `data:` URI, which is all `img-src data:` admits: an image runs no script, and a `data:` URI loads nothing from
|
|
134
|
+
* anywhere. `default-src` and `script-src` stay closed to it.
|
|
135
|
+
*/
|
|
136
|
+
export declare function htmlPage(page: {
|
|
137
|
+
readonly locale: Locale;
|
|
138
|
+
readonly brand: InstallationBrand | null;
|
|
139
|
+
readonly title: string;
|
|
140
|
+
readonly content: string;
|
|
141
|
+
readonly status?: number;
|
|
142
|
+
readonly formActionOrigin?: string;
|
|
143
|
+
}): Response;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const PASSWORD_MAX_CODE_POINTS = 256;
|
|
2
|
+
export interface PasswordPolicyContext {
|
|
3
|
+
readonly email?: string | null;
|
|
4
|
+
readonly label?: string | null;
|
|
5
|
+
}
|
|
6
|
+
/** Why a chosen password is refused; the page words it in the person's language. */
|
|
7
|
+
export type PasswordProblem = 'too_short' | 'too_long' | 'guessable';
|
|
8
|
+
export type PasswordPolicyResult = {
|
|
9
|
+
readonly ok: true;
|
|
10
|
+
readonly password: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly ok: false;
|
|
13
|
+
readonly problem: PasswordProblem;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Validate only length and whole-password blocklists; do not impose composition rules. `minLength` is the installation's
|
|
17
|
+
* (`passwordMinLength`), which every caller reads for the request: there is no default to fall back on by forgetting it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function validatePassword(raw: string, minLength: number, context?: PasswordPolicyContext): PasswordPolicyResult;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { EmailMessage } from '@fabrika/email';
|
|
2
|
+
import { type AppPresentation } from './app-presentation';
|
|
3
|
+
import type { PrincipalRow } from './db';
|
|
4
|
+
import type { ActionIssuance, PasswordActionPurpose } from './password-db';
|
|
5
|
+
import type { Services } from './services';
|
|
6
|
+
export interface IssuedPasswordAction {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly url: string;
|
|
9
|
+
readonly expiresAt: number;
|
|
10
|
+
readonly message: EmailMessage | null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Issue an opaque one-time action. The plaintext token exists only in the returned URL. The action keeps the
|
|
14
|
+
* presentation's application: the link names it (`?app=`) for the page's language, and the stored row decides where the
|
|
15
|
+
* completed action lands. The mail speaks the principal's own language where IAM keeps one, else the presentation's;
|
|
16
|
+
* the action keeps the person's language (the principal's, or the one the request named), so its page speaks it too.
|
|
17
|
+
*/
|
|
18
|
+
export declare function issuePasswordAction(services: Services, input: {
|
|
19
|
+
readonly principal: PrincipalRow;
|
|
20
|
+
readonly purpose: PasswordActionPurpose;
|
|
21
|
+
readonly issuedBy?: string | null;
|
|
22
|
+
readonly presentation: AppPresentation;
|
|
23
|
+
}, issuance: ActionIssuance): Promise<IssuedPasswordAction>;
|
|
24
|
+
export declare function deliverPasswordAction(services: Services, action: IssuedPasswordAction): Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type Locale } from '@fabrika/auth-core';
|
|
2
|
+
/** A stored or submitted value as a locale IAM speaks, or null: a value it does not (or no longer) speak counts as none. */
|
|
3
|
+
export declare function parseLocale(value: string | null | undefined): Locale | null;
|
|
4
|
+
/**
|
|
5
|
+
* The language a page speaks, from the most specific source that names one IAM speaks:
|
|
6
|
+
*
|
|
7
|
+
* 1. `person`: the reader's own, as IAM stored it for this flow (an invitation's, a password action's, a principal's);
|
|
8
|
+
* 2. `hint`: a link's or a form's `?locale=`, which IAM writes into the links it mails a person whose language it knows;
|
|
9
|
+
* 3. `remembered`: the language the browser last signed in with here (`LOCALE_COOKIE`);
|
|
10
|
+
* 4. `app`: the application's declared language;
|
|
11
|
+
* 5. `browser`: the best `Accept-Language` match;
|
|
12
|
+
* 6. the installation's default.
|
|
13
|
+
*
|
|
14
|
+
* The application's language ranks above the browser's, so an application that declares one keeps every page it
|
|
15
|
+
* showed before; only a language the person was given wins over it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function chooseLocale(sources: {
|
|
18
|
+
readonly person?: Locale | null;
|
|
19
|
+
readonly hint?: Locale | null;
|
|
20
|
+
readonly remembered?: Locale | null;
|
|
21
|
+
readonly app?: Locale | null;
|
|
22
|
+
readonly browser?: Locale | null;
|
|
23
|
+
}): Locale;
|
|
24
|
+
/** The request's own hints: its `?locale=`, the remembered cookie, and its `Accept-Language`. */
|
|
25
|
+
export declare function requestLocales(request: Request | null | undefined): {
|
|
26
|
+
readonly hint: Locale | null;
|
|
27
|
+
readonly remembered: Locale | null;
|
|
28
|
+
readonly browser: Locale | null;
|
|
29
|
+
};
|
|
30
|
+
/** The language of a page that names no application and knows no person: the request's hints, else the default. */
|
|
31
|
+
export declare function readerLocale(request: Request | null | undefined): Locale;
|
|
32
|
+
/**
|
|
33
|
+
* The best language IAM speaks among an `Accept-Language` header's ranges (RFC 9110 §12.5.4): by weight, ties in the
|
|
34
|
+
* order written, each range matched by its primary subtag (`uk-UA` is `uk`). A range of weight 0, `*` and a malformed
|
|
35
|
+
* weight are skipped. Null when no range names a language IAM speaks.
|
|
36
|
+
*/
|
|
37
|
+
export declare function browserLocale(header: string | null): Locale | null;
|
|
38
|
+
/**
|
|
39
|
+
* The `Set-Cookie` a sign-in of a person with `locale` (null for none) answers with: it remembers theirs, or clears a
|
|
40
|
+
* language the browser still holds from someone else; null when there is nothing to change.
|
|
41
|
+
*/
|
|
42
|
+
export declare function signInLocaleCookie(request: Request, locale: Locale | null): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* The `Set-Cookie` that remembers `locale` in `LOCALE_COOKIE` on IAM's host, for the pages IAM shows before it knows
|
|
45
|
+
* who is reading: a sign-in page reads it, so a person whose language differs from the application's keeps theirs
|
|
46
|
+
* after the first visit. A sign-in writes it, and so does an invitation's "sign in first", whose sign-in the
|
|
47
|
+
* application's proxy starts without a `?locale=` of IAM's. Host-only, like every cookie IAM writes, and words only:
|
|
48
|
+
* nothing reads it as a claim about the person.
|
|
49
|
+
*/
|
|
50
|
+
export declare function rememberLocaleCookie(locale: Locale): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a request proves it came through the platform proxy, which decides if IAM may read the request-id header the
|
|
3
|
+
* composition names (`src/request-id.ts`), and a client-address header where one is named (`src/client-address.ts`).
|
|
4
|
+
*
|
|
5
|
+
* On Zerops IAM is not publicly routed, but anything on the platform project's private network can reach its port and
|
|
6
|
+
* write the request id. So the proxy sends a per-installation secret in `PROXY_SECRET_HEADER` on IAM's route, and a
|
|
7
|
+
* request without it is attributed to nobody. This is attribution, not an enforcement decision (ADR-0022): a missing
|
|
8
|
+
* proof is never a refusal by itself, though the one bucket all such requests share refuses once exhausted.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The client coordinate every request without the proof shares. One bucket for all of them: a caller that cannot prove
|
|
12
|
+
* the proxy sent it cannot pick a fresh bucket per attempt, and the proxy's own requests never land here.
|
|
13
|
+
*/
|
|
14
|
+
export declare const UNPROVEN_CLIENT_ADDRESS = "unproven-caller";
|
|
15
|
+
/** Resolves true when the request may be attributed by the composition's headers. */
|
|
16
|
+
export type ProxyProof = (request: Request) => Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* The proof check for a configured secret. An empty secret means the composition checks nothing, and every request is
|
|
19
|
+
* read as it arrives — the Worker root, and an installation before the deploy that writes the secret.
|
|
20
|
+
*/
|
|
21
|
+
export declare function proxyProof(secret: string): ProxyProof;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EmailDeliveryError, type EmailSender } from '@fabrika/email';
|
|
2
|
+
import type { AuditEventInput } from './repositories/audit';
|
|
3
|
+
/**
|
|
4
|
+
* Whether the relay refused the message for good, so nothing was recorded and the provider cannot have it:
|
|
5
|
+
* - `provider_unauthorized`: Control knows no such key (a Control that holds an older secret, or none);
|
|
6
|
+
* - `mail_not_configured`: Control has no transport of its own;
|
|
7
|
+
* - a 404: Control runs no relay (an older release, or a Worker without its queue and bucket);
|
|
8
|
+
* - a 3xx: the URL is not where the relay answers (an `http:` origin that redirects to `https:`, say); the sender
|
|
9
|
+
* never follows it, so the relay never saw the message;
|
|
10
|
+
* - `invalid_configuration`: IAM's own relay settings cannot reach it.
|
|
11
|
+
* A timeout, a network failure or a provider outage may have reached the relay, so they never fall back.
|
|
12
|
+
*/
|
|
13
|
+
export declare function relayRefused(error: unknown): error is EmailDeliveryError;
|
|
14
|
+
/**
|
|
15
|
+
* Sends through `relay`, and through `direct` (IAM's own provider) only when the relay refused the message for good
|
|
16
|
+
* (`relayRefused`). The relay's capabilities are the sender's: a message goes there first. Without that fallback, sign-in
|
|
17
|
+
* links would stop while IAM deploys ahead of Control, or between a rotated secret reaching IAM and reaching Control.
|
|
18
|
+
*
|
|
19
|
+
* A fallback that lasts past a rollout means the relay is misconfigured, and the gate and the console's Mail page no
|
|
20
|
+
* longer see IAM's mail, so each one is `recorded` where an operator looks (the audit log), not only in the Worker's log.
|
|
21
|
+
* A record that fails never stops the message.
|
|
22
|
+
*/
|
|
23
|
+
export declare function relayWithFallback(relay: EmailSender, direct: EmailSender, recorded: (refusal: EmailDeliveryError) => Promise<void>): EmailSender;
|
|
24
|
+
/** The audit record of one fallback: which refusal, never the message, its recipient or a key. */
|
|
25
|
+
export declare function relayFallbackEvent(requestId: string, refusal: EmailDeliveryError): AuditEventInput;
|