@gjermundgaraba/clankerauth-sdk 0.26.1 → 0.26.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/README.md CHANGED
@@ -340,9 +340,9 @@ Tagged errors, all from `@gjermundgaraba/clankerauth-sdk/errors`: `Unauthorized`
340
340
 
341
341
  There is one 403. Only the verifier's own check fails with `InsufficientScope`: a credential that is valid but lacks a scope in `requiredScopes`, a resource's `required`. It names that scope and the credential's `actor`, which decides whether its `Forbidden` steps up. A scope asked for after verification, by `requires(scope)`, `admitted(scope)`, `admit(header, scope)` or `watch(header, scope)`, is refused with effect-actions' `Action.Forbidden` directly, decided by the same rule. A credential that is not this resource's at all — the wrong audience, or an API key with no entry in this resource's key list — is `Unauthorized`, because from the resource's side those are the same thing.
342
342
 
343
- JWTs are checked against issuer, audience, EdDSA signature, token type, required claims, expiry and scopes. Sender-constrained tokens are rejected. One JWKS read answers every verification for a minute, so a key the issuer starts or stops publishing takes effect within that minute; a `kid` the current document does not publish is `Unauthorized` and never triggers a read, so a token with an invented `kid` cannot become provider traffic. A failed read answers `ProviderUnavailable` (503) for five seconds before the next attempt; a read whose verification is interrupted writes nothing, and the next verification reads again. API keys are verified offline, against the resource's key list: one document the issuer signs with its access-token key, holding a sealed entry per key granted on this resource, which only that key can find or open. The list is verified once, when it is read, and one read answers every key it names for a minute, without issuer traffic; so a key disabled, deleted or re-scoped keeps the access it had until the next read, within about a minute. A key the held list does not name may have been created, enabled or granted on this resource since, so the list is read again before the key is refused, unless it was read within the last five seconds: such a key works within seconds, and unknown keys reach the issuer at most once every five seconds. A key's own expiry is checked on every verification, so it applies at once. A failed read, or one whose list or JWKS fetch takes longer than three seconds, is no error while the last list is inside its own lifetime, which the issuer sets to 24 hours: keys keep verifying through an outage, JWKS or not, and the issuer is tried again after five seconds. A read whose verification is interrupted writes nothing, and the next key reads again. Past that lifetime, or before any list has been read, a key is `ProviderUnavailable`. Reads that start failing are logged once as a warning, and their recovery once at info level, so an outage the held list hides still shows in the application's logs without a line per retry. The last list read is the one held, whatever its `iat`: HTTPS to the issuer is what keeps an old list from being replayed, and one could only ever be replayed inside its own day. The issuer does not count key use, so rate limiting is the application's. A key is a bearer secret, and one granted on several resources can be replayed by any of them to the others; a resource you trust less gets its own key. A resource that accepts only OAuth access tokens sets `apiKeys: false`; key-shaped bearers then fail as `Unauthorized` without reading the key list. Admission through a `Resource` has a five-second deadline; the raw `Verifier` has none, so an in-process caller can await a provider call it cannot cancel. The exception is the key list read, which gives each of its fetches three seconds: the list, and the JWKS it is verified with when none is held, so a slow first fetch does not cut the second short. An issuer that stops answering therefore delays a key by three seconds and never fails it while a list is held; one that answers the list late and then stalls on the JWKS can take the read past `Resource`'s deadline.
343
+ JWTs are checked against issuer, audience, EdDSA signature, token type, required claims, expiry and scopes. Sender-constrained tokens are rejected. One JWKS read answers every verification for a minute, so a key the issuer starts or stops publishing takes effect within that minute; a `kid` the current document does not publish is `Unauthorized` and never triggers a read, so a token with an invented `kid` cannot become provider traffic. A failed read answers `ProviderUnavailable` (503) for five seconds before the next attempt; a read whose verification is interrupted writes nothing, and the next verification reads again. API keys are verified offline, against the resource's key list: one document the issuer signs with its access-token key, holding a sealed entry per key granted on this resource, which only that key can find or open. The list is verified once, when it is read, and one read answers every key it names for a minute, without issuer traffic; so a key disabled, deleted or re-scoped keeps the access it had until the next read, within about a minute. A key the held list does not name may have been created, enabled or granted on this resource since, so the list is read again before the key is refused, unless it was read within the last five seconds: such a key works within seconds, and unknown keys reach the issuer at most once every five seconds. A key's own expiry is checked on every verification, so it applies at once. A failed read, or one whose list or JWKS fetch takes longer than three seconds, is no error while the last list is inside its own lifetime, which the issuer sets to 24 hours: keys keep verifying through an outage, JWKS or not, and the issuer is tried again after five seconds. A read whose verification is interrupted writes nothing, and the next key reads again. Past that lifetime, or before any list has been read, a key is `ProviderUnavailable`. Reads that start failing are logged once as a warning, and their recovery once at info level, so an outage the held list hides still shows in the application's logs without a line per retry. The last list read is the one held, whatever its `iat`: HTTPS to the issuer is what keeps an old list from being replayed, and one could only ever be replayed inside its own day. The issuer does not count key use, so rate limiting is the application's. A key is a bearer secret, and one granted on several resources can be replayed by any of them to the others; a resource you trust less gets its own key. A resource that accepts only OAuth access tokens sets `apiKeys: false`; key-shaped bearers then fail as `Unauthorized` without reading the key list. Admission through a `Resource` has a five-second deadline; the raw `Verifier` has none, so an in-process caller can await a provider call it cannot cancel. The exception is the key list read, which runs its two fetches together, the list and the JWKS it is verified with when none is held, and gives each three seconds, so a slow fetch does not cut the other short. A key list read therefore ends within three seconds, whatever stalls, and never fails a key while a list is held.
344
344
 
