@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
package/src/auth.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { API_KEY_PREFIX, isWorkloadKind, type PermissionEntry, type PrincipalType, type TokenPrincipalType } from '@fabrika/auth-core'
|
|
2
|
+
import type { SessionRow } from './db'
|
|
3
|
+
import type { Env } from './env'
|
|
4
|
+
import { hashToken, timingSafeEqualHex } from './secret'
|
|
5
|
+
import type { Config, Services } from './services'
|
|
6
|
+
import { getSigner, verifyAccessToken, verifyResourceAccessToken } from './signing'
|
|
7
|
+
import { resolveCredential } from './tokens'
|
|
8
|
+
|
|
9
|
+
/** Fixed identity of the local-dev login (`LOCAL_DEV_LOGIN`, `auth/login.ts`). */
|
|
10
|
+
export const LOCAL_DEV_ADMIN_ID = 'local-dev-admin'
|
|
11
|
+
export const LOCAL_DEV_ADMIN_EMAIL = 'admin@local.test'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* May this session still be used, given what the installation enables NOW?
|
|
15
|
+
*
|
|
16
|
+
* **Checked at USE, not at creation, and that is the point.** Turning a method off changes what the
|
|
17
|
+
* next login may do and nothing about what was already issued. Sessions live 30 days, so an
|
|
18
|
+
* installation that moved to password-only kept honouring every OIDC login for a month — and, for the
|
|
19
|
+
* bypass, every one of those is a global admin.
|
|
20
|
+
*
|
|
21
|
+
* The bypass carries `local_dev` as its own method rather than an exemption
|
|
22
|
+
* here, so this stays a total function over the enum: a method added later has to answer the question.
|
|
23
|
+
*/
|
|
24
|
+
export function sessionUsable(
|
|
25
|
+
session: Pick<SessionRow, 'authentication_method'>,
|
|
26
|
+
config: Pick<Config, 'authentication' | 'localDevLogin'>,
|
|
27
|
+
): boolean {
|
|
28
|
+
switch (session.authentication_method) {
|
|
29
|
+
case 'oidc':
|
|
30
|
+
return config.authentication.oidc.enabled
|
|
31
|
+
case 'password':
|
|
32
|
+
return config.authentication.password.enabled
|
|
33
|
+
case 'local_dev':
|
|
34
|
+
return config.localDevLogin
|
|
35
|
+
// No person can enable this method for themselves; the session lookup already refuses a revoked terminal.
|
|
36
|
+
case 'terminal_assertion':
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Fixed identity for the SEEDED PROVISIONING KEY below. A stable `service` principal with this id is
|
|
43
|
+
* seeded into `principals` (migration `0001_init.sql`) so the audit the provisioning
|
|
44
|
+
* key drives (e.g. `iam.app.schema.reconcile`) resolves its `principal_id` FK — the prod-applied analog
|
|
45
|
+
* of the dev admin's `seed.dev.sql` row.
|
|
46
|
+
*/
|
|
47
|
+
export const PROVISIONING_ADMIN_ID = 'provisioning-admin'
|
|
48
|
+
|
|
49
|
+
// ── Native caller resolution (IAM-native credentials, no Cloudflare Access) ──────────────
|
|
50
|
+
//
|
|
51
|
+
// Resolve the CALLER for the management RPCs (`issueKey`/`revokeKey`/`listPrincipals`)
|
|
52
|
+
// and the admin gate from an IAM-native credential the SDK forwards — a `px_token` access JWT
|
|
53
|
+
// (verified against our OWN signing keys) or an opaque `px_` key (resolved via the same
|
|
54
|
+
// `resolveCredential` core as `mintFromKey`). There is no Cloudflare Access JWT anymore.
|
|
55
|
+
|
|
56
|
+
/** The resolved caller. `type` is absent for an ANONYMOUS credential (a share link). */
|
|
57
|
+
export interface ResolvedCaller<T extends TokenPrincipalType = PrincipalType> {
|
|
58
|
+
id: string
|
|
59
|
+
type?: T
|
|
60
|
+
label: string | null
|
|
61
|
+
permissions: PermissionEntry[]
|
|
62
|
+
/** The terminal of a person's session token asserted on one (ADR-0067): its `terminal` claim's principal id. */
|
|
63
|
+
terminal?: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type CallerRefusal = { ok: false; reason: 'missing_token' | 'invalid_token' | 'unknown_principal' | 'disabled' }
|
|
67
|
+
|
|
68
|
+
export type CallerResolution<T extends TokenPrincipalType = PrincipalType> =
|
|
69
|
+
| { ok: true; caller: ResolvedCaller<T>; verifiedApp: string }
|
|
70
|
+
| CallerRefusal
|
|
71
|
+
|
|
72
|
+
type CallerEnv = Pick<Env, 'FABRIKA_IAM_SIGNING_KEYS' | 'FABRIKA_IAM_PROVISIONING_KEY' | 'ENVIRONMENT'>
|
|
73
|
+
type CallerInput = { app: string; credential: string | null; requestId: string }
|
|
74
|
+
|
|
75
|
+
const INVALID_TOKEN: CallerRefusal = { ok: false, reason: 'invalid_token' }
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The caller of a management or membership operation. A workload key or token calls none: it only mints for its own
|
|
79
|
+
* application (a job's link operations resolve through `resolveLinkCaller`).
|
|
80
|
+
*/
|
|
81
|
+
export async function resolveCaller(services: Services, env: CallerEnv, input: CallerInput): Promise<CallerResolution> {
|
|
82
|
+
const resolution = await resolveAnyCaller(services, env, input)
|
|
83
|
+
if (!resolution.ok) {
|
|
84
|
+
return resolution
|
|
85
|
+
}
|
|
86
|
+
const { type, ...caller } = resolution.caller
|
|
87
|
+
if (isWorkloadKind(type)) {
|
|
88
|
+
return INVALID_TOKEN
|
|
89
|
+
}
|
|
90
|
+
return { ok: true, caller: { ...caller, ...(type === undefined ? {} : { type }) }, verifiedApp: resolution.verifiedApp }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The caller of `issueLink` or `revokeLink`: a member caller, or a job (`type: 'job'`), which IAM then holds to the link
|
|
95
|
+
* mount its current declaration names. A webhook, a public procedure or a connector key calls neither.
|
|
96
|
+
*/
|
|
97
|
+
export async function resolveLinkCaller(services: Services, env: CallerEnv, input: CallerInput): Promise<CallerResolution<PrincipalType | 'job'>> {
|
|
98
|
+
const resolution = await resolveAnyCaller(services, env, input)
|
|
99
|
+
if (!resolution.ok) {
|
|
100
|
+
return resolution
|
|
101
|
+
}
|
|
102
|
+
const { type, ...caller } = resolution.caller
|
|
103
|
+
if (type === 'webhook' || type === 'public' || type === 'app') {
|
|
104
|
+
return INVALID_TOKEN
|
|
105
|
+
}
|
|
106
|
+
return { ok: true, caller: { ...caller, ...(type === undefined ? {} : { type }) }, verifiedApp: resolution.verifiedApp }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function resolveAnyCaller(services: Services, env: CallerEnv, input: CallerInput): Promise<CallerResolution<TokenPrincipalType>> {
|
|
110
|
+
if (input.credential === null) {
|
|
111
|
+
return { ok: false, reason: 'missing_token' }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// An opaque `px_` key → resolve its effective permissions (the same 2×2 as mintFromKey).
|
|
115
|
+
if (input.credential.startsWith(API_KEY_PREFIX)) {
|
|
116
|
+
const presentedHash = await hashToken(input.credential)
|
|
117
|
+
|
|
118
|
+
// SEEDED PROVISIONING KEY. A single operator-generated `px_` held ONLY in env (never in the DB) —
|
|
119
|
+
// the machine analog of the `IAM_BOOTSTRAP_ADMINS` email bootstrap. Checked BEFORE the DB lookup so
|
|
120
|
+
// a fresh control plane can reconcile/issue before any DB-backed admin credential exists. Empty env
|
|
121
|
+
// (the default) disables it. Compared by hash in constant time; resolves the seeded `provisioning-admin`
|
|
122
|
+
// principal (`0001_init.sql`) so its audit FK holds.
|
|
123
|
+
const provisioningKey = (env.FABRIKA_IAM_PROVISIONING_KEY ?? '').trim()
|
|
124
|
+
if (provisioningKey !== '' && timingSafeEqualHex(presentedHash, await hashToken(provisioningKey))) {
|
|
125
|
+
return {
|
|
126
|
+
ok: true,
|
|
127
|
+
caller: { id: PROVISIONING_ADMIN_ID, type: 'service', label: 'provisioning', permissions: [{ action: '*', scope: null, source: 'bootstrap' }] },
|
|
128
|
+
verifiedApp: input.app,
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const cred = await services.repositories.credentials.getActiveCredentialByHash(presentedHash)
|
|
133
|
+
if (!cred) {
|
|
134
|
+
return INVALID_TOKEN
|
|
135
|
+
}
|
|
136
|
+
const eff = await resolveCredential(services, cred, input.app)
|
|
137
|
+
if (!eff.ok) {
|
|
138
|
+
// A credential presented to the wrong app is indistinguishable from one that does not exist.
|
|
139
|
+
return { ok: false, reason: eff.reason === 'wrong_app' || eff.reason === 'issuer_unauthorized' ? 'invalid_token' : eff.reason }
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
ok: true,
|
|
143
|
+
caller: { id: eff.subject, ...(eff.type === undefined ? {} : { type: eff.type }), label: eff.label, permissions: eff.permissions },
|
|
144
|
+
// The credential's OWN app when it names one — `input.app` is caller-asserted, and after
|
|
145
|
+
// SEC-2 there is a verified value to prefer. A cross-app credential has nothing to assert
|
|
146
|
+
// with, so the caller's claim stands; `resolveCredential` has already bounded what that buys.
|
|
147
|
+
verifiedApp: cred.app ?? input.app,
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// A `px_token` access JWT → verify against OUR OWN signing keys; `aud` IS the app id and `perms`
|
|
152
|
+
// ARE the caller's resolved permissions for that app (the same snapshot the SDK's `can()` trusts).
|
|
153
|
+
const signer = await getSigner(env)
|
|
154
|
+
const claims = await verifyAccessToken(signer, input.credential, { issuer: services.config.issuer, audience: input.app })
|
|
155
|
+
if (!claims) {
|
|
156
|
+
return INVALID_TOKEN
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
ok: true,
|
|
160
|
+
caller: {
|
|
161
|
+
id: claims.sub,
|
|
162
|
+
...(claims.ptype === undefined ? {} : { type: claims.ptype }),
|
|
163
|
+
label: claims.label,
|
|
164
|
+
permissions: claims.perms,
|
|
165
|
+
...(claims.terminal === undefined ? {} : { terminal: claims.terminal.id }),
|
|
166
|
+
},
|
|
167
|
+
verifiedApp: claims.aud,
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** A request authenticated before its token expired may finish, and audit, after it; one hour covers that. */
|
|
172
|
+
export const AUDIT_TOKEN_EXPIRY_GRACE_SECONDS = 60 * 60
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The app an `audit` event belongs to, read from the caller's own token rather than from the event: a
|
|
176
|
+
* native access token's `aud`, or an OAuth resource token's signed `app`. Null when neither verifies.
|
|
177
|
+
* Signature, issuer and token kind are checked as strictly as anywhere; only `exp` gets
|
|
178
|
+
* `AUDIT_TOKEN_EXPIRY_GRACE_SECONDS`, because this decides where an event is filed, never what is allowed.
|
|
179
|
+
*/
|
|
180
|
+
export async function verifiedTokenApp(
|
|
181
|
+
services: Services,
|
|
182
|
+
env: Pick<Env, 'FABRIKA_IAM_SIGNING_KEYS' | 'ENVIRONMENT'>,
|
|
183
|
+
credential: string,
|
|
184
|
+
): Promise<string | null> {
|
|
185
|
+
const signer = await getSigner(env)
|
|
186
|
+
const opts = { issuer: services.config.issuer, expiryGraceSeconds: AUDIT_TOKEN_EXPIRY_GRACE_SECONDS }
|
|
187
|
+
const native = await verifyAccessToken(signer, credential, opts)
|
|
188
|
+
if (native !== null) {
|
|
189
|
+
return native.aud
|
|
190
|
+
}
|
|
191
|
+
const resource = await verifyResourceAccessToken(signer, credential, opts)
|
|
192
|
+
return resource?.oauth?.app ?? null
|
|
193
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// The application that calls IAM over a Workers service binding: the `props` the deployer wrote on that application's
|
|
2
|
+
// `IAM` binding (`IamApplicationReference` in `@fabrika/provider-cloudflare`), which workerd hands IAM as `ctx.props`.
|
|
3
|
+
// An application cannot choose them, so they are the binding's transport identity, as the membership transport key is
|
|
4
|
+
// over HTTP (ADR-0067 §3). Repository code holding the account token can, until backlog 86 lands (ADR-0048).
|
|
5
|
+
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
|
|
8
|
+
const bindingProps = z.object({ app: z.string().min(1) })
|
|
9
|
+
|
|
10
|
+
const applicationWorkerProps = z.object({ worker: z.literal('application') })
|
|
11
|
+
|
|
12
|
+
/** The IAM application id `<app>@<env>` whose deployment holds the binding, or null for a binding that names none. */
|
|
13
|
+
export function bindingApp(ctx: { readonly props?: unknown }): string | null {
|
|
14
|
+
const parsed = bindingProps.safeParse(ctx.props)
|
|
15
|
+
return parsed.success ? parsed.data.app : null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether the deployer marked the binding as the application Worker's, never its proxy's. Only the proxy obtains a
|
|
20
|
+
* delegation grant (ADR-0022 rule 6); a binding without the mark is a proxy's, a platform component's, or an application
|
|
21
|
+
* Worker deployed before the mark existed.
|
|
22
|
+
*/
|
|
23
|
+
export function isApplicationWorkerBinding(ctx: { readonly props?: unknown }): boolean {
|
|
24
|
+
return applicationWorkerProps.safeParse(ctx.props).success
|
|
25
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type BoundedBody = { ok: true; text: string } | { ok: false; reason: 'too_large' | 'unreadable' }
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A public route's request body as text, never more than `maxBytes` of it: a declared `Content-Length` over the cap is
|
|
5
|
+
* refused before reading, and a stream is cancelled at the first chunk past it. An absent body is the empty text.
|
|
6
|
+
*/
|
|
7
|
+
export async function readBoundedText(request: Request, maxBytes: number): Promise<BoundedBody> {
|
|
8
|
+
const declared = Number(request.headers.get('Content-Length') ?? '0')
|
|
9
|
+
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
10
|
+
await request.body?.cancel().catch(() => {})
|
|
11
|
+
return { ok: false, reason: 'too_large' }
|
|
12
|
+
}
|
|
13
|
+
if (request.body === null) return { ok: true, text: '' }
|
|
14
|
+
const reader = request.body.getReader()
|
|
15
|
+
const decoder = new TextDecoder()
|
|
16
|
+
let text = ''
|
|
17
|
+
let bytes = 0
|
|
18
|
+
try {
|
|
19
|
+
while (true) {
|
|
20
|
+
const chunk = await reader.read()
|
|
21
|
+
if (chunk.done) break
|
|
22
|
+
bytes += chunk.value.byteLength
|
|
23
|
+
if (bytes > maxBytes) {
|
|
24
|
+
await reader.cancel().catch(() => {})
|
|
25
|
+
return { ok: false, reason: 'too_large' }
|
|
26
|
+
}
|
|
27
|
+
text += decoder.decode(chunk.value, { stream: true })
|
|
28
|
+
}
|
|
29
|
+
return { ok: true, text: text + decoder.decode() }
|
|
30
|
+
} catch {
|
|
31
|
+
return { ok: false, reason: 'unreadable' }
|
|
32
|
+
} finally {
|
|
33
|
+
reader.releaseLock()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { iamMailCatalog } from '@fabrika/auth-core'
|
|
2
|
+
import type { Catalog } from './index'
|
|
3
|
+
|
|
4
|
+
export const cs: Catalog = {
|
|
5
|
+
pages: {
|
|
6
|
+
runsOn: 'Běží na platformě',
|
|
7
|
+
showPassword: 'Zobrazit',
|
|
8
|
+
hidePassword: 'Skrýt',
|
|
9
|
+
email: 'E-mail',
|
|
10
|
+
signIn: {
|
|
11
|
+
title: (appName) => (appName === null ? 'Přihlášení' : `Přihlášení do aplikace ${appName}`),
|
|
12
|
+
password: 'Heslo',
|
|
13
|
+
submit: 'Přihlásit se',
|
|
14
|
+
forgot: 'Zapomenuté heslo?',
|
|
15
|
+
singleSignOn: 'Pokračovat přes jednotné přihlášení',
|
|
16
|
+
invalidCredentials: 'Neplatný e-mail nebo heslo.',
|
|
17
|
+
},
|
|
18
|
+
chooseAccount: {
|
|
19
|
+
title: (appName) => (appName === null ? 'Pokračovat do aplikace' : `Pokračovat do aplikace ${appName}`),
|
|
20
|
+
signedInAs: 'Jste přihlášeni jako',
|
|
21
|
+
continueAs: (label) => `Pokračovat jako ${label}`,
|
|
22
|
+
another: 'Použít jiný účet',
|
|
23
|
+
anotherNote: 'Přechodem na jiný účet se tento prohlížeč odhlásí ze všech aplikací, do kterých je tímto účtem přihlášen.',
|
|
24
|
+
},
|
|
25
|
+
forgot: {
|
|
26
|
+
title: 'Obnovení hesla',
|
|
27
|
+
intro: (appName) =>
|
|
28
|
+
appName === null
|
|
29
|
+
? 'Zadejte adresu, kterou se přihlašujete.'
|
|
30
|
+
: `Zadejte adresu, kterou se přihlašujete do aplikace ${appName}.`,
|
|
31
|
+
submit: 'Pokračovat',
|
|
32
|
+
sentTitle: 'Žádost přijata',
|
|
33
|
+
sentText: 'Pokud účet může používat přihlášení heslem a e-mail se podaří doručit, přijde vám jednorázový odkaz.',
|
|
34
|
+
back: 'Zpět na přihlášení',
|
|
35
|
+
},
|
|
36
|
+
setPassword: {
|
|
37
|
+
title: (purpose) => (purpose === 'enrollment' ? 'Nastavte si heslo' : 'Obnovte si heslo'),
|
|
38
|
+
rule: (min, max) => `Použijte ${min}–${max} znaků. Dlouhé fráze jsou vítány.`,
|
|
39
|
+
shared: (appName) =>
|
|
40
|
+
appName === null
|
|
41
|
+
? 'Heslo patří k vašemu účtu v této přihlašovací službě a platí pro všechny aplikace, které ji používají.'
|
|
42
|
+
: `Heslo patří k vašemu účtu v této přihlašovací službě a platí pro všechny aplikace, které ji používají, nejen pro aplikaci ${appName}.`,
|
|
43
|
+
newPassword: 'Nové heslo',
|
|
44
|
+
problem: (problem, min, max) => {
|
|
45
|
+
switch (problem) {
|
|
46
|
+
case 'too_short':
|
|
47
|
+
return `Použijte alespoň ${min} ${min >= 2 && min <= 4 ? 'znaky' : 'znaků'}.`
|
|
48
|
+
case 'too_long':
|
|
49
|
+
return `Použijte nejvýše ${max} znaků.`
|
|
50
|
+
case 'guessable':
|
|
51
|
+
return 'Zvolte heslo, které nevychází z údajů vašeho účtu a není běžně používané.'
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
failure: {
|
|
56
|
+
title: 'Chyba přihlášení',
|
|
57
|
+
text: (failure) => {
|
|
58
|
+
switch (failure.kind) {
|
|
59
|
+
case 'no_return_address':
|
|
60
|
+
return 'Pro tuto aplikaci nebyla zadána návratová adresa.'
|
|
61
|
+
case 'no_handoff_proof':
|
|
62
|
+
return 'Pro tuto aplikaci chybí platný doklad předání z prohlížeče.'
|
|
63
|
+
case 'unregistered_origin':
|
|
64
|
+
return `${failure.origin} není registrovaná návratová adresa této aplikace.`
|
|
65
|
+
case 'password_disabled':
|
|
66
|
+
return 'Přihlášení heslem je vypnuté.'
|
|
67
|
+
case 'oidc_disabled':
|
|
68
|
+
return 'Jednotné přihlášení je vypnuté.'
|
|
69
|
+
case 'cross_origin':
|
|
70
|
+
return 'Neplatný původ požadavku.'
|
|
71
|
+
case 'malformed_form':
|
|
72
|
+
return 'Neplatný formulář.'
|
|
73
|
+
case 'login_unavailable':
|
|
74
|
+
return 'Přihlášení teď není k dispozici. Zkuste to později.'
|
|
75
|
+
case 'logout_unavailable':
|
|
76
|
+
return 'Odhlášení teď není k dispozici. Zkuste to později.'
|
|
77
|
+
case 'oidc_invalid_state':
|
|
78
|
+
return 'Pokus o jednotné přihlášení je neplatný nebo vypršel. Přihlaste se znovu.'
|
|
79
|
+
case 'oidc_exchange_failed':
|
|
80
|
+
return 'Poskytovatel identity přihlášení nedokončil.'
|
|
81
|
+
case 'oidc_invalid_id_token':
|
|
82
|
+
return 'Poskytovatel identity vrátil neplatnou identitu.'
|
|
83
|
+
case 'not_admitted':
|
|
84
|
+
return 'Tento účet se zde nemůže přihlásit.'
|
|
85
|
+
case 'login_refused':
|
|
86
|
+
return `Přihlášení bylo odmítnuto (${failure.reason}).`
|
|
87
|
+
case 'terminal_enrolment_not_allowed':
|
|
88
|
+
return 'Přihlaste se účtem, který smí registrovat terminály.'
|
|
89
|
+
case 'terminal_enrolment_unavailable':
|
|
90
|
+
return 'Registrace teď není k dispozici. Zkuste to později.'
|
|
91
|
+
case 'terminal_completion_refused':
|
|
92
|
+
return 'Toto přihlášení vypršelo nebo už bylo použito. Identifikujte se znovu.'
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
invalidLink: {
|
|
97
|
+
title: 'Odkaz není k dispozici',
|
|
98
|
+
text: 'Tento odkaz je neplatný, vypršel, nebo už byl použit.',
|
|
99
|
+
requestNew: 'Vyžádat nový odkaz',
|
|
100
|
+
},
|
|
101
|
+
logout: {
|
|
102
|
+
title: 'Odhlášení',
|
|
103
|
+
text: 'Tím ukončíte přihlášení ve všech aplikacích, do kterých jste přihlášeni.',
|
|
104
|
+
submit: 'Odhlásit se',
|
|
105
|
+
},
|
|
106
|
+
terminal: {
|
|
107
|
+
enrolTitle: 'Registrovat tento počítač jako terminál',
|
|
108
|
+
enrolText:
|
|
109
|
+
'Lidé se na tomto počítači budou přihlašovat přes aplikace, pro které je nastavený. Registrace vás v tomto prohlížeči odhlásí, aby terminál nikdy nezůstal přihlášený pod vaším účtem.',
|
|
110
|
+
label: 'Název terminálu',
|
|
111
|
+
labelProblem: (max) => `Použijte 1–${max} znaků.`,
|
|
112
|
+
submit: 'Registrovat a odhlásit',
|
|
113
|
+
enrolledTitle: 'Terminál je zaregistrovaný',
|
|
114
|
+
enrolledText: (label) => `Tento prohlížeč je teď terminál ${label}. Jste odhlášeni. Které aplikace obsluhuje, nastaví administrátor.`,
|
|
115
|
+
},
|
|
116
|
+
invitation: {
|
|
117
|
+
title: 'Přijetí pozvánky',
|
|
118
|
+
text: 'Přijměte pozvánku. V dalším kroku se přihlásíte pozvanou adresou, nebo si zvolíte heslo, pokud pozvánka zakládá nový účet.',
|
|
119
|
+
submit: 'Přijmout pozvánku',
|
|
120
|
+
createTitle: 'Zvolte si heslo',
|
|
121
|
+
createText: (address) => `Váš účet se přihlašuje adresou ${address} a heslem, které si zde zvolíte. Zvolením hesla pozvánku přijmete.`,
|
|
122
|
+
createSubmit: 'Nastavit heslo a přijmout',
|
|
123
|
+
otherAccountTitle: 'Jste přihlášeni jiným účtem',
|
|
124
|
+
otherAccountText: (address) =>
|
|
125
|
+
`Tato pozvánka zakládá nový účet pro adresu ${address} a tento prohlížeč je přihlášen jiným účtem. Nejprve se odhlaste, nebo otevřete odkaz z pozvánky v jiném profilu prohlížeče.`,
|
|
126
|
+
signOut: 'Odhlásit se',
|
|
127
|
+
signInFirstTitle: 'Nejprve se přihlaste',
|
|
128
|
+
signInFirstText: 'Přihlaste se pozvanou adresou a potom znovu otevřete odkaz z pozvánky.',
|
|
129
|
+
signIn: 'Přihlásit se',
|
|
130
|
+
noAccountTitle: 'Pro tuto adresu tu není účet',
|
|
131
|
+
noAccountText: (address) =>
|
|
132
|
+
`Pro adresu ${address} tu není účet a tato pozvánka ho nezakládá. Požádejte toho, kdo vás pozval, aby vám pro tuto adresu zřídil účet, a potom znovu otevřete odkaz z pozvánky.`,
|
|
133
|
+
unavailableTitle: 'Pozvánka není k dispozici',
|
|
134
|
+
accountCannotAccept: 'Tento účet nemůže přijímat pozvánky.',
|
|
135
|
+
wrongAddressTitle: 'Pozvánka pro jinou adresu',
|
|
136
|
+
wrongAddressText: 'Jste přihlášeni adresou, na kterou tato pozvánka nebyla poslána. Přihlaste se pozvanou adresou.',
|
|
137
|
+
inviterCannotGrant: 'Osoba, která pozvánku poslala, už tuto roli nemůže udělit. Požádejte o novou pozvánku.',
|
|
138
|
+
roleNotEligible: 'Tento účet nemůže mít roli, kterou pozvánka dává. Obraťte se na toho, kdo ji poslal.',
|
|
139
|
+
acceptedTitle: 'Pozvánka přijata',
|
|
140
|
+
acceptedText: ({ role, scope, appName }) => `V aplikaci ${appName} teď máte roli ${role} (${scope}).`,
|
|
141
|
+
invalidTitle: 'Odkaz není k dispozici',
|
|
142
|
+
invalidText:
|
|
143
|
+
'Tato pozvánka je neplatná, vypršela, byla zrušena, nebo už byla použita. Pokud jste ji ještě nepřijali, požádejte toho, kdo vás pozval, aby ji poslal znovu.',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
...iamMailCatalog('cs'),
|
|
147
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { iamMailCatalog } from '@fabrika/auth-core'
|
|
2
|
+
import type { Catalog } from './index'
|
|
3
|
+
|
|
4
|
+
export const en: Catalog = {
|
|
5
|
+
pages: {
|
|
6
|
+
runsOn: 'Runs on',
|
|
7
|
+
showPassword: 'Show',
|
|
8
|
+
hidePassword: 'Hide',
|
|
9
|
+
email: 'Email',
|
|
10
|
+
signIn: {
|
|
11
|
+
title: (appName) => (appName === null ? 'Sign in' : `Sign in to ${appName}`),
|
|
12
|
+
password: 'Password',
|
|
13
|
+
submit: 'Sign in',
|
|
14
|
+
forgot: 'Forgot password?',
|
|
15
|
+
singleSignOn: 'Continue with single sign-on',
|
|
16
|
+
invalidCredentials: 'Invalid email or password.',
|
|
17
|
+
},
|
|
18
|
+
chooseAccount: {
|
|
19
|
+
title: (appName) => (appName === null ? 'Continue to the application' : `Continue to ${appName}`),
|
|
20
|
+
signedInAs: 'You are signed in as',
|
|
21
|
+
continueAs: (label) => `Continue as ${label}`,
|
|
22
|
+
another: 'Use another account',
|
|
23
|
+
anotherNote: 'Using another account signs this browser out of every application it is signed in to with this account.',
|
|
24
|
+
},
|
|
25
|
+
forgot: {
|
|
26
|
+
title: 'Reset password',
|
|
27
|
+
intro: (appName) =>
|
|
28
|
+
appName === null
|
|
29
|
+
? 'Enter the address you sign in with.'
|
|
30
|
+
: `Enter the address you sign in to ${appName} with.`,
|
|
31
|
+
submit: 'Continue',
|
|
32
|
+
sentTitle: 'Request received',
|
|
33
|
+
sentText: 'If the account can use password sign-in and email delivery succeeds, a one-time link will arrive.',
|
|
34
|
+
back: 'Return to sign in',
|
|
35
|
+
},
|
|
36
|
+
setPassword: {
|
|
37
|
+
title: (purpose) => (purpose === 'enrollment' ? 'Set your password' : 'Reset your password'),
|
|
38
|
+
rule: (min, max) => `Use ${min}–${max} characters. Long passphrases are welcome.`,
|
|
39
|
+
shared: (appName) =>
|
|
40
|
+
appName === null
|
|
41
|
+
? 'The password belongs to your account on this sign-in service and applies to every application that uses it.'
|
|
42
|
+
: `The password belongs to your account on this sign-in service and applies to every application that uses it, not only to ${appName}.`,
|
|
43
|
+
newPassword: 'New password',
|
|
44
|
+
problem: (problem, min, max) => {
|
|
45
|
+
switch (problem) {
|
|
46
|
+
case 'too_short':
|
|
47
|
+
return `Use at least ${min} characters.`
|
|
48
|
+
case 'too_long':
|
|
49
|
+
return `Use at most ${max} characters.`
|
|
50
|
+
case 'guessable':
|
|
51
|
+
return 'Choose a password that is not based on your account details or a common password.'
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
failure: {
|
|
56
|
+
title: 'Authentication error',
|
|
57
|
+
text: (failure) => {
|
|
58
|
+
switch (failure.kind) {
|
|
59
|
+
case 'no_return_address':
|
|
60
|
+
return 'No return address was given for this app.'
|
|
61
|
+
case 'no_handoff_proof':
|
|
62
|
+
return 'No valid browser handoff proof was given for this app.'
|
|
63
|
+
case 'unregistered_origin':
|
|
64
|
+
return `${failure.origin} is not a registered return origin for this app.`
|
|
65
|
+
case 'password_disabled':
|
|
66
|
+
return 'Password sign-in is disabled.'
|
|
67
|
+
case 'oidc_disabled':
|
|
68
|
+
return 'Single sign-on is disabled.'
|
|
69
|
+
case 'cross_origin':
|
|
70
|
+
return 'Invalid request origin.'
|
|
71
|
+
case 'malformed_form':
|
|
72
|
+
return 'Invalid form.'
|
|
73
|
+
case 'login_unavailable':
|
|
74
|
+
return 'Sign-in is unavailable. Try again later.'
|
|
75
|
+
case 'logout_unavailable':
|
|
76
|
+
return 'Sign-out is unavailable. Try again later.'
|
|
77
|
+
case 'oidc_invalid_state':
|
|
78
|
+
return 'The single sign-on attempt is invalid or expired. Sign in again.'
|
|
79
|
+
case 'oidc_exchange_failed':
|
|
80
|
+
return 'The identity provider did not complete the sign-in.'
|
|
81
|
+
case 'oidc_invalid_id_token':
|
|
82
|
+
return 'The identity provider answered with an invalid identity.'
|
|
83
|
+
case 'not_admitted':
|
|
84
|
+
return 'This account may not sign in here.'
|
|
85
|
+
case 'login_refused':
|
|
86
|
+
return `Sign-in was refused (${failure.reason}).`
|
|
87
|
+
case 'terminal_enrolment_not_allowed':
|
|
88
|
+
return 'Sign in with an account that may enrol terminals.'
|
|
89
|
+
case 'terminal_enrolment_unavailable':
|
|
90
|
+
return 'Enrolment is unavailable. Try again later.'
|
|
91
|
+
case 'terminal_completion_refused':
|
|
92
|
+
return 'This sign-in has expired or was already used. Identify again.'
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
invalidLink: {
|
|
97
|
+
title: 'Link unavailable',
|
|
98
|
+
text: 'This link is invalid, expired, or already used.',
|
|
99
|
+
requestNew: 'Request a new link',
|
|
100
|
+
},
|
|
101
|
+
logout: {
|
|
102
|
+
title: 'Sign out',
|
|
103
|
+
text: 'This ends your session on every application you are signed in to.',
|
|
104
|
+
submit: 'Sign out',
|
|
105
|
+
},
|
|
106
|
+
terminal: {
|
|
107
|
+
enrolTitle: 'Enrol this computer as a terminal',
|
|
108
|
+
enrolText:
|
|
109
|
+
'People will sign in on this computer through the applications it is set up for. Enrolling signs you out of this browser, so the terminal is never left signed in as you.',
|
|
110
|
+
label: 'Name of the terminal',
|
|
111
|
+
labelProblem: (max) => `Use 1–${max} characters.`,
|
|
112
|
+
submit: 'Enrol and sign out',
|
|
113
|
+
enrolledTitle: 'Terminal enrolled',
|
|
114
|
+
enrolledText: (label) => `This browser is now the terminal ${label}. You are signed out. An administrator sets which applications it serves.`,
|
|
115
|
+
},
|
|
116
|
+
invitation: {
|
|
117
|
+
title: 'Accept invitation',
|
|
118
|
+
text:
|
|
119
|
+
'Accept the invitation. The next step asks you to sign in with the invited address, or to choose a password when the invitation creates your account.',
|
|
120
|
+
submit: 'Accept invitation',
|
|
121
|
+
createTitle: 'Choose your password',
|
|
122
|
+
createText: (address) => `Your account signs in with ${address} and the password you choose here. Choosing it accepts the invitation.`,
|
|
123
|
+
createSubmit: 'Set password and accept',
|
|
124
|
+
otherAccountTitle: 'Signed in with another account',
|
|
125
|
+
otherAccountText: (address) =>
|
|
126
|
+
`This invitation creates a new account for ${address}, and this browser is signed in with another account. Sign out first, or open the invitation link in another browser profile.`,
|
|
127
|
+
signOut: 'Sign out',
|
|
128
|
+
signInFirstTitle: 'Sign in first',
|
|
129
|
+
signInFirstText: 'Sign in with the invited address, then open the invitation link again.',
|
|
130
|
+
signIn: 'Sign in',
|
|
131
|
+
noAccountTitle: 'No account for this address',
|
|
132
|
+
noAccountText: (address) =>
|
|
133
|
+
`There is no account for ${address} here, and this invitation does not create one. Ask the person who invited you to have an account set up for this address, then open the invitation link again.`,
|
|
134
|
+
unavailableTitle: 'Invitation unavailable',
|
|
135
|
+
accountCannotAccept: 'This account cannot accept invitations.',
|
|
136
|
+
wrongAddressTitle: 'Invitation for another address',
|
|
137
|
+
wrongAddressText: 'You are signed in with an address this invitation was not sent to. Sign in with the invited address.',
|
|
138
|
+
inviterCannotGrant: 'The person who sent this invitation can no longer give this role. Ask for a new invitation.',
|
|
139
|
+
roleNotEligible: 'This account cannot hold the role this invitation gives. Ask the person who sent it.',
|
|
140
|
+
acceptedTitle: 'Invitation accepted',
|
|
141
|
+
acceptedText: ({ role, scope, appName }) => `You are now ${role} of a ${scope} of ${appName}.`,
|
|
142
|
+
invalidTitle: 'Link unavailable',
|
|
143
|
+
invalidText:
|
|
144
|
+
'This invitation is invalid, expired, cancelled or already used. If you have not accepted it yet, ask the person who invited you to send it again.',
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
...iamMailCatalog('en'),
|
|
148
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// IAM's words, per language: every page it renders for a person and its own e-mails. A string is plain text; the page
|
|
2
|
+
// or the template that inserts it escapes it. `catalogs` must name every locale and each one every key, so a missing
|
|
3
|
+
// translation fails the typecheck.
|
|
4
|
+
|
|
5
|
+
import type { IamMailCatalog, Locale } from '@fabrika/auth-core'
|
|
6
|
+
import type { AuthFailure } from '../auth/failure'
|
|
7
|
+
import type { PasswordProblem } from '../password-policy'
|
|
8
|
+
import { cs } from './cs'
|
|
9
|
+
import { en } from './en'
|
|
10
|
+
import { uk } from './uk'
|
|
11
|
+
|
|
12
|
+
export interface PageText {
|
|
13
|
+
/** The words before fabrika's mark and name in the footer of every page: "Runs on [mark] fabrika". */
|
|
14
|
+
readonly runsOn: string
|
|
15
|
+
readonly showPassword: string
|
|
16
|
+
readonly hidePassword: string
|
|
17
|
+
readonly email: string
|
|
18
|
+
readonly signIn: {
|
|
19
|
+
/** The page title and heading; `appName` is the application the login hands off to, if it declares one. */
|
|
20
|
+
readonly title: (appName: string | null) => string
|
|
21
|
+
readonly password: string
|
|
22
|
+
readonly submit: string
|
|
23
|
+
readonly forgot: string
|
|
24
|
+
readonly singleSignOn: string
|
|
25
|
+
readonly invalidCredentials: string
|
|
26
|
+
}
|
|
27
|
+
/** A handoff a browser already signed in here may continue, or end to sign in with another account. */
|
|
28
|
+
readonly chooseAccount: {
|
|
29
|
+
readonly title: (appName: string | null) => string
|
|
30
|
+
/** Followed by the account's label. */
|
|
31
|
+
readonly signedInAs: string
|
|
32
|
+
readonly continueAs: (label: string) => string
|
|
33
|
+
readonly another: string
|
|
34
|
+
/** Another account ends this login, and every app session made from it. */
|
|
35
|
+
readonly anotherNote: string
|
|
36
|
+
}
|
|
37
|
+
readonly forgot: {
|
|
38
|
+
readonly title: string
|
|
39
|
+
readonly intro: (appName: string | null) => string
|
|
40
|
+
readonly submit: string
|
|
41
|
+
readonly sentTitle: string
|
|
42
|
+
readonly sentText: string
|
|
43
|
+
readonly back: string
|
|
44
|
+
}
|
|
45
|
+
readonly setPassword: {
|
|
46
|
+
readonly title: (purpose: 'enrollment' | 'reset') => string
|
|
47
|
+
readonly rule: (min: number, max: number) => string
|
|
48
|
+
/** The password belongs to the person's account on the installation, not to the application. */
|
|
49
|
+
readonly shared: (appName: string | null) => string
|
|
50
|
+
readonly newPassword: string
|
|
51
|
+
readonly problem: (problem: PasswordProblem, min: number, max: number) => string
|
|
52
|
+
}
|
|
53
|
+
readonly failure: {
|
|
54
|
+
readonly title: string
|
|
55
|
+
readonly text: (failure: AuthFailure) => string
|
|
56
|
+
}
|
|
57
|
+
readonly invalidLink: {
|
|
58
|
+
readonly title: string
|
|
59
|
+
readonly text: string
|
|
60
|
+
readonly requestNew: string
|
|
61
|
+
}
|
|
62
|
+
readonly logout: {
|
|
63
|
+
readonly title: string
|
|
64
|
+
readonly text: string
|
|
65
|
+
readonly submit: string
|
|
66
|
+
}
|
|
67
|
+
/** Enrolling this browser as a shared terminal (ADR-0067): the administrator's form, and the page that ends it. */
|
|
68
|
+
readonly terminal: {
|
|
69
|
+
readonly enrolTitle: string
|
|
70
|
+
/** Enrolling signs the administrator out of this browser. */
|
|
71
|
+
readonly enrolText: string
|
|
72
|
+
readonly label: string
|
|
73
|
+
readonly labelProblem: (max: number) => string
|
|
74
|
+
readonly submit: string
|
|
75
|
+
readonly enrolledTitle: string
|
|
76
|
+
readonly enrolledText: (label: string) => string
|
|
77
|
+
}
|
|
78
|
+
readonly invitation: {
|
|
79
|
+
readonly title: string
|
|
80
|
+
readonly text: string
|
|
81
|
+
readonly submit: string
|
|
82
|
+
/** The set-password form of an invitation that creates its principal; `address` is the invited mailbox. */
|
|
83
|
+
readonly createTitle: string
|
|
84
|
+
readonly createText: (address: string) => string
|
|
85
|
+
readonly createSubmit: string
|
|
86
|
+
/** A browser signed in here as someone else opened an invitation that creates a new account for `address`. */
|
|
87
|
+
readonly otherAccountTitle: string
|
|
88
|
+
readonly otherAccountText: (address: string) => string
|
|
89
|
+
readonly signOut: string
|
|
90
|
+
readonly signInFirstTitle: string
|
|
91
|
+
readonly signInFirstText: string
|
|
92
|
+
readonly signIn: string
|
|
93
|
+
/**
|
|
94
|
+
* No principal holds `address`, this invitation creates none, and no sign-in here would create one: the person
|
|
95
|
+
* cannot accept on their own. The invitation stays open.
|
|
96
|
+
*/
|
|
97
|
+
readonly noAccountTitle: string
|
|
98
|
+
readonly noAccountText: (address: string) => string
|
|
99
|
+
readonly unavailableTitle: string
|
|
100
|
+
readonly accountCannotAccept: string
|
|
101
|
+
readonly wrongAddressTitle: string
|
|
102
|
+
readonly wrongAddressText: string
|
|
103
|
+
readonly inviterCannotGrant: string
|
|
104
|
+
/** An external principal and a role not declared external (ADR-0051). */
|
|
105
|
+
readonly roleNotEligible: string
|
|
106
|
+
readonly acceptedTitle: string
|
|
107
|
+
readonly acceptedText: (values: { readonly role: string; readonly scope: string; readonly appName: string }) => string
|
|
108
|
+
readonly invalidTitle: string
|
|
109
|
+
readonly invalidText: string
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** IAM's words: its pages here, and its e-mails as `@fabrika/auth-core` words them (`iamMailCatalog`). */
|
|
114
|
+
export interface Catalog extends IamMailCatalog {
|
|
115
|
+
readonly pages: PageText
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const catalogs: { readonly [L in Locale]: Catalog } = { en, cs, uk }
|
|
119
|
+
|
|
120
|
+
export function catalogFor(locale: Locale): Catalog {
|
|
121
|
+
return catalogs[locale]
|
|
122
|
+
}
|