@dokebi/oauth 0.1.4 → 0.1.5

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 (3) hide show
  1. package/AI.md +4 -3
  2. package/dist/plugin.js +37 -18
  3. package/package.json +7 -7
package/AI.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AI guide — @dokebi/oauth
2
2
 
3
- An **OAuth 2.1 authorization server** for @dokebi/web apps, on @dokebi/auth's opaque tokens (`dkb_…`, stored as sha256, revocable at once — no JWT): authorization code with **PKCE S256** (required), refresh tokens with rotation and reuse detection, revocation (RFC 7009), authorization server metadata (RFC 8414, derived from the options), protected resource metadata (RFC 9728), resource indicators (RFC 8707, **required**), the callback `iss` (RFC 9207), client ID metadata documents (CIMD, on by default), pre-registered clients and optional dynamic registration (RFC 7591, closed by default). Routes of the same app become protected resources with `config: { oauth: { resource, scopes? } }`. The consent page is the application's (`renderConsent` in `src/infra/oauth/extension.ts`). Node >=24.0.0, core ^0.4.2, @dokebi/web ^0.4.3, @dokebi/auth ^0.4.1 and @dokebi/session ^0.4.4 (required), @dokebi/csrf (recommended), @dokebi/db or @dokebi/redis (stores), @dokebi/rate-limit (optional). The design is [D-0091](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0091-oauth-authorization-server.md); the human-oriented description is the [README](README.md).
3
+ An **OAuth 2.1 authorization server** for @dokebi/web apps, on @dokebi/auth's opaque tokens (`dkb_…`, stored as sha256, revocable at once — no JWT): authorization code with **PKCE S256** (required), refresh tokens with rotation and reuse detection, revocation (RFC 7009), authorization server metadata (RFC 8414, derived from the options), protected resource metadata (RFC 9728), resource indicators (RFC 8707, **required**), the callback `iss` (RFC 9207), client ID metadata documents (CIMD, on by default), pre-registered clients and optional dynamic registration (RFC 7591, closed by default). Routes of the same app become protected resources with `config: { oauth: { resource, scopes? } }`. The consent page is the application's (`renderConsent` in `src/infra/oauth/extension.ts`). Node >=24.0.0, core ^0.4.2, @dokebi/web ^0.4.23, @dokebi/auth ^0.4.1 and @dokebi/session ^0.4.4 (required), @dokebi/csrf (recommended), @dokebi/db or @dokebi/redis (stores), @dokebi/rate-limit (optional). The design is [D-0091](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0091-oauth-authorization-server.md); the human-oriented description is the [README](README.md).
4
4
 
5
5
  Not provided: OpenID Connect (no `id_token`, userinfo or `/.well-known/openid-configuration` — offering it makes clients expect an id_token), the implicit, password, client_credentials and device grants, token introspection, JWT access tokens, `private_key_jwt`.
6
6
 
@@ -108,7 +108,7 @@ The `defineOptions` declaration in `src/options.ts` is the parser; the build wri
108
108
  | `POST /oauth/revoke` | RFC 7009: a token of this server and this client revokes its whole grant; an unknown token or another client's token answers the same 200 and revokes nothing |
109
109
  | `POST /oauth/register` | RFC 7591 when `registration: open` (public clients only); closed: 404 `{ error: "invalid_request", … }` |
110
110
 