345
- The bundled issuer does not configure automatic signing-key rotation. Immediate-use rotation is supported, but tokens signed by a new key are rejected until the next JWKS read, up to a minute; a key list signed by it is not taken until then either, and the held list keeps deciding. Publish-before-use avoids that window; it is not mandatory. Key lists are re-signed on every read, so issued API keys are unaffected by rotation.
345
+ The bundled issuer does not configure automatic signing-key rotation. Immediate-use rotation is supported, but tokens signed by a new key are rejected until the next JWKS read, up to a minute; a key list signed by it is not taken until then either, and the held list keeps deciding. The same holds on a read with no JWKS held: its JWKS fetch runs beside the list's, so a list signed by a key minted after that fetch began fails verification until the next JWKS read. The bundled issuer mints its signing key when it starts, so a fresh issuer's first list is signed by the key its JWKS publishes. Publish-before-use avoids that window; it is not mandatory. Key lists are re-signed on every read, so issued API keys are unaffected by rotation.
346
346
 
347
347
  The SDK's resource maps verification failures to effect-actions' refusals and its own 503; effect-actions supplies request-scoped identity, challenge headers and `Cache-Control: no-store` on every response to a request it authenticates; other cache policy is the host's. Defects and interruption are not relabeled as authentication rejection. Named effects supply tracing boundaries; application logging/tracing layers remain caller-owned. No `onFailure` callbacks or hidden runtime.
348
348
 
package/dist/verify.d.ts CHANGED
@@ -85,7 +85,8 @@ export declare const store: () => Store;
85
85
  * request costs nothing: every read it makes runs in the verification that needs it.
86
86
  * Verification runs to completion: a deadline is the request edge's policy, which
87
87
  * `Resource` applies, so an in-process caller can await a provider call it cannot cancel.
88
- * The one exception is a key list read, which gives up on each of its fetches after three seconds.
88
+ * The one exception is a key list read, which runs its fetches together and gives up on each
89
+ * after three seconds.
89
90
  */
