@dokebi/oauth 0.1.3 → 0.1.4

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
@@ -268,7 +268,7 @@ const user = await request.auth.user(); // the grant's user (dokebi-auth)
268
268
  - **The authentication time travels with each token chain**: as a reserved ability `dokebi-oauth:auth_time:<epoch seconds>` of its tokens, kept by every refresh, never shown as a scope (a grant is one authorization since D-0124, so its chain and it have one time; the mark stays on the tokens so that no table changed). There is no JWT or ID token: the routes of this app read it from `request.oauth.authTime`.
269
269
  - **`maxAge` (RFC 9470)**: a route that needs a recent sign-in (a key export, a vault reset) declares `config: { oauth: { resource, maxAge: 300 } }`. A token whose sign-in is unknown or older is 401 `INSUFFICIENT_USER_AUTHENTICATION` with `WWW-Authenticate: Bearer error="insufficient_user_authentication", error_description="…", resource_metadata="…", max_age="300"`; the client opens the browser for `/oauth/authorize?…&max_age=300` (or `prompt=login`) and retries with the new token.
270
270
  - `api.authenticate(request, { resource, scopes?, maxAge? })` runs the same check from your own hook (a WebSocket upgrade, an SSE `authenticate`, a route of an older scope); call it before anything reads `request.auth`.
