@smplcty/auth 11.1.0 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +16 -12
  2. package/dist/http/handlers.d.ts.map +1 -1
  3. package/dist/http/handlers.js +69 -23
  4. package/dist/http/handlers.js.map +1 -1
  5. package/dist/http/index.d.ts +1 -1
  6. package/dist/http/index.d.ts.map +1 -1
  7. package/dist/http/types.d.ts +43 -3
  8. package/dist/http/types.d.ts.map +1 -1
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/methods/email-code/index.d.ts.map +1 -1
  14. package/dist/methods/email-code/index.js +3 -0
  15. package/dist/methods/email-code/index.js.map +1 -1
  16. package/dist/methods/errors.d.ts +12 -0
  17. package/dist/methods/errors.d.ts.map +1 -1
  18. package/dist/methods/errors.js +15 -0
  19. package/dist/methods/errors.js.map +1 -1
  20. package/dist/methods/oidc/credentials.d.ts +76 -0
  21. package/dist/methods/oidc/credentials.d.ts.map +1 -0
  22. package/dist/methods/oidc/credentials.js +164 -0
  23. package/dist/methods/oidc/credentials.js.map +1 -0
  24. package/dist/methods/oidc/index.d.ts +26 -8
  25. package/dist/methods/oidc/index.d.ts.map +1 -1
  26. package/dist/methods/oidc/index.js +45 -2
  27. package/dist/methods/oidc/index.js.map +1 -1
  28. package/dist/methods/router.d.ts +3 -1
  29. package/dist/methods/router.d.ts.map +1 -1
  30. package/dist/methods/router.js +22 -5
  31. package/dist/methods/router.js.map +1 -1
  32. package/dist/methods/twilio/index.d.ts.map +1 -1
  33. package/dist/methods/twilio/index.js +5 -0
  34. package/dist/methods/twilio/index.js.map +1 -1
  35. package/dist/methods/types.d.ts +19 -3
  36. package/dist/methods/types.d.ts.map +1 -1
  37. package/package.json +26 -17
  38. package/schema/tables/auth_domain_credentials.yaml +86 -0
  39. package/schema/tables/auth_domains.yaml +8 -6
  40. package/schema/tables/tenant_email_domains.yaml +9 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smplcty/auth",
3
- "version": "11.1.0",
3
+ "version": "12.0.0",
4
4
  "description": "Robust, type-safe session and role-based authentication primitives for PostgreSQL apps using Row-Level Security.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -101,9 +101,12 @@
101
101
  ]
102
102
  },
103
103
  "peerDependencies": {
104
+ "@peculiar/x509": ">=3.0.0",
105
+ "@smplcty/schema-flow": ">=0.25.0",
104
106
  "@smplcty/twilio": ">=0.1.0",
105
107
  "oauth4webapi": ">=3.0.0",
106
- "pg": ">=8.0.0"
108
+ "pg": ">=8.0.0",
109
+ "reflect-metadata": ">=0.2.0"
107
110
  },
108
111
  "peerDependenciesMeta": {
109
112
  "@smplcty/twilio": {
@@ -111,35 +114,41 @@
111
114
  },
112
115
  "oauth4webapi": {
113
116
  "optional": true
117
+ },
118
+ "@smplcty/schema-flow": {
119
+ "optional": true
120
+ },
121
+ "@peculiar/x509": {
122
+ "optional": true
123
+ },
124
+ "reflect-metadata": {
125
+ "optional": true
114
126
  }
115
127
  },
116
128
  "devDependencies": {
129
+ "@peculiar/x509": "^3.1.0",
117
130
  "@release-it/keep-a-changelog": "^8.0.1",
118
- "@smplcty/schema-flow": "^0.24.0",
131
+ "@smplcty/schema-flow": "^0.26.0",
119
132
  "@smplcty/twilio": "^0.1.1",
120
- "@testcontainers/postgresql": "^12.2.0",
121
- "@types/node": "^22.20.5",
133
+ "@testcontainers/postgresql": "^12.2.1",
134
+ "@types/node": "^26.6.6",
122
135
  "@types/pg": "^8.23.1",
123
136
  "husky": "^9.1.7",
124
- "jose": "^6.2.12",
137
+ "jose": "^6.2.14",
125
138
  "lint-staged": "^17.6.0",
126
139
  "oauth4webapi": "^3.8.8",
127
- "oxlint": "^1.87.0",
140
+ "oxlint": "^1.90.0",
128
141
  "pg": "^8.23.1",
129
142
  "prettier": "^3.9.10",
130
- "release-it": "^21.1.1",
143
+ "reflect-metadata": "^0.2.2",
144
+ "release-it": "^21.1.2",
131
145
  "typescript": "^7.0.2",
132
- "vite": "^8.3.4",
133
- "vitest": "^5.0.4"
146
+ "vite": "^8.3.5",
147
+ "vitest": "^5.0.5"
134
148
  },