90
91
  export declare const make: (options: Options) => Effect.Effect<{
91
92
  verifyToken: (token: string) => Effect.Effect<{
package/dist/verify.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Clock, Duration, Effect, Result, Schema } from "effect";
1
+ import { Clock, Duration, Effect, Fiber, Result, Schema } from "effect";
2
2
  import { createLocalJWKSet, decodeProtectedHeader, jwtVerify } from "jose";
3
3
  import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
4
4
  import { ConfigurationError, InsufficientScope, ProviderUnavailable, Unauthorized, } from "./errors.js";
@@ -37,9 +37,9 @@ const documentLifetime = Duration.minutes(1);
37
37
  */
38
38
  const cooldown = Duration.seconds(5);
39
39
  /**
40
- * How long each fetch of a key list read may take: the list, and the JWKS it is verified
41
- * with when none is held. Under `Resource`'s five-second deadline, so an issuer that stops
42
- * answering fails the read, not the request, and a held list still decides.
40
+ * How long each fetch of a key list read may take: the list, and the JWKS it is verified with
41
+ * when none is held. Under `Resource`'s five-second deadline, so an issuer that stops answering
42
+ * fails the read, not the request, and a held list still decides.
43
43
  */
44
44
  const listReadTimeout = Duration.seconds(3);
45
45
  const deadline = (operation) => (effect) => Effect.timeoutOrElse(effect, {
@@ -52,7 +52,8 @@ const deadline = (operation) => (effect) => Effect.timeoutOrElse(effect, {
52
52
  * request costs nothing: every read it makes runs in the verification that needs it.
53
53
  * Verification runs to completion: a deadline is the request edge's policy, which
54
54
  * `Resource` applies, so an in-process caller can await a provider call it cannot cancel.
55
- * The one exception is a key list read, which gives up on each of its fetches after three seconds.
55
+ * The one exception is a key list read, which runs its fetches together and gives up on each
56
+ * after three seconds.
56
57
  */
57
58
  export const make = Effect.fn("Verifier.make")(function* (options) {
58
59
  const client = yield* HttpClient.HttpClient;
@@ -155,10 +156,11 @@ export const make = Effect.fn("Verifier.make")(function* (options) {
155
156
  });
156
157
  return yield* HttpClientResponse.schemaBodyJson(KeyListResponse)(response).pipe(Effect.mapError((cause) => new ProviderUnavailable({ operation: "key-list.decode", cause })));
157
158
  });
159
+ // why: the JWKS read runs beside the list's, on its own deadline, so neither spends the other's.
160
+ const signing = yield* Effect.forkScoped(keys.pipe(deadline("jwks.timeout")));
158
161
  const { list } = yield* fetched.pipe(deadline("key-list.timeout"));
159
162
  const rejected = (cause) => new ProviderUnavailable({ operation: "key-list.verify", cause });
160
- // why: a JWKS read on its own deadline, so a cold one does not spend the list's.
161
- const payload = yield* verifySigned(list, KeyList.type, keys.pipe(deadline("jwks.timeout"))).pipe(Effect.catchTag("Unauthorized", (cause) => Effect.fail(rejected(cause))));
163
+ const payload = yield* verifySigned(list, KeyList.type, Fiber.join(signing)).pipe(Effect.catchTag("Unauthorized", (cause) => Effect.fail(rejected(cause))));
162
164
  const claims = yield* Schema.decodeUnknownEffect(KeyListClaims)(payload).pipe(Effect.mapError(rejected));
163
165
  return {
164
166
  readAt: yield* Clock.currentTimeMillis,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjermundgaraba/clankerauth-sdk",
3
- "version": "0.26.1",
3
+ "version": "0.26.3",
4
4
  "description": "Effect-native clankerauth access-token and offline API-key verification, with optional effect-actions integration",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -47,7 +47,7 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "jose": "6.2.12",
50
+ "jose": "6.2.13",
51
51
  "oauth4webapi": "3.8.8",
52
52
  "proper-lockfile": "4.1.2"
53
53
  },