@dokebi/oauth 0.1.0 → 0.1.2

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 CHANGED
@@ -119,7 +119,7 @@ dokebi-oauth:
119
119
  dokebi-mcp: { app: mcp }
120
120
  ```
121
121
 
122
- The metadata documents answer `Access-Control-Allow-Origin: *`. `/oauth/token`, `/oauth/revoke` and `/oauth/register` have `config: { csrf: false, auth: false }` and are never sealed (`seal: false`). The consent decision (`POST /oauth/authorize`) is a form of your app: on a seal host (`dokebi-app.domains.<host>.seal`) it is sealed like every form (a plain post gets 415 `SEAL_REQUIRED`), so the consent page writes `data.seal.head` (§5: `seal(request)` of @dokebi/app), never a copied seal `<script>` or import map (`dokebi check` warns `seal-head-copied`). The plugin parses `application/x-www-form-urlencoded` bodies of its own routes itself (dokebi-web's `formBody` is not needed for them), so a **repeated parameter** is seen and refused (a framework parser keeps the last of `resource=A&resource=B` silently: the value checked and the value used could differ). Empty values count as omitted (RFC 6749 §3.1) but still count as a repeat.
122
+ The metadata documents answer `Access-Control-Allow-Origin: *`. `/oauth/token`, `/oauth/revoke` and `/oauth/register` have `config: { csrf: false, auth: false }` and are never sealed (`seal: false`). The consent decision (`POST /oauth/authorize`) is a form of your app: on a seal host (`dokebi-app.domains.<host>.seal`) it is sealed like every form (a plain post gets 415 `SEAL_REQUIRED`), so the consent page writes `data.seal.head` (§5: `seal(request)` of @dokebi/app), never a copied seal `<script>` or import map (`dokebi check` warns `seal-head-copied`). An **Inertia consent page** posts the decision with Inertia's `router.post` instead (sealed by `sealInertia`; the answer is 409 `X-Inertia-Location`, an error such as `CONSENT_EXPIRED` renders the app's error page in place), not with `@dokebi/seal/forms`, whose HTML error answer would be the app's own shell (plugins/dokebi-seal AI.md §5.2). The plugin parses `application/x-www-form-urlencoded` bodies of its own routes itself (dokebi-web's `formBody` is not needed for them), so a **repeated parameter** is seen and refused (a framework parser keeps the last of `resource=A&resource=B` silently: the value checked and the value used could differ). Empty values count as omitted (RFC 6749 §3.1) but still count as a repeat.
123
123
 
124
124
  **One resource comparison** decides everywhere (authorize, token, refresh, registration): scheme and host in lower case, the default port dropped, an empty path equal to `/` (RFC 3986 §6.2.3). The path, the query and their case are compared as they are. `resourceKey(uri)` and `sameResource(a, b)` are exported.
125
125
 
@@ -247,7 +247,7 @@ export default class AppOAuth extends OAuthExtension {
247
247
  Client authentication (RFC 6749 §2.3): a confidential client with `client_secret_basic` (Basic, the values form-urlencoded) or `client_secret_post`; a public client (`none`: a pre-registered client without a secret, a document client, a registered client) sends `client_id` only and no secret. Two methods at once is `invalid_request`; an unknown client, a wrong or missing secret, or a public client sending a secret is 401 `invalid_client` (with `WWW-Authenticate: Basic` after a Basic attempt).
248
248
 
249
249
  - `grant_type=authorization_code`: `code`, `code_verifier`, `redirect_uri` (all required), `resource` (optional; must name the same resource). The code is read first: it must be of this client, `redirect_uri` the same string, the verifier must match (S256, constant time) and `resource` the same — **an attempt that does not match is refused without using the code** (a stranger cannot burn it). Then it is used **atomically, once**, must be unexpired, and the grant live. **The user is read again** (`findById`, then `canDelegate`), and the grant's **pending pair** must still be live for that user: an account suspended (`active: false`) or invalidated account-wide (a new stamp: password change, "log out other devices"; `tokens.revokeAll`) since the consent, or a grant revoked meanwhile, gets no token (`invalid_grant`). The pair is dokebi-auth's `tokens.pair(user, { family: grant.id, audience: <resource id>, accessMs, refreshMs, notAfter: grant end })`. **A matching second use of a code revokes its grant and every token it issued** (warn `OAUTH_CODE_REUSED`) — also when it races the first exchange. The tokens carry the code's scopes as dokebi-auth abilities (`dokebi-oauth:none` for a resource without scopes).
250
- - `grant_type=refresh_token`: `refresh_token`, optional `resource` and `scope`. The token is looked at **before** it is used (`tokens.peek`): one of another client is `invalid_grant` and **its grant stays** (it was not consumed); a revoked or expired grant is `invalid_grant`. **The user is read again** and `canDelegate` asked: an account that is gone or may not delegate any more loses the grant (`invalid_grant`, info `OAUTH_GRANT_REVOKED` with `reason: cannot-delegate` or `user-gone`). **Narrowing** (RFC 6749 §6): `scope` may ask for a subset of the grant's scopes the refresh token holds — the new access token carries exactly that subset and the answer's `scope` says so; without `scope` the access token gets the grant's scopes the refresh token holds; the new refresh token keeps the refresh token's scopes. Asking for more is `invalid_scope`. Then dokebi-auth rotates it: a refresh token used before revokes the family, and this plugin revokes the grant (warn `OAUTH_REFRESH_REUSED`). The new tokens never outlive the grant (`notAfter`).
250
+ - `grant_type=refresh_token`: `refresh_token`, optional `resource` and `scope`. The token is looked at **before** it is used (`tokens.peek`): one of another client is `invalid_grant` and **its grant stays** (it was not consumed); a revoked or expired grant is `invalid_grant`. **The user is read again** and `canDelegate` asked: an account that is gone or may not delegate any more loses the grant (`invalid_grant`, info `OAUTH_GRANT_REVOKED` with `reason: cannot-delegate` or `user-gone`). **Narrowing** (RFC 6749 §6): `scope` may ask for a subset of the grant's scopes the refresh token holds — the new access token carries exactly that subset and the answer's `scope` says so; without `scope` the access token gets the grant's scopes the refresh token holds; the new refresh token keeps the refresh token's scopes. Asking for more is `invalid_scope`. Then dokebi-auth rotates it: a refresh token used before revokes the family, and this plugin revokes the grant (warn `OAUTH_REFRESH_REUSED`). Two refreshes **at once** with one token: both look at it while it is unused, one rotates it and the other is the reuse — dokebi-auth revokes the family (warn `TOKEN_REUSED`), the tokens the first one answered included, so both answers end unusable and the client connects again; this plugin does not see that reuse at its look, so there is no `OAUTH_REFRESH_REUSED` and the grant is left as after an account-wide invalidation (§9: without a live token, neither usable nor listed, not marked revoked). The new tokens never outlive the grant (`notAfter`).
251
251
  - Answer: `{ access_token, token_type: "Bearer", expires_in, refresh_token, scope? }`, `Cache-Control: no-store`, `Pragma: no-cache`.
252
252
  - With `rateLimit`, each client and credential (code or refresh token) has a bucket; beyond it 429 `invalid_request` with `Retry-After`.
253
253
 
package/dist/plugin.js CHANGED
@@ -749,7 +749,7 @@ function checkHost(server, logger, where, url, apps, option) {
749
749
  export function defineOAuthPlugin(settings = {}) {
750
750
  return definePlugin({
751
751
  name: 'dokebi-oauth',
752
- version: '0.1.0',
752
+ version: '0.1.2',
753
753
  core: '^0.4.2',
754
754
  options: declaration,
755
755
  contributes: [describePoint],
package/dist/server.js CHANGED
@@ -1041,6 +1041,10 @@ export class OAuthServer {
1041
1041
  await grants.revokeRow(grant, 'refresh-reused');
1042
1042
  grants.repeats.log('warn', 'OAuth refresh token used twice: its grant is revoked', 'OAUTH_REFRESH_REUSED', undefined, { realm: grant.realm, userId: grant.userId, clientId: client.id, grant: grant.id }, grant.id);
1043
1043
  }
1044
+ // Not seen at the look: two refreshes at once with one token (the other one rotated it,
1045
+ // this one is the reuse) or an account that changed meanwhile. dokebi-auth revoked the
1046
+ // family either way and does not say which, so the grant stays as it is after an
1047
+ // account-wide invalidation: without a live token, neither usable nor listed (grants.ts).
1044
1048
  throw new OAuthProtocolError('invalid_grant', 'The refresh token cannot be used; connect again');
1045
1049
  }
1046
1050
  grants.touch(grant, now);
@@ -1475,7 +1479,8 @@ function decisionBody(body) {
1475
1479
  if (scopeValue !== undefined &&
1476
1480
  (!Array.isArray(scopeValue) || scopeValue.some((item) => typeof item !== 'string')))
1477
1481
  throw new OAuthError('INVALID_CONSENT', 'scope must be scope names', { status: 400 });
1478
- const kind = read('kind');
1482
+ // A JSON body says "no kind" with null, as it does for binding (an Inertia form's empty field).
1483
+ const kind = read('kind') ?? undefined;
1479
1484
  if (kind !== undefined &&
1480
1485
  kind !== '' &&
1481
1486
  (typeof kind !== 'string' || kind.length > MAX_KIND || !KIND.test(kind)))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/oauth",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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",
@@ -69,14 +69,14 @@
69
69
  }
70
70
  },
71
71
  "devDependencies": {
72
- "@dokebi/auth": "0.4.1",
72
+ "@dokebi/auth": "0.4.3",
73
73
  "@dokebi/csrf": "0.4.0",
74
- "@dokebi/db": "0.4.1",
74
+ "@dokebi/db": "0.4.2",
75
75
  "@dokebi/rate-limit": "0.1.1",
76
76
  "@dokebi/redis": "0.4.1",
77
- "@dokebi/session": "0.4.4",
78
- "@dokebi/sse": "0.4.2",
79
- "@dokebi/web": "0.4.3"
77
+ "@dokebi/session": "0.4.7",
78
+ "@dokebi/sse": "0.4.5",
79
+ "@dokebi/web": "0.4.7"
80
80
  },
81
81
  "dokebi": {
82
82
  "schemaVersion": 2,