135
149
  "dependencies": {
136
150
  "@smplcty/db": "^4.3.0",
137
- "@smplcty/schema-std": "^0.0.1",
138
- "otplib": "^13.5.0"
139
- },
140
- "pnpm": {
141
- "overrides": {
142
- "undici@7.29.0": "7.29.1"
143
- }
151
+ "@smplcty/schema-std": "^0.1.0",
152
+ "otplib": "^13.6.0"
144
153
  }
145
154
  }
@@ -0,0 +1,86 @@
1
+ table: auth_domain_credentials
2
+ # The client credential an auth domain (a tenant's IdP) uses at the token
3
+ # endpoint: a client secret, and/or a generated private key for private_key_jwt.
4
+ # One row per auth domain. The tenant's security or settings admin sets it from
5
+ # the app; nobody provisions it through infrastructure.
6
+ #
7
+ # Never plaintext: the app encrypts through its own hook (for example a KMS data
8
+ # key) before writing, and decrypts only in memory during a token exchange.
9
+ #
10
+ # Grants. No role reachable from a tenant session can read a secret or private
11
+ # key back, by any route: app_rls gets column grants that write the ciphertext
12
+ # columns but SELECT only the public and status columns. (SELECT is also what a
13
+ # WHERE clause needs, so the ciphertext can't be probed with UPDATE … WHERE
14
+ # either.) Only app_privileged, the pre-session sign-in machinery, reads the
15
+ # ciphertext, for the token exchange.
16
+ mixins: [audit]
17
+ grants:
18
+ - to: app_rls
19
+ privileges: [SELECT]
20
+ columns: [auth_domain_id, secret_set_at, private_key_set_at, public_jwk, certificate, created_at, updated_at]
21
+ - to: app_rls
22
+ privileges: [INSERT]
23
+ columns:
24
+ [
25
+ auth_domain_id,
26
+ secret_ciphertext,
27
+ secret_set_at,
28
+ private_key_ciphertext,
29
+ private_key_set_at,
30
+ public_jwk,
31
+ certificate,
32
+ ]
33
+ - to: app_rls
34
+ privileges: [UPDATE]
35
+ columns: [secret_ciphertext, secret_set_at, private_key_ciphertext, private_key_set_at, public_jwk, certificate]
36
+ - to: app_privileged
37
+ privileges: [SELECT]
38
+ columns:
39
+ - name: auth_domain_id
40
+ type: bigint
41
+ primary_key: true
42
+ references:
43
+ table: auth_domains
44
+ column: auth_domain_id
45
+ # The client secret, encrypted by the app's hook. NULL when none is set.
46
+ - name: secret_ciphertext
47
+ type: text
48
+ - name: secret_set_at
49
+ type: timestamptz
50
+ # The PKCS#8 private key for private_key_jwt, encrypted by the app's hook.
51
+ - name: private_key_ciphertext
52
+ type: text
53
+ - name: private_key_set_at
54
+ type: timestamptz
55
+ # The public half, readable by the tenant admin to upload to their IdP: a
56
+ # JWK (with kid, x5c and x5t#S256) and a self-signed X.509 certificate (PEM),
57
+ # which is what Entra's certificate upload takes.
58
+ - name: public_jwk
59
+ type: jsonb
60
+ - name: certificate
61
+ type: text
62
+ checks:
63
+ - name: auth_domain_credentials_secret_pair_check
64
+ expression: '(secret_ciphertext IS NULL) = (secret_set_at IS NULL)'
65
+ - name: auth_domain_credentials_key_pair_check
66
+ expression: '(private_key_ciphertext IS NULL) = (private_key_set_at IS NULL)'
67
+ # RLS. Whoever may configure the tenant's SSO (its security or settings admin)
68
+ # may write its credentials, for live auth domains only. A soft-deleted auth
69
+ # domain's credential is also never used: the token exchange reads it joined to
70
+ # a live auth_domains row.
71
+ rls: true
72
+ policies:
73
+ - name: auth_domain_credentials_sso_admin
74
+ for: ALL
75
+ to: app_rls
76
+ permissive: true
77
+ using: >-
78
+ EXISTS (SELECT 1 FROM auth_domains ad
79
+ WHERE ad.auth_domain_id = auth_domain_credentials.auth_domain_id
80
+ AND ad.deleted_at IS NULL
81
+ AND (auth_has_role('security', ad.tenant_id) OR auth_has_role('settings', ad.tenant_id)))
82
+ check: >-
83
+ EXISTS (SELECT 1 FROM auth_domains ad
84
+ WHERE ad.auth_domain_id = auth_domain_credentials.auth_domain_id
85
+ AND ad.deleted_at IS NULL
86
+ AND (auth_has_role('security', ad.tenant_id) OR auth_has_role('settings', ad.tenant_id)))
@@ -45,15 +45,17 @@ columns:
45
45
  type: jsonb