271
- - **Bearer streams: `api.live(request)`** (D-0122, [D-0124](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0124-auth-time-bearer-live-grant-per-device.md)). After `authenticate`, `await oauth.live(request)` returns an `OAuthLiveAuthorization` (`valid()`, `subscribe()`, `expiresAt`) to return as `identity.authorization`. It is dokebi-auth's Bearer lease (`request.auth.live({ check })`) with the grant (not revoked, not expired) and `canDelegate` in **the same check**: one read of the token row, the user and the grant per check. @dokebi/sse and @dokebi/websocket end the connection when it ends: **at the token's expiry instant** (or the grant's end), **at once** on a revocation through this process (`grants.revoke`, `revokeAll`, the client's `/oauth/revoke`, a code or refresh reuse, an eviction by `grant.maxPerClient`; dokebi-auth's `tokens.revokeFamily`, `revoke` and `logoutOtherDevices()` re-check at once too), and **within `live.maxAgeMs`** (5 s) on what this process does not see: a revocation in another process, an **account change** (a new stamp: a password change or "log out other devices" elsewhere; `active: false`; a deleted account) or a `canDelegate` that turned false. A check that fails or throws ends it (error `OAUTH_LIVE_CHECK_FAILED` for the grant read or the hook, `AUTH_LIVE_CHECK_FAILED` for the token or user read); one that hangs never extends it. A token that stopped being valid between the route check and `live()` is 401 `UNAUTHENTICATED`. `expiresAt` lets the app send its own "refresh now" event shortly before.
271
+ - **Bearer streams: `api.live(request)`** (D-0122, [D-0124](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0124-auth-time-bearer-live-grant-per-device.md)). After `authenticate`, `await oauth.live(request)` returns an `OAuthLiveAuthorization` (`valid()`, `subscribe()`, `endReason()` — 0.1.4, [D-0262](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0262-live-lease-unconfirmed.md): `ended` for a revocation, an expiry or a changed user or grant, `unconfirmed` when no check could confirm it in time, so a WebSocket closes 4403 or 4503 — `expiresAt`) to return as `identity.authorization`. It is dokebi-auth's Bearer lease (`request.auth.live({ check })`) with the grant (not revoked, not expired) and `canDelegate` in **the same check**: one read of the token row, the user and the grant per check. @dokebi/sse and @dokebi/websocket end the connection when it ends: **at the token's expiry instant** (or the grant's end), **at once** on a revocation through this process (`grants.revoke`, `revokeAll`, the client's `/oauth/revoke`, a code or refresh reuse, an eviction by `grant.maxPerClient`; dokebi-auth's `tokens.revokeFamily`, `revoke` and `logoutOtherDevices()` re-check at once too), and **within `live.maxAgeMs`** (5 s) on what this process does not see: a revocation in another process, an **account change** (a new stamp: a password change or "log out other devices" elsewhere; `active: false`; a deleted account) or a `canDelegate` that turned false. A check that fails or throws ends it (error `OAUTH_LIVE_CHECK_FAILED` for the grant read or the hook, `AUTH_LIVE_CHECK_FAILED` for the token or user read); one that hangs never extends it. A token that stopped being valid between the route check and `live()` is 401 `UNAUTHENTICATED`. `expiresAt` lets the app send its own "refresh now" event shortly before.
272
272
 
273
273
  ```ts snippet
274
274
  // src/modules/term/events.ts — a Bearer event stream that ends with its token
package/dist/live.d.ts CHANGED
@@ -7,6 +7,11 @@ export interface OAuthLiveAuthorization {
7
7
  subscribe(invalidated: () => void): () => void;
8
8
  /** When the lease ends at the latest: the token's expiry or the grant's end, whichever is first. */
9
9
  readonly expiresAt: Date;
10
+ /**
11
+ * D-0262: why an invalid lease ended — `ended` (revoked, expired, the user or grant changed) or
12
+ * `unconfirmed` (no check could confirm it in time); undefined while valid.
13
+ */
14
+ endReason(): 'ended' | 'unconfirmed' | undefined;
10
15
  }
11
16
  /** How a lease is timed (dokebi-oauth `live`). */
12
17
  export interface LiveTiming {
@@ -17,6 +22,8 @@ export interface LiveTiming {
17
22
  export interface InnerLease {
18
23
  valid(): boolean;
19
24
  subscribe(invalidated: () => void): () => void;
25
+ /** dokebi-auth 0.4.10 (D-0262); an older one says nothing: an end. */
26
+ endReason?(): string | undefined;
20
27
  }
21
28
  /** The open leases of this process by grant, for the revocations this process makes. */
22
29
  export declare class LiveGrants {
@@ -41,6 +48,7 @@ export declare class GrantLease implements OAuthLiveAuthorization {
41
48
  readonly registry: LiveGrants;
42
49
  });
43
50
  valid(): boolean;
51
+ endReason(): 'ended' | 'unconfirmed' | undefined;
44
52
  subscribe(invalidated: () => void): () => void;
45
53
  /** Ends the lease (once) and tells every listener. */
46
54
  end(reason: string): void;
package/dist/live.js CHANGED
@@ -45,6 +45,8 @@ export class GrantLease {
45
45
  #listeners = new Set();
46
46
  #release;
47
47
  #ended = false;
48
+ /** Ended here (a revocation): always `ended`, whatever the inner lease says. */
49
+ #revoked = false;
48
50
  constructor(settings) {
49
51
  this.#grant = settings.grant;
50
52
  this.#inner = settings.inner;
@@ -55,6 +57,13 @@ export class GrantLease {
55
57
  valid() {
56
58
  return !this.#ended && this.#inner.valid();
57
59
  }
60
+ endReason() {
61
+ if (this.valid())
62
+ return undefined;
63
+ if (this.#revoked)
64
+ return 'ended';
65
+ return this.#inner.endReason?.() === 'unconfirmed' ? 'unconfirmed' : 'ended';
66
+ }
58
67
  subscribe(invalidated) {
59
68
  if (typeof invalidated !== 'function')
60
69
  throw new TypeError('subscribe needs a function');
@@ -68,7 +77,7 @@ export class GrantLease {
68
77
  if (this.#listeners.size === 1) {
69
78
  this.#registry.add(this.#grant, this);
70
79
  // The inner lease runs the checks while something listens here.
71
- const release = this.#inner.subscribe(() => this.end('unconfirmed'));
80
+ const release = this.#inner.subscribe(() => this.end('inner'));
72
81
  if (this.#ended)
73
82
  release();
74
83
  else
@@ -85,6 +94,8 @@ export class GrantLease {
85
94
  if (this.#ended)
86
95
  return;
87
96
  this.#ended = true;
97
+ if (reason === 'revoked')
98
+ this.#revoked = true;
88
99
  this.#stop();
89
100
  diagnostics.logDebug(this.#logger, 'OAuth live authorization ended', () => ({
90
101
  grant: this.#grant,
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.3',
752
+ version: '0.1.4',
753
753
  core: '^0.4.2',
754
754
  options: declaration,
755
755
  contributes: [describePoint],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/oauth",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
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,7 +69,7 @@
69
69
  }
70
70
  },
71
71
  "devDependencies": {
72
- "@dokebi/auth": "0.4.8",
72
+ "@dokebi/auth": "0.4.10",
73
73
  "@dokebi/csrf": "0.4.3",
74
74
  "@dokebi/db": "0.4.4",
75
75
  "@dokebi/rate-limit": "0.1.1",