111
- **Hosts (D-0132).** Without `app` every endpoint answers on every host the server receives. In a project split into apps by host, `app` binds the authorization server (metadata, authorize with the consent page and its decision, token, revoke, register) to the issuer's app, and `resources.<id>.app` binds each resource's protected resource metadata to the app of its URI (RFC 9728 §3: the metadata lives at the origin of the resource identifier; RFC 8414 §3: the server metadata at the issuer's). Other hosts get the 404 of an unknown route. A resource without its own `app` follows `app`; resources on several apps get one pair of metadata routes per app, each serving only that app's resources (and those bound nowhere). The metadata itself never depends on the request host: `issuer`, the endpoints (`issuer` + path) and `authorization_servers` come from `issuer`, `resource` and the `resource_metadata` of the 401 challenge from the resource `uri`, so split hosts stay correct. At boot each published URL is checked against its apps: the issuer or a resource URI on a domain of another app fails the start (`INVALID_OPTIONS` naming the option to set), a host no domain names is warned (`OAUTH_HOST_UNMAPPED`, `where`, `host`, `apps`: a proxy may send another Host). The sign-in page is the app's own route (put it on the issuer's app). Example:
111
+ **Hosts (D-0132).** Without `app` every endpoint answers on every host the server receives. In a project split into apps by host, `app` binds the authorization server (metadata, authorize with the consent page and its decision, token, revoke, register) to the issuer's app, and `resources.<id>.app` binds each resource's protected resource metadata to the app of its URI (RFC 9728 §3: the metadata lives at the origin of the resource identifier; RFC 8414 §3: the server metadata at the issuer's). Other hosts get the 404 of an unknown route. A resource without its own `app` follows `app`; resources on several apps get one pair of metadata routes per app, each serving only that app's resources (and those bound nowhere). The metadata itself never depends on the request host: `issuer`, the endpoints (`issuer` + path) and `authorization_servers` come from `issuer`, `resource` and the `resource_metadata` of the 401 challenge from the resource `uri`, so split hosts stay correct. At boot each published URL is checked against its apps: the issuer or a resource URI on a domain of another app fails the start (`INVALID_OPTIONS` naming the option to set), a host no domain names is warned (`OAUTH_HOST_UNMAPPED`, `where`, `host`, `apps`: a proxy may send another Host). When a module gives @dokebi/app its domains (a domain provider, read in dokebi-app's start), the "no domain names it" part waits for the provider's first load (0.1.5, [D-0266](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0266-host-checks-after-provider-load.md)): a host only the table names is not warned, a host neither dokebi.yaml nor the table names is warned once, and a row that puts the issuer or a resource URI on another app is error `OAUTH_HOST_OTHER_APP` (the app keeps running; clients reach a 404 at that URL until the table or `app` is fixed). The sign-in page is the app's own route (put it on the issuer's app). Example:
112
112
 
113
113
  ```yaml
114
114
  dokebi-oauth:
@@ -444,7 +444,8 @@ Never in a log line: tokens, codes, verifiers, states, secrets, cookies (tests s
444
444
  | warn | `OAUTH_STORE_FULL` | `store`, `operation`, `limit`, `max` (repeats counted) |
445
445
  | warn | `OAUTH_CSRF_MISSING` | `fix` (once at start, without @dokebi/csrf) |
446
446
  | warn | `OAUTH_DECIDE_NOT_ATOMIC` | `fix`, `error` (once: the session store has no one-use values, §5) |
447
- | warn | `OAUTH_HOST_UNMAPPED` | `where` (`dokebi-oauth.issuer` or `dokebi-oauth.resources.<id>.uri`), `url`, `host`, `apps`, `unknownDomain`, `fix` (at boot, when bound: no domain of dokebi-app names that host, D-0132) |
447
+ | warn | `OAUTH_HOST_UNMAPPED` | `where` (`dokebi-oauth.issuer` or `dokebi-oauth.resources.<id>.uri`), `url`, `host`, `apps`, `unknownDomain`, `fix` (at boot, when bound: no domain of dokebi-app names that host, D-0132; with a module's domain provider after its first load, D-0266) |
448
+ | error | `OAUTH_HOST_OTHER_APP` | `where`, `url`, `host`, `hostApp`, `apps`, `fix` (0.1.5, after the first load of a module's domain provider: a row of the provider put that host on another app, D-0266; the same in dokebi.yaml fails the start) |
448
449
  | error | `OAUTH_STORE_FAILED` · `OAUTH_HOOK_FAILED` · `OAUTH_TOUCH_FAILED` · `OAUTH_STORE_CLOSE_FAILED` · `OAUTH_LIVE_CHECK_FAILED` | the full `error`; `store`, `operation`, `hook` or `resource` (a live check whose grant read or hook threw: the connection ends; repeats counted) |
449
450
  | debug | `OAuth authorize refused` | `reason` (`repeated`, `encoding`, `unknown`, `document`, `redirect_uri`, an RFC code, `canDelegate`), `client` |
450
451
  | debug | `OAuth authorize: re-authentication first` · `OAuth authorize: fresh sign-in first` · `OAuth authorize: fresh authentication seen` | `client`, `reason` (`prompt`, `max_age`, `again`) |
package/dist/plugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { addExtensionDependencies, createExtension, definePlugin, definePoint, optionalDependency, providerDependency, readExtensionEntry, } from '@dokebi/core';
3
3
  import { diagnostics } from '@dokebi/core/libraries';
4
- import { appUrlMatch, pluginRouteIds } from '@dokebi/web/points';
4
+ import { afterAppDomains, appUrlMatch, pluginRouteIds } from '@dokebi/web/points';
5
5
  import { httpsFetch } from './cimd.js';
6
6
  import { ClientDirectory, DYNAMIC_ID } from './clients.js';
7
7
  import { OAuthError } from './errors.js';
@@ -19,10 +19,10 @@ import { openSqlStore } from './store-sql.js';
19
19
  * this package keeps working with older cores, which never describe.
20
20
  */
21
21
  const describePoint = definePoint('core:describe');
22
- /** dokebi-web 0.4.3 or later: `routeConfig` and `routeHook` (D-0076 §5). */
22
+ /** dokebi-web 0.4.23 or later: `routeConfig` and `routeHook` (D-0076 §5), `afterAppDomains` (D-0266). */
23
23
  const web = providerDependency({
24
24
  name: 'dokebi-web',
25
- version: '^0.4.3',
25
+ version: '^0.4.23',
26
26
  packageName: '@dokebi/web',
27
27
  load: () => import('@dokebi/web'),
28
28
  });
@@ -589,8 +589,9 @@ class OAuthRuntime {
589
589
  const resourceApps = new Map([...resources.keys()].map((id) => [id, appList(options.resources[id]?.app) ?? issuerApps]));
590
590
  const issuerBinding = issuerApps === undefined ? {} : { app: issuerApps };
591
591
  const routes = async (scope) => {
592
- // At boot the app routing is final: the issuer and each resource URI must be hosts of the
593
- // apps that serve them, or the metadata would send clients to a 404.
592
+ // The issuer and each resource URI must be hosts of the apps that serve them, or the
593
+ // metadata would send clients to a 404. The dokebi.yaml domains are final at boot; the
594
+ // rows of a domain provider come later, and the host is asked again then (D-0266).
594
595
  checkHost(server, logger, 'dokebi-oauth.issuer', options.issuer, issuerApps, 'dokebi-oauth.app');
595
596
  for (const [id, apps] of resourceApps)
596
597
  checkHost(server, logger, `dokebi-oauth.resources.${id}.uri`, resources.get(id).uri, apps, `dokebi-oauth.resources.${id}.app`);
@@ -722,8 +723,11 @@ function metadataHosts(resources, apps) {
722
723
  return groups;
723
724
  }
724
725
  /**
725
- * A URL this plugin publishes (the issuer, a resource URI) against the apps that serve it, at
726
- * boot (D-0132): a domain of another app fails the start, a host that is no domain is warned.
726
+ * A URL this plugin publishes (the issuer, a resource URI) against the apps that serve it
727
+ * (D-0132). At boot, against the dokebi.yaml domains: a domain of another app fails the start.
728
+ * When the domains are complete (D-0266: now, or after the first load of a domain provider): a
729
+ * host that is no domain is warned, and a host a provider's row gave to another app is an error
730
+ * line (a table that came later does not stop a running app).
727
731
  */
728
732
  function checkHost(server, logger, where, url, apps, option) {
729
733
  const match = appUrlMatch(server.apps, url, apps);
@@ -731,16 +735,31 @@ function checkHost(server, logger, where, url, apps, option) {
731
735
  throw new OAuthError('INVALID_OPTIONS', `${where} ${url} is on ${match.host}, a domain of app ${match.app}, but ${option} is ${apps?.join(', ')}: clients would reach a 404 there`, {
732
736
  fix: `Set options.${option} to ${match.app} (the app of ${match.host}), or move ${where} to a host of ${apps?.join(' or ')}.`,
733
737
  });
734
- if (match.kind === 'unconfigured')
735
- logger.log('warn', 'An OAuth URL host is no domain of dokebi-app', {
736
- code: 'OAUTH_HOST_UNMAPPED',
737
- where,
738
- url,
739
- host: match.host,
740
- apps,
741
- unknownDomain: match.fallback ?? null,
742
- fix: `Point ${match.host} at ${apps?.[0]} in options.dokebi-app.domains (npx dokebi app link ${apps?.[0]} ${match.host}), unless a proxy sends another Host.`,
743
- });
738
+ if (match.kind === 'ok')
739
+ return;
740
+ afterAppDomains(server.apps, () => {
741
+ const loaded = appUrlMatch(server.apps, url, apps);
742
+ if (loaded.kind === 'other-app')
743
+ logger.log('error', 'An OAuth URL host is a domain of another app', {
744
+ code: 'OAUTH_HOST_OTHER_APP',
745
+ where,
746
+ url,
747
+ host: loaded.host,
748
+ hostApp: loaded.app,
749
+ apps,
750
+ fix: `The domain provider points ${loaded.host} at ${loaded.app}: clients reach a 404 there. Point it at ${apps?.[0]} in the provider's table, or set options.${option} to ${loaded.app}.`,
751
+ });
752
+ else if (loaded.kind === 'unconfigured')
753
+ logger.log('warn', 'An OAuth URL host is no domain of dokebi-app', {
754
+ code: 'OAUTH_HOST_UNMAPPED',
755
+ where,
756
+ url,
757
+ host: loaded.host,
758
+ apps,
759
+ unknownDomain: loaded.fallback ?? null,
760
+ fix: `Point ${loaded.host} at ${apps?.[0]} in options.dokebi-app.domains (npx dokebi app link ${apps?.[0]} ${loaded.host}) or in the domain provider's table, unless a proxy sends another Host.`,
761
+ });
762
+ });
744
763
  }