46
46
  nullable: false
47
47
  default: "'{}'::jsonb"
48
- # RLS. Federation config is a settings concern: a settings admin sees and
49
- # maintains the auth_domains of the tenants they have settings access to. (Sign-
50
- # in itself reads auth_domains through the bypass pool pre-session, so ordinary
51
- # users never need direct access here.)
48
+ # RLS. Setting up a tenant's SSO is a job for its security or settings admin:
49
+ # they see and maintain the auth_domains of the tenants they hold either role
50
+ # for. (Sign-in itself reads auth_domains through the bypass pool pre-session,
51
+ # so ordinary users never need direct access here.)
52
52
  rls: true
53
53
  policies:
54
+ # The policy keeps its original name, from when only settings admins were admitted:
55
+ # renaming it would leave the old policy behind as a blocked destructive drop.
54
56
  - name: auth_domains_settings
55
57
  for: ALL
56
58
  to: app_rls
57
59
  permissive: true
58
- using: auth_has_role('settings', auth_domains.tenant_id)
59
- check: auth_has_role('settings', auth_domains.tenant_id)
60
+ using: auth_has_role('security', auth_domains.tenant_id) OR auth_has_role('settings', auth_domains.tenant_id)
61
+ check: auth_has_role('security', auth_domains.tenant_id) OR auth_has_role('settings', auth_domains.tenant_id)
@@ -68,14 +68,18 @@ indexes:
68
68
  - columns: [domain]
69
69
  where: 'verified_at IS NOT NULL AND deleted_at IS NULL'
70
70
  name: tenant_email_domains_verified_domain_idx
71
- # RLS. A settings concern, like auth_domains: a settings admin sees and
72
- # maintains the email domains of the tenants they have settings access to. The
73
- # sign-in checks read this table through the privileged pool, pre-session.
71
+ # RLS. Part of setting up SSO, like auth_domains: a security or settings admin
72
+ # sees and maintains the email domains (and sso_required) of the tenants they
73
+ # hold either role for. Verifying a domain stays out of their reach through the
74
+ # column grants above. The sign-in checks read this table through the
75
+ # privileged pool, pre-session.
74
76
  rls: true
75
77
  policies:
78
+ # The policy keeps its original name, from when only settings admins were admitted:
79
+ # renaming it would leave the old policy behind as a blocked destructive drop.
76
80
  - name: tenant_email_domains_settings
77
81
  for: ALL
78
82
  to: app_rls
79
83
  permissive: true
80
- using: auth_has_role('settings', tenant_email_domains.tenant_id)
81
- check: auth_has_role('settings', tenant_email_domains.tenant_id)
84
+ using: auth_has_role('security', tenant_email_domains.tenant_id) OR auth_has_role('settings', tenant_email_domains.tenant_id)
85
+ check: auth_has_role('security', tenant_email_domains.tenant_id) OR auth_has_role('settings', tenant_email_domains.tenant_id)