@dokebi/oauth 0.1.1 → 0.1.3

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
@@ -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/clients.js CHANGED
@@ -84,7 +84,8 @@ export class ClientDirectory {
84
84
  if (registered)
85
85
  return { ok: true, client: registered };
86
86
  if (this.isDocument(clientId)) {
87
- const now = Date.now();
87
+ // D-0254: the document and refusal copies age on the monotonic clock.
88
+ const now = performance.now();
88
89
  const cached = this.#documents.get(clientId, now);
89
90
  if (cached)
90
91
  return {
@@ -153,7 +154,7 @@ export class ClientDirectory {
153
154
  throw error;
154
155
  this.#refused.set(clientId, {
155
156
  error,
156
- until: Date.now() + this.#settings.cimd.refusalCacheMs,
157
+ until: performance.now() + this.#settings.cimd.refusalCacheMs,
157
158
  });
158
159
  return {
159
160
  ok: false,
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.1',
752
+ version: '0.1.3',
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.1",
3
+ "version": "0.1.3",
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",
73
- "@dokebi/csrf": "0.4.0",
74
- "@dokebi/db": "0.4.1",
72
+ "@dokebi/auth": "0.4.8",
73
+ "@dokebi/csrf": "0.4.3",
74
+ "@dokebi/db": "0.4.4",
75
75
  "@dokebi/rate-limit": "0.1.1",
76
- "@dokebi/redis": "0.4.1",
77
- "@dokebi/session": "0.4.4",
78
- "@dokebi/sse": "0.4.2",
79
- "@dokebi/web": "0.4.3"
76
+ "@dokebi/redis": "0.4.2",
77
+ "@dokebi/session": "0.4.10",
78
+ "@dokebi/sse": "0.4.7",
79
+ "@dokebi/web": "0.4.21"
80
80
  },
81
81
  "dokebi": {
82
82
  "schemaVersion": 2,