@smplcty/auth 9.0.1 → 10.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.
- package/README.md +12 -9
- package/dist/email-domains/index.d.ts +76 -0
- package/dist/email-domains/index.d.ts.map +1 -0
- package/dist/email-domains/index.js +87 -0
- package/dist/email-domains/index.js.map +1 -0
- package/dist/find-user-by-communication-method.d.ts +4 -0
- package/dist/find-user-by-communication-method.d.ts.map +1 -1
- package/dist/find-user-by-communication-method.js +5 -1
- package/dist/find-user-by-communication-method.js.map +1 -1
- package/dist/http/handlers.d.ts.map +1 -1
- package/dist/http/handlers.js +11 -7
- package/dist/http/handlers.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/email-domain.d.ts +10 -0
- package/dist/internal/email-domain.d.ts.map +1 -0
- package/dist/internal/email-domain.js +54 -0
- package/dist/internal/email-domain.js.map +1 -0
- package/dist/methods/errors.d.ts +27 -5
- package/dist/methods/errors.d.ts.map +1 -1
- package/dist/methods/errors.js +35 -7
- package/dist/methods/errors.js.map +1 -1
- package/dist/methods/oidc/index.d.ts.map +1 -1
- package/dist/methods/oidc/index.js +12 -1
- package/dist/methods/oidc/index.js.map +1 -1
- package/dist/methods/router.d.ts +4 -2
- package/dist/methods/router.d.ts.map +1 -1
- package/dist/methods/router.js +28 -30
- package/dist/methods/router.js.map +1 -1
- package/dist/methods/types.d.ts +10 -9
- package/dist/methods/types.d.ts.map +1 -1
- package/package.json +11 -6
- package/schema/functions/auth_all_tenants.yaml +1 -1
- package/schema/functions/auth_can_admin_user.yaml +1 -1
- package/schema/functions/auth_create_user.yaml +1 -1
- package/schema/functions/auth_has_role.yaml +1 -1
- package/schema/functions/auth_in_tenant.yaml +1 -1
- package/schema/functions/auth_tenant_ids.yaml +1 -1
- package/schema/functions/resolve_session.yaml +1 -1
- package/schema/tables/tenant_email_domains.yaml +81 -0
- package/schema/tables/tenants.yaml +0 -8
- package/schema/tables/user_communication_methods.yaml +4 -1
package/README.md
CHANGED
|
@@ -211,7 +211,9 @@ Sign-in is **tenant-centric**: the app resolves the tenant from the request sub-
|
|
|
211
211
|
- **1 IdP** → straight redirect, no chooser.
|
|
212
212
|
- **N IdPs** → a chooser (one button per IdP, labeled `displayName`, valued by `auth_domain_id`).
|
|
213
213
|
|
|
214
|
-
The user-bound **OTP** path is
|
|
214
|
+
The user-bound **OTP** path is open on every tenant, except that addresses at a verified email domain that requires SSO are refused **in the router**, on every sub-domain (not just hidden in the UI). **OIDC** is handled by a dedicated `@smplcty/auth/oidc` handler (built on [`oauth4webapi`](https://github.com/panva/oauth4webapi)) — its `authorize`/`callback` shape is richer than the OTP two-phase, so it's driven directly rather than through the router. See [ADR-0001](docs/adr/0001-oidc-via-oauth4webapi.md).
|
|
215
|
+
|
|
216
|
+
**A tenant's IdP may only sign in email addresses at domains that tenant has verified** (`tenant_email_domains`). A tenant admin configures their own IdP, and an IdP can claim any address, so without this check one tenant could sign in as another tenant's users, or as a global admin. A tenant proves it owns a domain by publishing a DNS TXT record whose name you white-label (`@smplcty/auth/email-domains`). A verified domain can also **require SSO**, which refuses code sign-in for every address at that domain on every sub-domain. Full reference: **[Email domains](https://mabulu-inc.github.io/simplicity-auth/methods/email-domains/)**.
|
|
215
217
|
|
|
216
218
|
```ts
|
|
217
219
|
import { createMethodRouter } from '@smplcty/auth';
|
|
@@ -228,7 +230,7 @@ const oidc = oidcHandler({ clientSecret: (ad) => secrets.get(ad.tenantId) }); //
|
|
|
228
230
|
// Sign-in page — app parsed Host → 'acme':
|
|
229
231
|
const opts = await router.signInOptions({ tenantSlug: 'acme' });
|
|
230
232
|
// opts = { tenantId, authDomains: AuthDomain[], otpAllowed: boolean }
|
|
231
|
-
// render: a button per opts.authDomains + an OTP form iff opts.otpAllowed
|
|
233
|
+
// render: a button per opts.authDomains + an OTP form iff opts.otpAllowed (an OTP handler is configured)
|
|
232
234
|
|
|
233
235
|
// OIDC — user picked an IdP (an AuthDomain from opts.authDomains):
|
|
234
236
|
const { redirectUrl, loginState } = await oidc.initiate(authDomain);
|
|
@@ -237,8 +239,8 @@ const { redirectUrl, loginState } = await oidc.initiate(authDomain);
|
|
|
237
239
|
const user = await oidc.complete({ db: pool, authDomain, callbackUrl, loginState });
|
|
238
240
|
|
|
239
241
|
// OTP (only when opts.otpAllowed):
|
|
240
|
-
await router.initiateOtp({
|
|
241
|
-
const user2 = await router.completeOtp({
|
|
242
|
+
await router.initiateOtp({ identifier: phone });
|
|
243
|
+
const user2 = await router.completeOtp({ identifier: phone, credential: code });
|
|
242
244
|
|
|
243
245
|
const session = await createSession(pool, {
|
|
244
246
|
userCommunicationMethodId: user.userCommunicationMethodId,
|
|
@@ -284,8 +286,8 @@ app.all('/auth/*', (c) => handlers.handle(c.req.raw).then((r) => r ?? c.notFound
|
|
|
284
286
|
It exposes `GET …/sign-in/options`, `POST …/otp/initiate`, `POST …/otp/complete`,
|
|
285
287
|
`GET …/oidc/start`, `GET …/oidc/callback`, `POST …/sign-out`, and
|
|
286
288
|
`GET …/session`, plus `getSessionToken` / `withRequestSession` for authenticating
|
|
287
|
-
every other request. `returnTo` is open-redirect-guarded,
|
|
288
|
-
server-side, and the OIDC login-state cookie is HMAC-signed and freshness-checked.
|
|
289
|
+
every other request. `returnTo` is open-redirect-guarded, SSO-required email domains are
|
|
290
|
+
enforced server-side, and the OIDC login-state cookie is HMAC-signed and freshness-checked.
|
|
289
291
|
|
|
290
292
|
Full reference: **[HTTP transport](https://mabulu-inc.github.io/simplicity-auth/http/transport/)**.
|
|
291
293
|
|
|
@@ -478,7 +480,7 @@ The library ships its schema as schema-flow YAML inside the package at `@smplcty
|
|
|
478
480
|
@smplcty/auth/schema/
|
|
479
481
|
├── tables/
|
|
480
482
|
│ ├── users.yaml # + audit; seeds the app-init service user (matched by name)
|
|
481
|
-
│ ├── tenants.yaml # + audit; slug (sub-domain, DNS-label CHECK),
|
|
483
|
+
│ ├── tenants.yaml # + audit; slug (sub-domain, DNS-label CHECK), and tenant_email_domains.yaml (verified email domains, SSO required)
|
|
482
484
|
│ ├── roles.yaml # + audit; seeds 'user' (default), 'settings', 'security'
|
|
483
485
|
│ ├── user_roles.yaml # + audit; tenant_id NULL = wildcard / all tenants
|
|
484
486
|
│ ├── communication_channels.yaml # + audit
|
|
@@ -495,7 +497,7 @@ The library ships its schema as schema-flow YAML inside the package at `@smplcty
|
|
|
495
497
|
|
|
496
498
|
### Consuming with [`@smplcty/schema-flow`](https://www.npmjs.com/package/@smplcty/schema-flow)
|
|
497
499
|
|
|
498
|
-
Requires **`@smplcty/schema-flow >= 0.
|
|
500
|
+
Requires **`@smplcty/schema-flow >= 0.21.1`** — the shipped seeds assign no primary keys (the app-init user and the standard roles are matched by their natural keys, `name`/`kind`) and rely on insert-only seeding, where an existing row is never overwritten. `0.13.0` makes insert-only the default (the old per-table `seeds_on_conflict` knob is gone); on older versions these seeds would upsert and clobber any consumer edits to the standard roles on every migration. `0.14.0` is required so `resolve_session` converges: it canonicalizes function type aliases (`resolve_session` returns a `TABLE(… expires_at timestamptz …)`), so the function no longer reports phantom drift on every `plan`/`run`/`drift`. `0.18.2` is required for the `SECURITY DEFINER` search_path pins (see below): it emits the pin as a valid `SET search_path` clause and compares it against `pg_proc.proconfig` semantically (whitespace/case-normalized), so a pinned function converges to a clean no-op instead of reporting phantom drift. `0.21.1` is required to upgrade an existing database to the case-insensitive `user_communication_methods_channel_code_key`: it swaps a redefined index in without `--allow-destructive` and keeps the old one if the new one cannot be built. Older versions skip the change unless you pass the flag, and can leave the table without a working index if the build fails.
|
|
499
501
|
|
|
500
502
|
If you are upgrading an existing database, run schema-flow with `--allow-destructive` once: `0.14.0` recreates a function whose return type changed via `DROP … CASCADE` + a post-apply convergence pass that restores the dependent RLS policies, and (where a live DB carries a plain `UNIQUE` constraint sharing a name with one of auth's partial-unique indexes) drops the constraint and builds the partial index. Both paths are gated behind the flag; without it the change is reported as blocked rather than silently no-applied.
|
|
501
503
|
|
|
@@ -512,7 +514,7 @@ The `audit` mixin makes `created_by`/`updated_by` NOT NULL, stamped from `app.ac
|
|
|
512
514
|
|
|
513
515
|
### ⚠️ Known limitation — auth must deploy into the `public` schema
|
|
514
516
|
|
|
515
|
-
The library's seven `SECURITY DEFINER` functions (`auth_has_role`, `auth_can_admin_user`, `auth_in_tenant`, `auth_all_tenants`, `auth_tenant_ids`, `resolve_session`, `auth_create_user`) each ship with a **pinned `search_path` of `pg_catalog, public`**. This is a security hardening: a `SECURITY DEFINER` function otherwise inherits the _caller's_ `search_path`, so a caller who plants a shadow object (a fake `user_roles` table, a fake `current_user_id()`) in an earlier-resolving schema could make an unqualified name inside these functions resolve to _their_ object — and it would run with the definer's elevated rights, subverting an authorization check. Pinning to the trusted schema list closes that. (`current_user_id()` is `SECURITY INVOKER`, so it carries no escalation risk and is intentionally left unpinned.)
|
|
517
|
+
The library's seven `SECURITY DEFINER` functions (`auth_has_role`, `auth_can_admin_user`, `auth_in_tenant`, `auth_all_tenants`, `auth_tenant_ids`, `resolve_session`, `auth_create_user`) each ship with a **pinned `search_path` of `pg_catalog, public, pg_temp`**. This is a security hardening: a `SECURITY DEFINER` function otherwise inherits the _caller's_ `search_path`, so a caller who plants a shadow object (a fake `user_roles` table, a fake `current_user_id()`) in an earlier-resolving schema could make an unqualified name inside these functions resolve to _their_ object — and it would run with the definer's elevated rights, subverting an authorization check. Pinning to the trusted schema list closes that. `pg_temp` is listed **last** on purpose: when it is left out, Postgres searches the caller's temporary schema _first_ for table names, so any caller able to run SQL could shadow `user_roles` with a temp table of the same name. Listed last, it can never take precedence over `public`. (`current_user_id()` is `SECURITY INVOKER`, so it carries no escalation risk and is intentionally left unpinned.)
|
|
516
518
|
|
|
517
519
|
The consequence: **`public` is hardcoded into the shipped pin**, so auth must be deployed into the `public` schema. Every consumer today deploys there (schema-flow's default), so this is a no-op for you in practice — but if you deploy auth into a non-`public` schema (e.g. `auth`, `app`), the pinned path won't contain auth's tables and the functions will break. schema-flow does not yet interpolate the deploy `pgSchema` into `set:` values, which is the only reason the pin can't be schema-agnostic.
|
|
518
520
|
|
|
@@ -536,6 +538,7 @@ Every table carries the `soft_delete` mixin (`deleted_at`). The library **honors
|
|
|
536
538
|
- Identity GUCs set via `set_config($1, $2, true)`, transaction-scoped — injection and cross-request leakage are impossible.
|
|
537
539
|
- `withSession` validates existence, expiry/revocation, and role membership before running the callback. Fails closed.
|
|
538
540
|
- Force sign-off is a row update (per-session, per-user, or per-tenant); role/privilege changes apply on the next request.
|
|
541
|
+
- A tenant's IdP is trusted only for email domains the tenant has proven it owns via DNS; tenant admins can't mark a domain verified by any write.
|
|
539
542
|
- Auth core has no `jose`/Twilio dependency; method handlers are opt-in subpaths with optional peers.
|
|
540
543
|
|
|
541
544
|
## License
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Queryable } from '../types.js';
|
|
2
|
+
/** Resolve a name's TXT records: one array of character-string chunks per record. */
|
|
3
|
+
export type ResolveTxt = (name: string) => Promise<string[][]>;
|
|
4
|
+
export interface EmailDomainVerifierOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The label(s) the TXT record lives under, prepended to the domain — e.g.
|
|
7
|
+
* `'_my-shiny-product'` publishes at `_my-shiny-product.acme.com`. Your
|
|
8
|
+
* product's name, not this library's: customers see and publish it. An
|
|
9
|
+
* underscore-prefixed label is recommended (RFC 8552): a bare label is a
|
|
10
|
+
* hostname that can collide with a real host, or with a CNAME on that name.
|
|
11
|
+
*/
|
|
12
|
+
recordLabel: string;
|
|
13
|
+
/**
|
|
14
|
+
* The value's prefix — e.g. `'my-shiny-product-verification'` publishes
|
|
15
|
+
* `my-shiny-product-verification=<token>`.
|
|
16
|
+
*/
|
|
17
|
+
valuePrefix: string;
|
|
18
|
+
/**
|
|
19
|
+
* Override the DNS lookup. Defaults to `node:dns/promises` `resolveTxt`
|
|
20
|
+
* (loaded on first use). Pass a DNS-over-HTTPS resolver where `node:dns` is
|
|
21
|
+
* unavailable (edge runtimes), or a fake in tests.
|
|
22
|
+
*/
|
|
23
|
+
resolveTxt?: ResolveTxt;
|
|
24
|
+
}
|
|
25
|
+
/** The TXT record a customer publishes to prove they own a domain. */
|
|
26
|
+
export interface EmailDomainVerificationRecord {
|
|
27
|
+
readonly type: 'TXT';
|
|
28
|
+
/** Fully qualified record name, e.g. `_my-shiny-product.acme.com`. */
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly value: string;
|
|
31
|
+
}
|
|
32
|
+
export interface EmailDomainVerifier {
|
|
33
|
+
/**
|
|
34
|
+
* The record to show the customer for a `tenant_email_domains` row (its
|
|
35
|
+
* `domain` and `verification_token`, which a settings admin can read).
|
|
36
|
+
*/
|
|
37
|
+
record(row: {
|
|
38
|
+
domain: string;
|
|
39
|
+
verificationToken: string;
|
|
40
|
+
}): EmailDomainVerificationRecord;
|
|
41
|
+
/**
|
|
42
|
+
* Look the row's record up in DNS and, if it carries the row's token, mark
|
|
43
|
+
* the domain verified. Returns whether the domain is verified. Safe to call
|
|
44
|
+
* on any user's behalf: it only ever records what DNS proves. Retry when the
|
|
45
|
+
* customer has just published the record — DNS can take minutes to show it.
|
|
46
|
+
*
|
|
47
|
+
* **Contract:** `db` connects as `app_privileged` (app_rls cannot write
|
|
48
|
+
* `verified_at`) with an audit actor set — e.g. a client inside
|
|
49
|
+
* `withServiceContext`, since `updated_by` is NOT NULL.
|
|
50
|
+
*
|
|
51
|
+
* @throws {InvalidInputError} If no live row has that id.
|
|
52
|
+
*/
|
|
53
|
+
verify(db: Queryable, tenantEmailDomainId: number): Promise<boolean>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Build the DNS verifier for `tenant_email_domains` (opt-in subpath
|
|
57
|
+
* `@smplcty/auth/email-domains`). An auth domain authenticates only email
|
|
58
|
+
* addresses at its tenant's verified domains; this is how a domain becomes
|
|
59
|
+
* verified. A global admin can instead mark a row verified directly
|
|
60
|
+
* (`UPDATE tenant_email_domains SET verified_at = now() …` through the
|
|
61
|
+
* privileged pool) for a customer who can't edit DNS.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const verifier = emailDomainVerifier({
|
|
66
|
+
* recordLabel: '_my-shiny-product',
|
|
67
|
+
* valuePrefix: 'my-shiny-product-verification',
|
|
68
|
+
* });
|
|
69
|
+
* verifier.record(row); // { type: 'TXT', name: '_my-shiny-product.acme.com', value: 'my-shiny-product-verification=…' }
|
|
70
|
+
* const verified = await withServiceContext(privilegedPool, 'domain-verifier', (c) => verifier.verify(c, row.id));
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @throws {InvalidInputError} If `recordLabel` or `valuePrefix` is malformed.
|
|
74
|
+
*/
|
|
75
|
+
export declare function emailDomainVerifier(options: EmailDomainVerifierOptions): EmailDomainVerifier;
|
|
76
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/email-domains/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,qFAAqF;AACrF,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAE/D,MAAM,WAAW,0BAA0B;IACzC;;;;;;OAMG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,sEAAsE;AACtE,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,iBAAiB,EAAE,MAAM,CAAA;KAAE,GAAG,6BAA6B,CAAC;IAC1F;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtE;AAkCD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,mBAAmB,CA0C5F"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { InvalidInputError } from '../errors.js';
|
|
2
|
+
const LABEL_PATTERN = /^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*$/;
|
|
3
|
+
// DNS lookups that mean "no such record yet", not a failure.
|
|
4
|
+
const NO_RECORD_CODES = new Set(['ENOTFOUND', 'ENODATA']);
|
|
5
|
+
const SELECT_ROW = `
|
|
6
|
+
SELECT domain, verification_token AS "verificationToken", verified_at AS "verifiedAt"
|
|
7
|
+
FROM tenant_email_domains
|
|
8
|
+
WHERE tenant_email_domain_id = $1 AND deleted_at IS NULL
|
|
9
|
+
`;
|
|
10
|
+
// The token guard keeps a row from being verified by a lookup of a token it
|
|
11
|
+
// no longer carries.
|
|
12
|
+
const MARK_VERIFIED = `
|
|
13
|
+
UPDATE tenant_email_domains
|
|
14
|
+
SET verified_at = now()
|
|
15
|
+
WHERE tenant_email_domain_id = $1
|
|
16
|
+
AND verification_token = $2
|
|
17
|
+
AND verified_at IS NULL
|
|
18
|
+
AND deleted_at IS NULL
|
|
19
|
+
`;
|
|
20
|
+
const nodeResolveTxt = async (name) => {
|
|
21
|
+
const dns = await import('node:dns/promises');
|
|
22
|
+
return dns.resolveTxt(name);
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Build the DNS verifier for `tenant_email_domains` (opt-in subpath
|
|
26
|
+
* `@smplcty/auth/email-domains`). An auth domain authenticates only email
|
|
27
|
+
* addresses at its tenant's verified domains; this is how a domain becomes
|
|
28
|
+
* verified. A global admin can instead mark a row verified directly
|
|
29
|
+
* (`UPDATE tenant_email_domains SET verified_at = now() …` through the
|
|
30
|
+
* privileged pool) for a customer who can't edit DNS.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const verifier = emailDomainVerifier({
|
|
35
|
+
* recordLabel: '_my-shiny-product',
|
|
36
|
+
* valuePrefix: 'my-shiny-product-verification',
|
|
37
|
+
* });
|
|
38
|
+
* verifier.record(row); // { type: 'TXT', name: '_my-shiny-product.acme.com', value: 'my-shiny-product-verification=…' }
|
|
39
|
+
* const verified = await withServiceContext(privilegedPool, 'domain-verifier', (c) => verifier.verify(c, row.id));
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @throws {InvalidInputError} If `recordLabel` or `valuePrefix` is malformed.
|
|
43
|
+
*/
|
|
44
|
+
export function emailDomainVerifier(options) {
|
|
45
|
+
const { recordLabel, valuePrefix } = options;
|
|
46
|
+
if (typeof recordLabel !== 'string' || !LABEL_PATTERN.test(recordLabel)) {
|
|
47
|
+
throw new InvalidInputError('recordLabel must be one or more DNS labels (letters, digits, "_" and "-")');
|
|
48
|
+
}
|
|
49
|
+
if (typeof valuePrefix !== 'string' || valuePrefix.length === 0 || /[\s=]/.test(valuePrefix)) {
|
|
50
|
+
throw new InvalidInputError('valuePrefix must be a non-empty string without whitespace or "="');
|
|
51
|
+
}
|
|
52
|
+
const resolveTxt = options.resolveTxt ?? nodeResolveTxt;
|
|
53
|
+
function record(row) {
|
|
54
|
+
return { type: 'TXT', name: `${recordLabel}.${row.domain}`, value: `${valuePrefix}=${row.verificationToken}` };
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
record,
|
|
58
|
+
async verify(db, tenantEmailDomainId) {
|
|
59
|
+
if (!Number.isInteger(tenantEmailDomainId) || tenantEmailDomainId <= 0) {
|
|
60
|
+
throw new InvalidInputError('tenantEmailDomainId must be a positive integer');
|
|
61
|
+
}
|
|
62
|
+
const { rows } = await db.query(SELECT_ROW, [tenantEmailDomainId]);
|
|
63
|
+
const row = rows[0];
|
|
64
|
+
if (!row)
|
|
65
|
+
throw new InvalidInputError(`No email domain with id ${tenantEmailDomainId}`);
|
|
66
|
+
if (row.verifiedAt)
|
|
67
|
+
return true;
|
|
68
|
+
const expected = record(row);
|
|
69
|
+
let records;
|
|
70
|
+
try {
|
|
71
|
+
records = await resolveTxt(expected.name);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
if (NO_RECORD_CODES.has(err.code ?? ''))
|
|
75
|
+
return false;
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
78
|
+
// A long TXT value arrives split into 255-byte chunks; rejoin each record.
|
|
79
|
+
if (!records.some((chunks) => chunks.join('') === expected.value))
|
|
80
|
+
return false;
|
|
81
|
+
const marked = await db.query(MARK_VERIFIED, [tenantEmailDomainId, row.verificationToken]);
|
|
82
|
+
// Zero rows: removed (or re-verified) since the read above.
|
|
83
|
+
return (marked.rowCount ?? 0) > 0;
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/email-domains/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAyDjD,MAAM,aAAa,GAAG,qCAAqC,CAAC;AAC5D,6DAA6D;AAC7D,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC;AAE1D,MAAM,UAAU,GAAG;;;;CAIlB,CAAC;AAEF,4EAA4E;AAC5E,qBAAqB;AACrB,MAAM,aAAa,GAAG;;;;;;;CAOrB,CAAC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AAE,CAAC,KAAK,CAAM,UAAU,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC;YACxE,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YACpB,IAAI,CAAC,GAAG;gBAAE,MAAM,IAAI,iBAAiB,CAAC,2BAA2B,mBAAmB,EAAE,CAAC,CAAC;YACxF,IAAI,GAAG,CAAC,UAAU;gBAAE,OAAO,IAAI,CAAC;YAEhC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,OAAmB,CAAC;YACxB,IAAI,CAAC;gBACH,OAAO,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC5C,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,eAAe,CAAC,GAAG,CAAE,GAAyB,CAAC,IAAI,IAAI,EAAE,CAAC;oBAAE,OAAO,KAAK,CAAC;gBAC7E,MAAM,GAAG,CAAC;YACZ,CAAC;YACD,2EAA2E;YAC3E,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,QAAQ,CAAC,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;YAEhF,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,mBAAmB,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC;YAC3F,4DAA4D;YAC5D,OAAO,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACpC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -3,6 +3,10 @@ import type { FindUserQuery, Queryable, UserByCommunicationMethod } from './type
|
|
|
3
3
|
* Look up the user attached to a communication method (an email address,
|
|
4
4
|
* phone number, etc). Returns `null` if no matching record exists.
|
|
5
5
|
*
|
|
6
|
+
* `code` matches in any casing (`Bob@Acme.com` finds `bob@acme.com`); the
|
|
7
|
+
* stored code keeps the casing it was entered with. Normalize phone numbers
|
|
8
|
+
* before storing and before calling this.
|
|
9
|
+
*
|
|
6
10
|
* Returning `null` instead of throwing is deliberate: the caller (a
|
|
7
11
|
* sign-in endpoint, typically) decides whether to expose user-existence
|
|
8
12
|
* information to the client. To avoid the user-enumeration oracle, most
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-user-by-communication-method.d.ts","sourceRoot":"","sources":["../src/find-user-by-communication-method.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAkBtF
|
|
1
|
+
{"version":3,"file":"find-user-by-communication-method.d.ts","sourceRoot":"","sources":["../src/find-user-by-communication-method.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAkBtF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,6BAA6B,CACjD,EAAE,EAAE,SAAS,EACb,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAgB3C"}
|
|
@@ -8,7 +8,7 @@ const SELECT_BY_COMMUNICATION_METHOD = `
|
|
|
8
8
|
ON cc.communication_channel_id = ucm.communication_channel_id
|
|
9
9
|
JOIN users u ON u.user_id = ucm.user_id
|
|
10
10
|
WHERE cc.name = $1
|
|
11
|
-
AND ucm.code = $2
|
|
11
|
+
AND lower(ucm.code) = lower($2)
|
|
12
12
|
AND ucm.deleted_at IS NULL
|
|
13
13
|
AND cc.deleted_at IS NULL
|
|
14
14
|
AND u.deleted_at IS NULL
|
|
@@ -18,6 +18,10 @@ const SELECT_BY_COMMUNICATION_METHOD = `
|
|
|
18
18
|
* Look up the user attached to a communication method (an email address,
|
|
19
19
|
* phone number, etc). Returns `null` if no matching record exists.
|
|
20
20
|
*
|
|
21
|
+
* `code` matches in any casing (`Bob@Acme.com` finds `bob@acme.com`); the
|
|
22
|
+
* stored code keeps the casing it was entered with. Normalize phone numbers
|
|
23
|
+
* before storing and before calling this.
|
|
24
|
+
*
|
|
21
25
|
* Returning `null` instead of throwing is deliberate: the caller (a
|
|
22
26
|
* sign-in endpoint, typically) decides whether to expose user-existence
|
|
23
27
|
* information to the client. To avoid the user-enumeration oracle, most
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-user-by-communication-method.js","sourceRoot":"","sources":["../src/find-user-by-communication-method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,8BAA8B,GAAG;;;;;;;;;;;;;;CActC,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"find-user-by-communication-method.js","sourceRoot":"","sources":["../src/find-user-by-communication-method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,8BAA8B,GAAG;;;;;;;;;;;;;;CActC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,EAAa,EACb,KAAoB;IAEpB,IAAI,OAAO,KAAK,EAAE,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,iBAAiB,CAAC,0CAA0C,CAAC,CAAC;IAC1E,CAAC;IACD,IAAI,OAAO,KAAK,EAAE,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,iBAAiB,CAAC,uCAAuC,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,KAAK,CAA4B,8BAA8B,EAAE;QACzF,KAAK,CAAC,OAAO;QACb,KAAK,CAAC,IAAI;KACX,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IACtB,kEAAkE;IAClE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,yBAAyB,EAAE,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,EAAE,CAAC;AAC1G,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/http/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,UAAU,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/http/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,UAAU,EAAE,MAAM,IAAI,CAAC;AAoB3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAQlD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAmB/D,mGAAmG;AACnG,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI,CAQvF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,OAAO,EAC3E,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,cAAc,EACtB,EAAE,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,cAAc,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAClE,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAA;CAAO,GAC9B,OAAO,CAAC,CAAC,CAAC,CAOZ;AAsDD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,YAAY,CAmMvE"}
|
package/dist/http/handlers.js
CHANGED
|
@@ -3,7 +3,7 @@ import { revokeSession } from '../revoke-session.js';
|
|
|
3
3
|
import { withSession } from '../with-session.js';
|
|
4
4
|
import { createMethodRouter } from '../methods/router.js';
|
|
5
5
|
import { AuthError, InvalidInputError, RoleNotHeldError, SessionExpiredError, SessionNotFoundError, } from '../errors.js';
|
|
6
|
-
import { OtpNotAllowedError, VerificationFailedError } from '../methods/errors.js';
|
|
6
|
+
import { EmailDomainNotVerifiedError, OtpNotAllowedError, SsoRequiredError, VerificationFailedError, } from '../methods/errors.js';
|
|
7
7
|
import { parseCookies, serializeCookie, signLoginState, verifyLoginState, } from './cookies.js';
|
|
8
8
|
const DEFAULT_SESSION_TTL = '30 days';
|
|
9
9
|
const DEFAULT_LOGIN_STATE_TTL = 600;
|
|
@@ -77,6 +77,11 @@ function toErrorResponse(err) {
|
|
|
77
77
|
return json({ error: err.message, code: err.code }, 400);
|
|
78
78
|
if (err instanceof OtpNotAllowedError)
|
|
79
79
|
return json({ error: 'OTP sign-in is not allowed', code: err.code }, 403);
|
|
80
|
+
if (err instanceof SsoRequiredError)
|
|
81
|
+
return json({ error: 'Sign in with your organization', code: err.code }, 403);
|
|
82
|
+
if (err instanceof EmailDomainNotVerifiedError) {
|
|
83
|
+
return json({ error: 'This organization has not verified that email domain', code: err.code }, 403);
|
|
84
|
+
}
|
|
80
85
|
if (err instanceof VerificationFailedError)
|
|
81
86
|
return json({ error: 'Verification failed', code: err.code }, 401);
|
|
82
87
|
if (err instanceof RoleNotHeldError)
|
|
@@ -160,12 +165,12 @@ export function createAuthHandlers(config) {
|
|
|
160
165
|
},
|
|
161
166
|
async otpInitiate(request) {
|
|
162
167
|
try {
|
|
163
|
-
|
|
164
|
-
if (
|
|
168
|
+
// Sign-in happens on a tenant's sub-domain; an unknown one is a 404.
|
|
169
|
+
if ((await resolveTenantId(request)) === null)
|
|
165
170
|
return json({ error: 'unknown tenant' }, 404);
|
|
166
171
|
const body = await readJson(request);
|
|
167
172
|
const identifier = requireString(body, 'identifier');
|
|
168
|
-
const result = await router.initiateOtp({
|
|
173
|
+
const result = await router.initiateOtp({ identifier });
|
|
169
174
|
return json(result);
|
|
170
175
|
}
|
|
171
176
|
catch (err) {
|
|
@@ -174,13 +179,12 @@ export function createAuthHandlers(config) {
|
|
|
174
179
|
},
|
|
175
180
|
async otpComplete(request) {
|
|
176
181
|
try {
|
|
177
|
-
|
|
178
|
-
if (tenantId === null)
|
|
182
|
+
if ((await resolveTenantId(request)) === null)
|
|
179
183
|
return json({ error: 'unknown tenant' }, 404);
|
|
180
184
|
const body = await readJson(request);
|
|
181
185
|
const identifier = requireString(body, 'identifier');
|
|
182
186
|
const credential = requireString(body, 'credential');
|
|
183
|
-
const user = await router.completeOtp({
|
|
187
|
+
const user = await router.completeOtp({ identifier, credential });
|
|
184
188
|
const cookie = await mintSessionCookie(request, user);
|
|
185
189
|
const returnTo = sanitizeReturnTo(typeof body.returnTo === 'string' ? body.returnTo : undefined);
|
|
186
190
|
const res = json({ ok: true, returnTo: returnTo ?? config.returnToDefault ?? '/' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/http/handlers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAInF,OAAO,EACL,YA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AE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC5F,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { withServiceContext } from './with-service-context.js';
|
|
|
11
11
|
export { withTransaction } from '@smplcty/db';
|
|
12
12
|
export { IDENTITY_GUC, setLocal, setActorId, setSessionId, setActiveRole, setPrivileges, setIdentityContext, } from './set-helpers.js';
|
|
13
13
|
export { createMethodRouter } from './methods/router.js';
|
|
14
|
-
export { OtpNotAllowedError, VerificationFailedError } from './methods/errors.js';
|
|
14
|
+
export { EmailDomainNotVerifiedError, OtpNotAllowedError, SsoRequiredError, VerificationFailedError, } from './methods/errors.js';
|
|
15
15
|
export type { MethodHandler, MethodInitiateResult, MethodInitiateContext, MethodCompleteContext, ResolvedUser, MethodRouter, MethodRouterOptions, SignInOptions, AuthDomain, } from './methods/types.js';
|
|
16
16
|
export { verifyDevOtp, isDevOtpEnrolled, generateDevOtpSecret, getDevOtpEnrollmentUri } from './dev-otp.js';
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,SAAS,EACT,OAAO,EACP,WAAW,EACX,cAAc,EACd,eAAe,EACf,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,yBAAyB,EACzB,aAAa,EACb,MAAM,EACN,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,kB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BAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAI/D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,UAAU,GACX,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export { withTransaction } from '@smplcty/db';
|
|
|
18
18
|
export { IDENTITY_GUC, setLocal, setActorId, setSessionId, setActiveRole, setPrivileges, setIdentityContext, } from './set-helpers.js';
|
|
19
19
|
// Authentication methods — pluggable two-phase handlers + auth_domains router.
|
|
20
20
|
export { createMethodRouter } from './methods/router.js';
|
|
21
|
-
export { OtpNotAllowedError, VerificationFailedError } from './methods/errors.js';
|
|
21
|
+
export { EmailDomainNotVerifiedError, OtpNotAllowedError, SsoRequiredError, VerificationFailedError, } from './methods/errors.js';
|
|
22
22
|
// Developer OTP — for devs whose phones can't receive Twilio SMS.
|
|
23
23
|
export { verifyDevOtp, isDevOtpEnrolled, generateDevOtpSecret, getDevOtpEnrollmentUri } from './dev-otp.js';
|
|
24
24
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAmBrB,oBAAoB;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,wBAAwB;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,yEAAyE;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,sEAAsE;AACtE,2EAA2E;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,oEAAoE;AACpE,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,+EAA+E;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAmBrB,oBAAoB;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,wBAAwB;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,yEAAyE;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,sEAAsE;AACtE,2EAA2E;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,oEAAoE;AACpE,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,+EAA+E;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAa7B,kEAAkE;AAClE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Queryable } from '../types.js';
|
|
2
|
+
/** The lowercase domain of an email address, or null when it has no `@`. */
|
|
3
|
+
export declare function emailDomainOf(email: string): string | null;
|
|
4
|
+
/** Whether `tenantId` has verified `domain` (a live, verified tenant_email_domains row). */
|
|
5
|
+
export declare function tenantHasVerifiedDomain(db: Queryable, tenantId: number, domain: string): Promise<boolean>;
|
|
6
|
+
/** The first of `domains` that is verified by some tenant with SSO required, or null. */
|
|
7
|
+
export declare function ssoRequiredDomain(db: Queryable, domains: readonly string[]): Promise<string | null>;
|
|
8
|
+
/** The SSO-required domain among the user's email addresses, or null. */
|
|
9
|
+
export declare function ssoRequiredDomainForUser(db: Queryable, userId: number): Promise<string | null>;
|
|
10
|
+
//# sourceMappingURL=email-domain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-domain.d.ts","sourceRoot":"","sources":["../../src/internal/email-domain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI1D;AAYD,4FAA4F;AAC5F,wBAAsB,uBAAuB,CAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAG/G;AAwBD,yFAAyF;AACzF,wBAAsB,iBAAiB,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAIzG;AAED,yEAAyE;AACzE,wBAAsB,wBAAwB,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAMpG"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** The lowercase domain of an email address, or null when it has no `@`. */
|
|
2
|
+
export function emailDomainOf(email) {
|
|
3
|
+
const at = email.lastIndexOf('@');
|
|
4
|
+
if (at < 0 || at === email.length - 1)
|
|
5
|
+
return null;
|
|
6
|
+
return email.slice(at + 1).toLowerCase();
|
|
7
|
+
}
|
|
8
|
+
const SELECT_TENANT_VERIFIED_DOMAIN = `
|
|
9
|
+
SELECT 1
|
|
10
|
+
FROM tenant_email_domains
|
|
11
|
+
WHERE tenant_id = $1
|
|
12
|
+
AND domain = $2
|
|
13
|
+
AND verified_at IS NOT NULL
|
|
14
|
+
AND deleted_at IS NULL
|
|
15
|
+
LIMIT 1
|
|
16
|
+
`;
|
|
17
|
+
/** Whether `tenantId` has verified `domain` (a live, verified tenant_email_domains row). */
|
|
18
|
+
export async function tenantHasVerifiedDomain(db, tenantId, domain) {
|
|
19
|
+
const { rows } = await db.query(SELECT_TENANT_VERIFIED_DOMAIN, [tenantId, domain]);
|
|
20
|
+
return rows.length > 0;
|
|
21
|
+
}
|
|
22
|
+
const SELECT_SSO_REQUIRED_DOMAIN = `
|
|
23
|
+
SELECT d.domain
|
|
24
|
+
FROM tenant_email_domains d
|
|
25
|
+
WHERE d.domain = ANY ($1::text[])
|
|
26
|
+
AND d.sso_required
|
|
27
|
+
AND d.verified_at IS NOT NULL
|
|
28
|
+
AND d.deleted_at IS NULL
|
|
29
|
+
LIMIT 1
|
|
30
|
+
`;
|
|
31
|
+
// The domains of every live email address the user holds.
|
|
32
|
+
const SELECT_USER_EMAIL_DOMAINS = `
|
|
33
|
+
SELECT DISTINCT lower(substring(ucm.code FROM '@([^@]*)$')) AS domain
|
|
34
|
+
FROM user_communication_methods ucm
|
|
35
|
+
JOIN communication_channels cc
|
|
36
|
+
ON cc.communication_channel_id = ucm.communication_channel_id
|
|
37
|
+
WHERE ucm.user_id = $1
|
|
38
|
+
AND cc.name = 'email'
|
|
39
|
+
AND ucm.deleted_at IS NULL
|
|
40
|
+
AND cc.deleted_at IS NULL
|
|
41
|
+
`;
|
|
42
|
+
/** The first of `domains` that is verified by some tenant with SSO required, or null. */
|
|
43
|
+
export async function ssoRequiredDomain(db, domains) {
|
|
44
|
+
if (domains.length === 0)
|
|
45
|
+
return null;
|
|
46
|
+
const { rows } = await db.query(SELECT_SSO_REQUIRED_DOMAIN, [domains]);
|
|
47
|
+
return rows[0]?.domain ?? null;
|
|
48
|
+
}
|
|
49
|
+
/** The SSO-required domain among the user's email addresses, or null. */
|
|
50
|
+
export async function ssoRequiredDomainForUser(db, userId) {
|
|
51
|
+
const { rows } = await db.query(SELECT_USER_EMAIL_DOMAINS, [userId]);
|
|
52
|
+
return ssoRequiredDomain(db, rows.map((r) => r.domain).filter((d) => !!d));
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=email-domain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-domain.js","sourceRoot":"","sources":["../../src/internal/email-domain.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,EAAE,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACnD,OAAO,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AAC3C,CAAC;AAED,MAAM,6BAA6B,GAAG;;;;;;;;CAQrC,CAAC;AAEF,4FAA4F;AAC5F,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,EAAa,EAAE,QAAgB,EAAE,MAAc;IAC3F,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,6BAA6B,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;IACnF,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,0BAA0B,GAAG;;;;;;;;CAQlC,CAAC;AAEF,0DAA0D;AAC1D,MAAM,yBAAyB,GAAG;;;;;;;;;CASjC,CAAC;AAEF,yFAAyF;AACzF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,EAAa,EAAE,OAA0B;IAC/E,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,KAAK,CAAqB,0BAA0B,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3F,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,IAAI,CAAC;AACjC,CAAC;AAED,yEAAyE;AACzE,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,EAAa,EAAE,MAAc;IAC1E,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,KAAK,CAA4B,yBAAyB,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAChG,OAAO,iBAAiB,CACtB,EAAE,EACF,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAC1D,CAAC;AACJ,CAAC"}
|
package/dist/methods/errors.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { AuthError } from '../errors.js';
|
|
2
2
|
/**
|
|
3
|
-
* Thrown when OTP (user-bound) sign-in is attempted
|
|
4
|
-
*
|
|
5
|
-
* crafted request can't bypass a hidden UI button.
|
|
3
|
+
* Thrown when OTP (user-bound) sign-in is attempted but the router has no OTP
|
|
4
|
+
* handler configured — an SSO-only product.
|
|
6
5
|
*/
|
|
7
6
|
export declare class OtpNotAllowedError extends AuthError {
|
|
8
7
|
readonly name = "OtpNotAllowedError";
|
|
9
8
|
readonly code: 'OTP_NOT_ALLOWED';
|
|
10
|
-
|
|
11
|
-
constructor(tenantId: number, message?: string);
|
|
9
|
+
constructor(message?: string);
|
|
12
10
|
}
|
|
13
11
|
/**
|
|
14
12
|
* Thrown by a handler's `complete` when the submitted credential fails
|
|
@@ -20,4 +18,28 @@ export declare class VerificationFailedError extends AuthError {
|
|
|
20
18
|
readonly code: 'VERIFICATION_FAILED';
|
|
21
19
|
constructor(message?: string);
|
|
22
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Thrown by the OIDC handler when the IdP asserts an email address at a domain
|
|
23
|
+
* the auth domain's tenant has not verified (`tenant_email_domains`). An IdP is
|
|
24
|
+
* trusted only for the domains its tenant has proven it owns, so a tenant admin
|
|
25
|
+
* can't use their own IdP to sign in as someone else's user.
|
|
26
|
+
*/
|
|
27
|
+
export declare class EmailDomainNotVerifiedError extends AuthError {
|
|
28
|
+
readonly name = "EmailDomainNotVerifiedError";
|
|
29
|
+
readonly code: 'EMAIL_DOMAIN_NOT_VERIFIED';
|
|
30
|
+
readonly tenantId: number;
|
|
31
|
+
readonly domain: string;
|
|
32
|
+
constructor(tenantId: number, domain: string, message?: string);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Thrown by the router's OTP path when the email address, or an email address
|
|
36
|
+
* of the user being signed in, is at a verified domain that requires SSO. That
|
|
37
|
+
* user must sign in through their organization's IdP, on any sub-domain.
|
|
38
|
+
*/
|
|
39
|
+
export declare class SsoRequiredError extends AuthError {
|
|
40
|
+
readonly name = "SsoRequiredError";
|
|
41
|
+
readonly code: 'SSO_REQUIRED';
|
|
42
|
+
readonly domain: string;
|
|
43
|
+
constructor(domain: string, message?: string);
|
|
44
|
+
}
|
|
23
45
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/methods/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/methods/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,SAAS;IAC/C,SAAkB,IAAI,wBAAwB;IAC9C,SAAkB,IAAI,EAAG,iBAAiB,CAAU;IAEpD,YAAY,OAAO,GAAE,MAAqC,EAEzD;CACF;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,SAAS;IACpD,SAAkB,IAAI,6BAA6B;IACnD,SAAkB,IAAI,EAAG,qBAAqB,CAAU;IAExD,YAAY,OAAO,GAAE,MAA8B,EAElD;CACF;AAED;;;;;GAKG;AACH,qBAAa,2BAA4B,SAAQ,SAAS;IACxD,SAAkB,IAAI,iCAAiC;IACvD,SAAkB,IAAI,EAAG,2BAA2B,CAAU;IAC9D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,YAAY,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAI7D;CACF;AAED;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,SAAkB,IAAI,sBAAsB;IAC5C,SAAkB,IAAI,EAAG,cAAc,CAAU;IACjD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,YAAY,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAG3C;CACF"}
|
package/dist/methods/errors.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { AuthError } from '../errors.js';
|
|
2
2
|
/**
|
|
3
|
-
* Thrown when OTP (user-bound) sign-in is attempted
|
|
4
|
-
*
|
|
5
|
-
* crafted request can't bypass a hidden UI button.
|
|
3
|
+
* Thrown when OTP (user-bound) sign-in is attempted but the router has no OTP
|
|
4
|
+
* handler configured — an SSO-only product.
|
|
6
5
|
*/
|
|
7
6
|
export class OtpNotAllowedError extends AuthError {
|
|
8
7
|
name = 'OtpNotAllowedError';
|
|
9
8
|
code = 'OTP_NOT_ALLOWED';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
super(message ?? `OTP sign-in is not allowed for tenant ${tenantId}`);
|
|
13
|
-
this.tenantId = tenantId;
|
|
9
|
+
constructor(message = 'OTP sign-in is not allowed') {
|
|
10
|
+
super(message);
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
13
|
/**
|
|
@@ -25,4 +22,35 @@ export class VerificationFailedError extends AuthError {
|
|
|
25
22
|
super(message);
|
|
26
23
|
}
|
|
27
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Thrown by the OIDC handler when the IdP asserts an email address at a domain
|
|
27
|
+
* the auth domain's tenant has not verified (`tenant_email_domains`). An IdP is
|
|
28
|
+
* trusted only for the domains its tenant has proven it owns, so a tenant admin
|
|
29
|
+
* can't use their own IdP to sign in as someone else's user.
|
|
30
|
+
*/
|
|
31
|
+
export class EmailDomainNotVerifiedError extends AuthError {
|
|
32
|
+
name = 'EmailDomainNotVerifiedError';
|
|
33
|
+
code = 'EMAIL_DOMAIN_NOT_VERIFIED';
|
|
34
|
+
tenantId;
|
|
35
|
+
domain;
|
|
36
|
+
constructor(tenantId, domain, message) {
|
|
37
|
+
super(message ?? `Tenant ${tenantId} has not verified the email domain ${domain}`);
|
|
38
|
+
this.tenantId = tenantId;
|
|
39
|
+
this.domain = domain;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Thrown by the router's OTP path when the email address, or an email address
|
|
44
|
+
* of the user being signed in, is at a verified domain that requires SSO. That
|
|
45
|
+
* user must sign in through their organization's IdP, on any sub-domain.
|
|
46
|
+
*/
|
|
47
|
+
export class SsoRequiredError extends AuthError {
|
|
48
|
+
name = 'SsoRequiredError';
|
|
49
|
+
code = 'SSO_REQUIRED';
|
|
50
|
+
domain;
|
|
51
|
+
constructor(domain, message) {
|
|
52
|
+
super(message ?? `Sign-in for ${domain} addresses requires SSO`);
|
|
53
|
+
this.domain = domain;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
28
56
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/methods/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/methods/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IAC7B,IAAI,GAAG,oBAAoB,CAAC;IAC5B,IAAI,GAAG,iBAA0B,CAAC;IAEpD,YAAY,OAAO,GAAW,4BAA4B;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IAClC,IAAI,GAAG,yBAAyB,CAAC;IACjC,IAAI,GAAG,qBAA8B,CAAC;IAExD,YAAY,OAAO,GAAW,qBAAqB;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,2BAA4B,SAAQ,SAAS;IACtC,IAAI,GAAG,6BAA6B,CAAC;IACrC,IAAI,GAAG,2BAAoC,CAAC;IACrD,QAAQ,CAAS;IACjB,MAAM,CAAS;IAExB,YAAY,QAAgB,EAAE,MAAc,EAAE,OAAgB;QAC5D,KAAK,CAAC,OAAO,IAAI,UAAU,QAAQ,sCAAsC,MAAM,EAAE,CAAC,CAAC;QACnF,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAC3B,IAAI,GAAG,kBAAkB,CAAC;IAC1B,IAAI,GAAG,cAAuB,CAAC;IACxC,MAAM,CAAS;IAExB,YAAY,MAAc,EAAE,OAAgB;QAC1C,KAAK,CAAC,OAAO,IAAI,eAAe,MAAM,yBAAyB,CAAC,CAAC;QACjE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/methods/oidc/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/methods/oidc/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAItC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,oGAAoG;IACpG,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,oFAAoF;IACpF,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,UAAU,EAAE,cAAc,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACxG;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;QACtB,EAAE,EAAE,SAAS,CAAC;QACd,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;QACnC,MAAM,EAAE,eAAe,CAAC;KACzB,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5B,8EAA8E;IAC9E,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,KAAK,eAAe,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,yBAAyB,CAAC,CAAC,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACxG,QAAQ,CAAC,KAAK,EAAE;QACd,EAAE,EAAE,SAAS,CAAC;QACd,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;QACnC,4EAA4E;QAC5E,WAAW,EAAE,MAAM,GAAG,GAAG,CAAC;QAC1B,UAAU,EAAE,cAAc,CAAC;KAC5B,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC3B;AA+BD,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,WAAW,CAiGzE"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as oauth from 'oauth4webapi';
|
|
2
2
|
import { InvalidInputError } from '../../errors.js';
|
|
3
3
|
import { findUserByCommunicationMethod } from '../../find-user-by-communication-method.js';
|
|
4
|
-
import {
|
|
4
|
+
import { emailDomainOf, tenantHasVerifiedDomain } from '../../internal/email-domain.js';
|
|
5
|
+
import { EmailDomainNotVerifiedError, VerificationFailedError } from '../errors.js';
|
|
5
6
|
function paramsOf(authDomain) {
|
|
6
7
|
if (authDomain.integrationType !== 'oidc') {
|
|
7
8
|
throw new InvalidInputError(`OidcHandler requires integration_type 'oidc', got '${authDomain.integrationType}'`);
|
|
@@ -90,6 +91,16 @@ export function oidcHandler(options = {}) {
|
|
|
90
91
|
if (!email) {
|
|
91
92
|
throw new VerificationFailedError('OIDC id_token has no email or preferred_username');
|
|
92
93
|
}
|
|
94
|
+
// An IdP is trusted only for the email domains its tenant has verified —
|
|
95
|
+
// checked before any lookup or provisioning, so a tenant admin's IdP can't
|
|
96
|
+
// sign in (or create) a user at someone else's domain.
|
|
97
|
+
const domain = emailDomainOf(email);
|
|
98
|
+
if (!domain) {
|
|
99
|
+
throw new VerificationFailedError('OIDC email claim is not an email address');
|
|
100
|
+
}
|
|
101
|
+
if (!(await tenantHasVerifiedDomain(db, authDomain.tenantId, domain))) {
|
|
102
|
+
throw new EmailDomainNotVerifiedError(authDomain.tenantId, domain);
|
|
103
|
+
}
|
|
93
104
|
const existing = await findUserByCommunicationMethod(db, { channel: 'email', code: email });
|
|
94
105
|
if (existing) {
|
|
95
106
|
return existing;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/methods/oidc/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,6BAA6B,EAAE,MAAM,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/methods/oidc/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,6BAA6B,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAExF,OAAO,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAqGpF,SAAS,QAAQ,CAAC,UAA2C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AkD,CAAC,CAAC;YACxF,CAAC;YAED,yEAAyE;YACzE,2EAA2E;YAC3E,uDAAuD;YACvD,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;YACpC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,uBAAuB,CAAC,0CAA0C,CAAC,CAAC;YAChF,CAAC;YACD,IAAI,CAAC,CAAC,MAAM,uBAAuB,CAAC,EAAE,EAAE,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;gBACtE,MAAM,IAAI,2BAA2B,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACrE,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,6BAA6B,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YAC5F,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,QAAQ,CAAC;YAClB,CAAC;YACD,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBAC1B,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;YAC3D,CAAC;YACD,MAAM,IAAI,uBAAuB,CAAC,4DAA4D,CAAC,CAAC;QAClG,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/methods/router.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { MethodRouter, MethodRouterOptions } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Build the tenant-centric sign-in router: **discovery** (`signInOptions`) and
|
|
4
|
-
* the **user-bound OTP path** (`initiateOtp`/`completeOtp
|
|
5
|
-
*
|
|
4
|
+
* the **user-bound OTP path** (`initiateOtp`/`completeOtp`). Code sign-in is
|
|
5
|
+
* open to everyone except addresses at a verified email domain that requires
|
|
6
|
+
* SSO (`tenant_email_domains.sso_required`) — refused here, on every
|
|
7
|
+
* sub-domain, not just hidden in the UI.
|
|
6
8
|
*
|
|
7
9
|
* OIDC is intentionally not routed here: it has a richer `authorize`/`callback`
|
|
8
10
|
* shape (PKCE + login-state) handled by `@smplcty/auth/oidc`. Resolve the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/methods/router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/methods/router.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAGV,YAAY,EACZ,mBAAmB,EAGpB,MAAM,YAAY,CAAC;AAyBpB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CA2D7E"}
|
package/dist/methods/router.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { InvalidInputError } from '../errors.js';
|
|
2
|
-
import {
|
|
2
|
+
import { emailDomainOf, ssoRequiredDomain, ssoRequiredDomainForUser } from '../internal/email-domain.js';
|
|
3
|
+
import { OtpNotAllowedError, SsoRequiredError } from './errors.js';
|
|
3
4
|
const SELECT_TENANT_BY_SLUG = `
|
|
4
|
-
SELECT tenant_id AS "tenantId"
|
|
5
|
+
SELECT tenant_id AS "tenantId"
|
|
5
6
|
FROM tenants
|
|
6
7
|
WHERE slug = $1 AND deleted_at IS NULL
|
|
7
8
|
LIMIT 1
|
|
8
9
|
`;
|
|
9
|
-
const SELECT_ALLOW_OTP = `
|
|
10
|
-
SELECT allow_otp AS "allowOtp"
|
|
11
|
-
FROM tenants
|
|
12
|
-
WHERE tenant_id = $1 AND deleted_at IS NULL
|
|
13
|
-
LIMIT 1
|
|
14
|
-
`;
|
|
15
10
|
const SELECT_AUTH_DOMAINS_BY_TENANT = `
|
|
16
11
|
SELECT
|
|
17
12
|
auth_domain_id AS "authDomainId",
|
|
@@ -25,8 +20,10 @@ const SELECT_AUTH_DOMAINS_BY_TENANT = `
|
|
|
25
20
|
`;
|
|
26
21
|
/**
|
|
27
22
|
* Build the tenant-centric sign-in router: **discovery** (`signInOptions`) and
|
|
28
|
-
* the **user-bound OTP path** (`initiateOtp`/`completeOtp
|
|
29
|
-
*
|
|
23
|
+
* the **user-bound OTP path** (`initiateOtp`/`completeOtp`). Code sign-in is
|
|
24
|
+
* open to everyone except addresses at a verified email domain that requires
|
|
25
|
+
* SSO (`tenant_email_domains.sso_required`) — refused here, on every
|
|
26
|
+
* sub-domain, not just hidden in the UI.
|
|
30
27
|
*
|
|
31
28
|
* OIDC is intentionally not routed here: it has a richer `authorize`/`callback`
|
|
32
29
|
* shape (PKCE + login-state) handled by `@smplcty/auth/oidc`. Resolve the
|
|
@@ -42,19 +39,10 @@ const SELECT_AUTH_DOMAINS_BY_TENANT = `
|
|
|
42
39
|
export function createMethodRouter(options) {
|
|
43
40
|
const { otpHandler } = options;
|
|
44
41
|
const q = options.db;
|
|
45
|
-
|
|
46
|
-
if (!
|
|
47
|
-
throw new
|
|
48
|
-
|
|
49
|
-
if (!otpHandler) {
|
|
50
|
-
throw new OtpNotAllowedError(tenantId, 'No OTP handler is configured');
|
|
51
|
-
}
|
|
52
|
-
const { rows } = await q.query(SELECT_ALLOW_OTP, [tenantId]);
|
|
53
|
-
const row = rows[0];
|
|
54
|
-
// Unknown tenant or allow_otp=false both deny — fail closed.
|
|
55
|
-
if (!row || row.allowOtp !== true) {
|
|
56
|
-
throw new OtpNotAllowedError(tenantId);
|
|
57
|
-
}
|
|
42
|
+
function requireOtpHandler() {
|
|
43
|
+
if (!otpHandler)
|
|
44
|
+
throw new OtpNotAllowedError('No OTP handler is configured');
|
|
45
|
+
return otpHandler;
|
|
58
46
|
}
|
|
59
47
|
return {
|
|
60
48
|
async signInOptions({ tenantSlug }) {
|
|
@@ -75,25 +63,35 @@ export function createMethodRouter(options) {
|
|
|
75
63
|
authDomainId: Number(d.authDomainId),
|
|
76
64
|
tenantId: Number(d.tenantId),
|
|
77
65
|
})),
|
|
78
|
-
otpAllowed:
|
|
66
|
+
otpAllowed: !!otpHandler,
|
|
79
67
|
};
|
|
80
68
|
},
|
|
81
|
-
async initiateOtp({
|
|
69
|
+
async initiateOtp({ identifier }) {
|
|
82
70
|
if (typeof identifier !== 'string' || identifier.length === 0) {
|
|
83
71
|
throw new InvalidInputError('identifier must be a non-empty string');
|
|
84
72
|
}
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
const handler = requireOtpHandler();
|
|
74
|
+
// Don't send a code to an address that could never use it.
|
|
75
|
+
const domain = emailDomainOf(identifier);
|
|
76
|
+
const required = domain ? await ssoRequiredDomain(q, [domain]) : null;
|
|
77
|
+
if (required)
|
|
78
|
+
throw new SsoRequiredError(required);
|
|
79
|
+
return handler.initiate({ db: options.db, identifier });
|
|
87
80
|
},
|
|
88
|
-
async completeOtp({
|
|
81
|
+
async completeOtp({ identifier, credential }) {
|
|
89
82
|
if (typeof identifier !== 'string' || identifier.length === 0) {
|
|
90
83
|
throw new InvalidInputError('identifier must be a non-empty string');
|
|
91
84
|
}
|
|
92
85
|
if (typeof credential !== 'string' || credential.length === 0) {
|
|
93
86
|
throw new InvalidInputError('credential must be a non-empty string');
|
|
94
87
|
}
|
|
95
|
-
await
|
|
96
|
-
|
|
88
|
+
const user = await requireOtpHandler().complete({ db: options.db, identifier, credential });
|
|
89
|
+
// Checked on the resolved user, not just the identifier: someone whose
|
|
90
|
+
// email is at an SSO-required domain can't sign in by phone either.
|
|
91
|
+
const required = await ssoRequiredDomainForUser(q, user.userId);
|
|
92
|
+
if (required)
|
|
93
|
+
throw new SsoRequiredError(required);
|
|
94
|
+
return user;
|
|
97
95
|
},
|
|
98
96
|
};
|
|
99
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/methods/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file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IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC9D,MAAM,IAAI,iBAAiB,CAAC,uCAAuC,CAAC,CAAC;YACvE,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,iBAAiB,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;YAC5F,uEAAuE;YACvE,oEAAoE;YACpE,MAAM,QAAQ,GAAG,MAAM,wBAAwB,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAChE,IAAI,QAAQ;gBAAE,MAAM,IAAI,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YACnD,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/methods/types.d.ts
CHANGED
|
@@ -62,8 +62,8 @@ export interface MethodHandler {
|
|
|
62
62
|
export interface MethodRouterOptions {
|
|
63
63
|
/** Used to look up tenants and their `auth_domains`. */
|
|
64
64
|
db: Queryable;
|
|
65
|
-
/** The user-bound OTP handler (e.g. a `TwilioVerifyHandler`).
|
|
66
|
-
*
|
|
65
|
+
/** The user-bound OTP handler (e.g. a `TwilioVerifyHandler`). Omit it for an
|
|
66
|
+
* SSO-only product. */
|
|
67
67
|
otpHandler?: MethodHandler;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
@@ -78,7 +78,8 @@ export interface SignInOptions {
|
|
|
78
78
|
* This list is discovery ("here are your IdPs"), not a guarantee every row is
|
|
79
79
|
* startable. */
|
|
80
80
|
readonly authDomains: readonly AuthDomain[];
|
|
81
|
-
/** Whether to offer OTP:
|
|
81
|
+
/** Whether to offer OTP: an `otpHandler` is configured. (Addresses at an
|
|
82
|
+
* SSO-required verified domain are still refused, per address.) */
|
|
82
83
|
readonly otpAllowed: boolean;
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
@@ -93,16 +94,16 @@ export interface MethodRouter {
|
|
|
93
94
|
signInOptions(input: {
|
|
94
95
|
tenantSlug: string;
|
|
95
96
|
}): Promise<SignInOptions | null>;
|
|
96
|
-
/** User-bound (OTP) phase 1. Throws {@link OtpNotAllowedError} when
|
|
97
|
-
*
|
|
97
|
+
/** User-bound (OTP) phase 1. Throws {@link OtpNotAllowedError} when no OTP
|
|
98
|
+
* handler is configured, {@link SsoRequiredError} for an address at an
|
|
99
|
+
* SSO-required verified domain. */
|
|
98
100
|
initiateOtp(input: {
|
|
99
|
-
tenantId: number;
|
|
100
101
|
identifier: string;
|
|
101
102
|
}): Promise<MethodInitiateResult>;
|
|
102
|
-
/** User-bound (OTP) phase 2. Throws {@link OtpNotAllowedError} when
|
|
103
|
-
*
|
|
103
|
+
/** User-bound (OTP) phase 2. Throws {@link OtpNotAllowedError} when no OTP
|
|
104
|
+
* handler is configured, {@link SsoRequiredError} when the signed-in user has
|
|
105
|
+
* an address at an SSO-required verified domain. */
|
|
104
106
|
completeOtp(input: {
|
|
105
|
-
tenantId: number;
|
|
106
107
|
identifier: string;
|
|
107
108
|
credential: string;
|
|
108
109
|
}): Promise<ResolvedUser>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/methods/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,wEAAwE;IACxE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,yCAAyC;IACzC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,yCAAyC;IACzC,QAAQ,CAAC,iBAAiB,EAA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U,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;IAC5E;;wCAEoC;IACpC,WAAW,CAAC,KAAK,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC1E;;yDAEqD;IACrD,WAAW,CAAC,KAAK,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACvF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smplcty/auth",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.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",
|
|
@@ -27,6 +27,11 @@
|
|
|
27
27
|
"import": "./dist/scope/flat-tenant.js",
|
|
28
28
|
"default": "./dist/scope/flat-tenant.js"
|
|
29
29
|
},
|
|
30
|
+
"./email-domains": {
|
|
31
|
+
"types": "./dist/email-domains/index.d.ts",
|
|
32
|
+
"import": "./dist/email-domains/index.js",
|
|
33
|
+
"default": "./dist/email-domains/index.js"
|
|
34
|
+
},
|
|
30
35
|
"./http": {
|
|
31
36
|
"types": "./dist/http/index.d.ts",
|
|
32
37
|
"import": "./dist/http/index.js",
|
|
@@ -105,7 +110,7 @@
|
|
|
105
110
|
},
|
|
106
111
|
"devDependencies": {
|
|
107
112
|
"@release-it/keep-a-changelog": "^8.0.1",
|
|
108
|
-
"@smplcty/schema-flow": "^0.
|
|
113
|
+
"@smplcty/schema-flow": "^0.24.0",
|
|
109
114
|
"@smplcty/twilio": "^0.1.1",
|
|
110
115
|
"@testcontainers/postgresql": "^12.2.0",
|
|
111
116
|
"@types/node": "^22.20.5",
|
|
@@ -116,11 +121,11 @@
|
|
|
116
121
|
"oauth4webapi": "^3.8.8",
|
|
117
122
|
"oxlint": "^1.87.0",
|
|
118
123
|
"pg": "^8.23.1",
|
|
119
|
-
"prettier": "^3.9.
|
|
120
|
-
"release-it": "^21.1.
|
|
124
|
+
"prettier": "^3.9.10",
|
|
125
|
+
"release-it": "^21.1.1",
|
|
121
126
|
"typescript": "^7.0.2",
|
|
122
|
-
"vite": "^8.3.
|
|
123
|
-
"vitest": "^5.0.
|
|
127
|
+
"vite": "^8.3.4",
|
|
128
|
+
"vitest": "^5.0.4"
|
|
124
129
|
},
|
|
125
130
|
"dependencies": {
|
|
126
131
|
"@smplcty/db": "^4.3.0",
|
|
@@ -4,7 +4,7 @@ volatility: stable
|
|
|
4
4
|
parallel: restricted
|
|
5
5
|
security: definer
|
|
6
6
|
set:
|
|
7
|
-
search_path: pg_catalog, public
|
|
7
|
+
search_path: pg_catalog, public, pg_temp
|
|
8
8
|
# True when the current actor holds any live wildcard role — a user_roles row
|
|
9
9
|
# with tenant_id IS NULL, which reaches every tenant (surfaced elsewhere as the
|
|
10
10
|
# app.all_tenants GUC). The all-access companion to auth_tenant_ids: a wildcard
|
|
@@ -4,7 +4,7 @@ volatility: stable
|
|
|
4
4
|
parallel: restricted
|
|
5
5
|
security: definer
|
|
6
6
|
set:
|
|
7
|
-
search_path: pg_catalog, public
|
|
7
|
+
search_path: pg_catalog, public, pg_temp
|
|
8
8
|
# True when the current actor is a security admin for at least one tenant the
|
|
9
9
|
# target user holds a role in — i.e. they share a tenant where the actor holds
|
|
10
10
|
# `security`. This is the "a security admin manages the users in their tenants"
|
|
@@ -2,7 +2,7 @@ name: auth_create_user
|
|
|
2
2
|
language: plpgsql
|
|
3
3
|
security: definer
|
|
4
4
|
set:
|
|
5
|
-
search_path: pg_catalog, public
|
|
5
|
+
search_path: pg_catalog, public, pg_temp
|
|
6
6
|
# The authority-checked, atomic way for an app_rls request (a security admin) to
|
|
7
7
|
# provision a human user. Raw INSERT on `users` is closed under RLS — a user
|
|
8
8
|
# must never exist without the roles and contact methods that make it usable,
|
|
@@ -4,7 +4,7 @@ volatility: stable
|
|
|
4
4
|
parallel: restricted
|
|
5
5
|
security: definer
|
|
6
6
|
set:
|
|
7
|
-
search_path: pg_catalog, public
|
|
7
|
+
search_path: pg_catalog, public, pg_temp
|
|
8
8
|
# True when the current request actor holds `role_name` with authority over
|
|
9
9
|
# `target_tenant_id`. A wildcard assignment (user_roles.tenant_id IS NULL)
|
|
10
10
|
# reaches every tenant, so it always qualifies. Passing a NULL target means
|
|
@@ -4,7 +4,7 @@ volatility: stable
|
|
|
4
4
|
parallel: restricted
|
|
5
5
|
security: definer
|
|
6
6
|
set:
|
|
7
|
-
search_path: pg_catalog, public
|
|
7
|
+
search_path: pg_catalog, public, pg_temp
|
|
8
8
|
# True when the current actor holds ANY role reaching `target_tenant_id`
|
|
9
9
|
# (directly or via a wildcard assignment). Used where visibility is granted to
|
|
10
10
|
# every member of a tenant regardless of which role they hold — e.g. a tenant
|
|
@@ -4,7 +4,7 @@ volatility: stable
|
|
|
4
4
|
parallel: restricted
|
|
5
5
|
security: definer
|
|
6
6
|
set:
|
|
7
|
-
search_path: pg_catalog, public
|
|
7
|
+
search_path: pg_catalog, public, pg_temp
|
|
8
8
|
# The set of tenant ids the current actor holds a live, tenant-scoped role in
|
|
9
9
|
# (wildcard grants — user_roles.tenant_id IS NULL — are NOT in this set; test
|
|
10
10
|
# them with auth_all_tenants()). Returns nothing when there is no actor.
|
|
@@ -3,7 +3,7 @@ language: plpgsql
|
|
|
3
3
|
volatility: stable
|
|
4
4
|
security: definer
|
|
5
5
|
set:
|
|
6
|
-
search_path: pg_catalog, public
|
|
6
|
+
search_path: pg_catalog, public, pg_temp
|
|
7
7
|
# A PURE resolver. Given a session token hash, it returns the session's
|
|
8
8
|
# user, its expiry, the user's selectable roles (split from privileges by
|
|
9
9
|
# roles.is_privilege), and the user's privileges. It takes NO role
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
table: tenant_email_domains
|
|
2
|
+
# The email domains a tenant has claimed, and whether it has proven it owns
|
|
3
|
+
# them. An auth domain (a tenant's IdP) authenticates only email addresses at
|
|
4
|
+
# its tenant's VERIFIED domains — a tenant admin's IdP can assert any address,
|
|
5
|
+
# so without this one tenant could sign in as any user in the system. A domain
|
|
6
|
+
# is verified by publishing verification_token in a DNS TXT record (see
|
|
7
|
+
# @smplcty/auth/email-domains), or by a global admin through the privileged
|
|
8
|
+
# pool for a customer who can't edit DNS.
|
|
9
|
+
#
|
|
10
|
+
# sso_required: once verified, code (OTP) sign-in is refused for every email
|
|
11
|
+
# address at the domain, on every sub-domain — the tenant's users must come in
|
|
12
|
+
# through SSO. Outsiders (addresses at other domains) are unaffected.
|
|
13
|
+
mixins: [audit, soft_delete]
|
|
14
|
+
# Grants. The verified state is the security boundary, so app_rls gets column
|
|
15
|
+
# grants that leave it out: a tenant admin can claim a domain, toggle
|
|
16
|
+
# sso_required and remove (soft-delete) a row, but can never write
|
|
17
|
+
# verification_token (server-generated, so it can't be copied from another
|
|
18
|
+
# tenant's public TXT record) or verified_at (written only after a DNS check,
|
|
19
|
+
# or by a global admin, both through app_privileged). domain and tenant_id are
|
|
20
|
+
# not updatable either, so a verified row can't be pointed somewhere else.
|
|
21
|
+
grants:
|
|
22
|
+
- to: app_rls
|
|
23
|
+
privileges: [SELECT]
|
|
24
|
+
- to: app_rls
|
|
25
|
+
privileges: [INSERT]
|
|
26
|
+
columns: [tenant_id, domain, sso_required]
|
|
27
|
+
- to: app_rls
|
|
28
|
+
privileges: [UPDATE]
|
|
29
|
+
columns: [sso_required, deleted_at]
|
|
30
|
+
- to: app_privileged
|
|
31
|
+
privileges: [UPDATE]
|
|
32
|
+
columns: [verified_at]
|
|
33
|
+
columns:
|
|
34
|
+
- name: tenant_email_domain_id
|
|
35
|
+
type: bigserial
|
|
36
|
+
primary_key: true
|
|
37
|
+
- name: tenant_id
|
|
38
|
+
type: bigint
|
|
39
|
+
nullable: false
|
|
40
|
+
references:
|
|
41
|
+
table: tenants
|
|
42
|
+
column: tenant_id
|
|
43
|
+
# Lowercase, exact match: acme.com does not cover eu.acme.com.
|
|
44
|
+
- name: domain
|
|
45
|
+
type: text
|
|
46
|
+
nullable: false
|
|
47
|
+
# Per row, so a token issued to one tenant never verifies the domain for
|
|
48
|
+
# another — even if both claim it.
|
|
49
|
+
- name: verification_token
|
|
50
|
+
type: text
|
|
51
|
+
nullable: false
|
|
52
|
+
default: "replace(gen_random_uuid()::text, '-', '')"
|
|
53
|
+
- name: verified_at
|
|
54
|
+
type: timestamptz
|
|
55
|
+
- name: sso_required
|
|
56
|
+
type: boolean
|
|
57
|
+
nullable: false
|
|
58
|
+
default: 'false'
|
|
59
|
+
checks:
|
|
60
|
+
- name: tenant_email_domains_domain_check
|
|
61
|
+
expression: "domain ~ '^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9-]{2,63}$'"
|
|
62
|
+
indexes:
|
|
63
|
+
- columns: [tenant_id, domain]
|
|
64
|
+
unique: true
|
|
65
|
+
where: 'deleted_at IS NULL'
|
|
66
|
+
name: tenant_email_domains_tenant_domain_key
|
|
67
|
+
# The sign-in checks look a domain up across tenants.
|
|
68
|
+
- columns: [domain]
|
|
69
|
+
where: 'verified_at IS NOT NULL AND deleted_at IS NULL'
|
|
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.
|
|
74
|
+
rls: true
|
|
75
|
+
policies:
|
|
76
|
+
- name: tenant_email_domains_settings
|
|
77
|
+
for: ALL
|
|
78
|
+
to: app_rls
|
|
79
|
+
permissive: true
|
|
80
|
+
using: auth_has_role('settings', tenant_email_domains.tenant_id)
|
|
81
|
+
check: auth_has_role('settings', tenant_email_domains.tenant_id)
|
|
@@ -17,14 +17,6 @@ columns:
|
|
|
17
17
|
# Nullable: multitenancy (and sub-domains) are optional for simple apps.
|
|
18
18
|
- name: slug
|
|
19
19
|
type: text
|
|
20
|
-
# Whether user-bound OTP (Twilio) sign-in is allowed for this tenant.
|
|
21
|
-
# Irrelevant when the tenant has no auth_domain (OTP is the only way);
|
|
22
|
-
# set false to enforce SSO-only on a tenant that has OIDC. Enforced in the
|
|
23
|
-
# router, not just the UI.
|
|
24
|
-
- name: allow_otp
|
|
25
|
-
type: boolean
|
|
26
|
-
nullable: false
|
|
27
|
-
default: true
|
|
28
20
|
checks:
|
|
29
21
|
# The slug IS the sub-domain (acme.app.com), so it must be a valid DNS label:
|
|
30
22
|
# lowercase alphanumerics and internal hyphens, no leading/trailing hyphen. An
|
|
@@ -32,7 +32,10 @@ columns:
|
|
|
32
32
|
nullable: true
|
|
33
33
|
indexes:
|
|
34
34
|
# Partial so a (channel, code) can be reused after the row is soft-deleted.
|
|
35
|
-
|
|
35
|
+
# Keyed on lower(code): codes are stored as entered but matched in any casing
|
|
36
|
+
# (findUserByCommunicationMethod), so two live codes differing only by case
|
|
37
|
+
# would make that lookup ambiguous. This index also backs the lookup.
|
|
38
|
+
- columns: [communication_channel_id, { expression: lower(code) }]
|
|
36
39
|
unique: true
|
|
37
40
|
where: 'deleted_at IS NULL'
|
|
38
41
|
name: user_communication_methods_channel_code_key
|