745
764
  /**
746
765
  * The dokebi-oauth plugin factory with settings: `defineOAuthPlugin({ cimdFetch })`.
@@ -749,7 +768,7 @@ function checkHost(server, logger, where, url, apps, option) {
749
768
  export function defineOAuthPlugin(settings = {}) {
750
769
  return definePlugin({
751
770
  name: 'dokebi-oauth',
752
- version: '0.1.4',
771
+ version: '0.1.5',
753
772
  core: '^0.4.2',
754
773
  options: declaration,
755
774
  contributes: [describePoint],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/oauth",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "OAuth 2.1 authorization server for @dokebi/web on @dokebi/auth tokens: authorization code with PKCE, refresh rotation, revocation, client ID metadata documents, protected resource metadata and route protection.",
5
5
  "keywords": [
6
6
  "dokebi",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@dokebi/core": "^0.4.2",
48
- "@dokebi/web": "^0.4.3",
48
+ "@dokebi/web": "^0.4.23",
49
49
  "@dokebi/auth": "^0.4.1",
50
50
  "@dokebi/session": "^0.4.4",
51
51
  "@dokebi/csrf": "^0.4.0",
@@ -69,14 +69,14 @@
69
69
  }
70
70
  },
71
71
  "devDependencies": {
72
- "@dokebi/auth": "0.4.10",
73
- "@dokebi/csrf": "0.4.3",
72
+ "@dokebi/auth": "0.4.12",
73
+ "@dokebi/csrf": "0.4.4",
74
74
  "@dokebi/db": "0.4.4",
75
- "@dokebi/rate-limit": "0.1.1",
75
+ "@dokebi/rate-limit": "0.1.2",
76
76
  "@dokebi/redis": "0.4.2",
77
77
  "@dokebi/session": "0.4.10",
78
78
  "@dokebi/sse": "0.4.7",
79
- "@dokebi/web": "0.4.21"
79
+ "@dokebi/web": "0.4.23"
80
80
  },
81
81
  "dokebi": {
82
82
  "schemaVersion": 2,
@@ -85,7 +85,7 @@
85
85
  "dependencies": [
86
86
  {
87
87
  "name": "dokebi-web",
88
- "version": "^0.4.3"
88
+ "version": "^0.4.23"
89
89
  },
90
90
  {
91
91
  "name": "dokebi-auth",