@dokebi/oauth 0.1.4 → 0.1.6
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/AI.md +5 -4
- package/dist/plugin.js +39 -19
- package/package.json +9 -9
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
|
+
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
|
|
|
@@ -101,14 +101,14 @@ The `defineOptions` declaration in `src/options.ts` is the parser; the build wri
|
|
|
101
101
|
| Path | Meaning |
|
|
102
102
|
|---|---|
|
|
103
103
|
| `GET /.well-known/oauth-authorization-server` | RFC 8414 metadata, **derived from the options only**: `issuer`, the endpoints (`registration_endpoint` only when open), `response_types_supported: ["code"]`, `grant_types_supported: ["authorization_code", "refresh_token"]`, `code_challenge_methods_supported: ["S256"]`, `token_endpoint_auth_methods_supported: ["none", "client_secret_basic", "client_secret_post"]`, `scopes_supported` (all resources), `client_id_metadata_document_supported: true` (when CIMD is on), `authorization_response_iss_parameter_supported: true` |
|
|
104
|
-
| `GET /.well-known/oauth-protected-resource<path>` | RFC 9728 metadata of the resource whose URI has `<path>` (`https://h/mcp` → `/.well-known/oauth-protected-resource/mcp`): `resource` **exactly as configured** (never re-serialized: `new URL().href` adds a trailing `/` and breaks Claude's comparison), `authorization_servers: [issuer]`, `scopes_supported`, `bearer_methods_supported: ["header"]`, `resource_name`. Any other path under it: 404 `{ error: "not_found", error_description, resource_metadata: [every resource's metadata URL] }` (no log) |
|
|
104
|
+
| `GET /.well-known/oauth-protected-resource<path>` | RFC 9728 metadata of the resource whose URI has `<path>` (`https://h/mcp` → `/.well-known/oauth-protected-resource/mcp`): `resource` **exactly as configured** (never re-serialized: `new URL().href` adds a trailing `/` and breaks Claude's comparison), `authorization_servers: [issuer]`, `scopes_supported`, `bearer_methods_supported: ["header"]`, `resource_name`. Any other path under it: 404 `{ error: "not_found", error_description, resource_metadata: [every resource's metadata URL] }` with `Cache-Control: no-store` (0.1.6, [D-0302](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0302-missing-files-never-cached.md): a resource added later is found at once) (no log) |
|
|
105
105
|
| `GET /oauth/authorize` | the authorization request (§4) |
|
|
106
106
|
| `POST /oauth/authorize` | the consent decision of the app's page (§5); checked by @dokebi/csrf |
|
|
107
107
|
| `POST /oauth/token` | `authorization_code` and `refresh_token` (§6). `Cache-Control: no-store`. Errors are RFC 6749 bodies `{ error, error_description }` |
|
|
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.
|
|
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.
|
|
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
|
-
//
|
|
593
|
-
//
|
|
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`);
|
|
@@ -619,8 +620,9 @@ class OAuthRuntime {
|
|
|
619
620
|
const path = request.url.split('?', 1)[0];
|
|
620
621
|
const resource = served.find((one) => one.metadataPath === path);
|
|
621
622
|
reply.header('access-control-allow-origin', '*');
|
|
623
|
+
// D-0302: never kept by a CDN or browser (a resource added later is found at once).
|
|
622
624
|
if (!resource)
|
|
623
|
-
return reply.code(404).send(oauth.metadataNotFound());
|
|
625
|
+
return reply.code(404).header('cache-control', 'no-store').send(oauth.metadataNotFound());
|
|
624
626
|
return reply.send(oauth.resourceMetadata(resource));
|
|
625
627
|
};
|
|
626
628
|
const common = { seal: false };
|
|
@@ -722,8 +724,11 @@ function metadataHosts(resources, apps) {
|
|
|
722
724
|
return groups;
|
|
723
725
|
}
|
|
724
726
|
/**
|
|
725
|
-
* A URL this plugin publishes (the issuer, a resource URI) against the apps that serve it
|
|
726
|
-
*
|
|
727
|
+
* A URL this plugin publishes (the issuer, a resource URI) against the apps that serve it
|
|
728
|
+
* (D-0132). At boot, against the dokebi.yaml domains: a domain of another app fails the start.
|
|
729
|
+
* When the domains are complete (D-0266: now, or after the first load of a domain provider): a
|
|
730
|
+
* host that is no domain is warned, and a host a provider's row gave to another app is an error
|
|
731
|
+
* line (a table that came later does not stop a running app).
|
|
727
732
|
*/
|
|
728
733
|
function checkHost(server, logger, where, url, apps, option) {
|
|
729
734
|
const match = appUrlMatch(server.apps, url, apps);
|
|
@@ -731,16 +736,31 @@ function checkHost(server, logger, where, url, apps, option) {
|
|
|
731
736
|
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
737
|
fix: `Set options.${option} to ${match.app} (the app of ${match.host}), or move ${where} to a host of ${apps?.join(' or ')}.`,
|
|
733
738
|
});
|
|
734
|
-
if (match.kind === '
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
host
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
739
|
+
if (match.kind === 'ok')
|
|
740
|
+
return;
|
|
741
|
+
afterAppDomains(server.apps, () => {
|
|
742
|
+
const loaded = appUrlMatch(server.apps, url, apps);
|
|
743
|
+
if (loaded.kind === 'other-app')
|
|
744
|
+
logger.log('error', 'An OAuth URL host is a domain of another app', {
|
|
745
|
+
code: 'OAUTH_HOST_OTHER_APP',
|
|
746
|
+
where,
|
|
747
|
+
url,
|
|
748
|
+
host: loaded.host,
|
|
749
|
+
hostApp: loaded.app,
|
|
750
|
+
apps,
|
|
751
|
+
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}.`,
|
|
752
|
+
});
|
|
753
|
+
else if (loaded.kind === 'unconfigured')
|
|
754
|
+
logger.log('warn', 'An OAuth URL host is no domain of dokebi-app', {
|
|
755
|
+
code: 'OAUTH_HOST_UNMAPPED',
|
|
756
|
+
where,
|
|
757
|
+
url,
|
|
758
|
+
host: loaded.host,
|
|
759
|
+
apps,
|
|
760
|
+
unknownDomain: loaded.fallback ?? null,
|
|
761
|
+
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.`,
|
|
762
|
+
});
|
|
763
|
+
});
|
|
744
764
|
}
|
|
745
765
|
/**
|
|
746
766
|
* The dokebi-oauth plugin factory with settings: `defineOAuthPlugin({ cimdFetch })`.
|
|
@@ -749,7 +769,7 @@ function checkHost(server, logger, where, url, apps, option) {
|
|
|
749
769
|
export function defineOAuthPlugin(settings = {}) {
|
|
750
770
|
return definePlugin({
|
|
751
771
|
name: 'dokebi-oauth',
|
|
752
|
-
version: '0.1.
|
|
772
|
+
version: '0.1.6',
|
|
753
773
|
core: '^0.4.2',
|
|
754
774
|
options: declaration,
|
|
755
775
|
contributes: [describePoint],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dokebi/oauth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
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.
|
|
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.
|
|
73
|
-
"@dokebi/csrf": "0.4.
|
|
74
|
-
"@dokebi/db": "0.4.
|
|
75
|
-
"@dokebi/rate-limit": "0.1.
|
|
72
|
+
"@dokebi/auth": "0.4.15",
|
|
73
|
+
"@dokebi/csrf": "0.4.4",
|
|
74
|
+
"@dokebi/db": "0.4.7",
|
|
75
|
+
"@dokebi/rate-limit": "0.1.2",
|
|
76
76
|
"@dokebi/redis": "0.4.2",
|
|
77
|
-
"@dokebi/session": "0.4.
|
|
77
|
+
"@dokebi/session": "0.4.11",
|
|
78
78
|
"@dokebi/sse": "0.4.7",
|
|
79
|
-
"@dokebi/web": "0.4.
|
|
79
|
+
"@dokebi/web": "0.4.28"
|
|
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.
|
|
88
|
+
"version": "^0.4.23"
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
91
|
"name": "dokebi-auth",
|