@zuiio/m2m 0.0.0-stage → 0.1.0
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 +59 -2
- package/dist/claims.d.ts +48 -0
- package/dist/claims.d.ts.map +1 -0
- package/dist/claims.js +71 -0
- package/dist/claims.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/sign.d.ts +67 -0
- package/dist/sign.d.ts.map +1 -0
- package/dist/sign.js +114 -0
- package/dist/sign.js.map +1 -0
- package/dist/verify.d.ts +79 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +168 -0
- package/dist/verify.js.map +1 -0
- package/package.json +29 -4
package/README.md
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zuiio/m2m
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Machine-to-machine JWT for the Zuiio ecosystem: Zuiio ID (issuer) mints tokens
|
|
4
|
+
with `signMachineToken`, every consumer (zer-green, agent gateway, any Worker or
|
|
5
|
+
Node service) verifies them with `verifyMachineToken`. Replaces the drifted
|
|
6
|
+
copies in `zer-green/src/server/m2m-jwt.ts` and the agent gateway's
|
|
7
|
+
`worker/src/core/m2m-jwt.ts`.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @zuiio/m2m
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Published privately to npmjs from this repo by the `publish-packages` workflow;
|
|
16
|
+
consumers need an npm token with read access to the `@zuiio` scope.
|
|
17
|
+
|
|
18
|
+
## Verify
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { verifyMachineToken } from "@zuiio/m2m";
|
|
22
|
+
const result = await verifyMachineToken(bearer, {
|
|
23
|
+
expectedAudience: "agent-gateway",
|
|
24
|
+
requiredScope: "agent:invoke",
|
|
25
|
+
});
|
|
26
|
+
if (!result.ok) return new Response(result.reason, { status: 401 });
|
|
27
|
+
const { clientId, claims } = result;
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Failures are values, never exceptions: `expired`, `bad_signature`,
|
|
31
|
+
`wrong_issuer`, `wrong_audience`, `missing_scope`, `malformed`,
|
|
32
|
+
`jwks_unavailable`. The verifier never logs or echoes the token. Accepted
|
|
33
|
+
algorithms are `RS256` and `ES256`; clock tolerance is 30s.
|
|
34
|
+
|
|
35
|
+
## Sign (issuer only)
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { signMachineToken } from "@zuiio/m2m";
|
|
39
|
+
const token = await signMachineToken(
|
|
40
|
+
{ clientId: "svc-alpha", audience: "agent-gateway", scope: "agent:invoke" },
|
|
41
|
+
{ signingKey: privateJwk },
|
|
42
|
+
);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`RS256`, claims `iss`/`sub` (`client:<id>`)/`aud`/`scope`/`iat`/`exp`/`jti`,
|
|
46
|
+
default issuer `https://id.zuiio.app`, one hour — identical to what Zuiio ID
|
|
47
|
+
mints today, derived `kid` included.
|
|
48
|
+
|
|
49
|
+
## JWKS host rule
|
|
50
|
+
|
|
51
|
+
`jwksUrl` must point at the **same single issuer host** you accept.
|
|
52
|
+
`https://id.zuiio.app` is the only default; there is no `id.zuiiotech.com`
|
|
53
|
+
fallback. Accepting the legacy `https://id.zuiiotech.com` issuer means passing
|
|
54
|
+
that host's JWKS explicitly — mixing one host's issuer with another's keys
|
|
55
|
+
fails closed.
|
|
56
|
+
|
|
57
|
+
## Migration
|
|
58
|
+
|
|
59
|
+
Delete the local `verifyM2MToken` and its JWKS cache; call `verifyMachineToken`
|
|
60
|
+
and switch on `result.ok`. Keep bearer/service-binding/auth layering in the service.
|
package/dist/claims.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claim shapes and runtime guards shared by the signer and the verifier.
|
|
3
|
+
*
|
|
4
|
+
* Zuiio ID mints `client_credentials` access tokens with a fixed claim set:
|
|
5
|
+
* `iss`, `sub` (`client:<client_id>`), `aud`, `scope`, `iat`, `exp`, `jti`.
|
|
6
|
+
* Anything else a token carries is passed through untouched.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/** Prefix Zuiio ID puts in front of the client id inside the `sub` claim. */
|
|
11
|
+
export declare const CLIENT_SUBJECT_PREFIX = "client:";
|
|
12
|
+
/** Claims carried by a Zuiio ID machine-to-machine access token. */
|
|
13
|
+
export interface MachineTokenClaims {
|
|
14
|
+
/** Issuer host that minted the token, e.g. `https://id.zuiio.app`. */
|
|
15
|
+
iss: string;
|
|
16
|
+
/** `client:<client_id>` — see {@link clientIdFromSubject}. */
|
|
17
|
+
sub: string;
|
|
18
|
+
/** Target service the token is scoped to, e.g. `agent-gateway`. */
|
|
19
|
+
aud: string | string[];
|
|
20
|
+
/** Space-delimited scopes granted to the client. */
|
|
21
|
+
scope?: string;
|
|
22
|
+
/** Issued at, seconds since the Unix epoch. */
|
|
23
|
+
iat: number;
|
|
24
|
+
/** Expiry, seconds since the Unix epoch. */
|
|
25
|
+
exp: number;
|
|
26
|
+
/** Unique token id (UUID v4) minted by Zuiio ID. */
|
|
27
|
+
jti?: string;
|
|
28
|
+
[claim: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Runtime guard for the claims {@link verifyMachineToken} requires before it
|
|
32
|
+
* trusts a payload. Structural only — signature, issuer, audience and time are
|
|
33
|
+
* checked by the verifier itself.
|
|
34
|
+
*
|
|
35
|
+
* Returns `false` for any claim set that could not have been minted by Zuiio
|
|
36
|
+
* ID, including an empty client id in `sub`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isMachineTokenClaims(value: unknown): value is MachineTokenClaims;
|
|
39
|
+
/**
|
|
40
|
+
* Client id carried by a token subject. `client:svc-alpha` and a bare
|
|
41
|
+
* `svc-alpha` both resolve to `svc-alpha`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function clientIdFromSubject(subject: string): string;
|
|
44
|
+
/** Scopes granted by a claim set, split on whitespace. */
|
|
45
|
+
export declare function tokenScopes(claims: Pick<MachineTokenClaims, "scope">): string[];
|
|
46
|
+
/** Whether the claim set grants `scope` as one of its space-delimited scopes. */
|
|
47
|
+
export declare function claimsHaveScope(claims: Pick<MachineTokenClaims, "scope">, scope: string): boolean;
|
|
48
|
+
//# sourceMappingURL=claims.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claims.d.ts","sourceRoot":"","sources":["../src/claims.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,qBAAqB,YAAY,CAAC;AAE/C,oEAAoE;AACpE,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,8DAA8D;IAC9D,GAAG,EAAE,MAAM,CAAC;IACZ,mEAAmE;IACnE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACvB,oDAAoD;IACpD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,oDAAoD;IACpD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAiBD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,kBAAkB,CAc7B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAI3D;AAED,0DAA0D;AAC1D,wBAAgB,WAAW,CACzB,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,GACxC,MAAM,EAAE,CAIV;AAED,iFAAiF;AACjF,wBAAgB,eAAe,CAC7B,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,EACzC,KAAK,EAAE,MAAM,GACZ,OAAO,CAET"}
|
package/dist/claims.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claim shapes and runtime guards shared by the signer and the verifier.
|
|
3
|
+
*
|
|
4
|
+
* Zuiio ID mints `client_credentials` access tokens with a fixed claim set:
|
|
5
|
+
* `iss`, `sub` (`client:<client_id>`), `aud`, `scope`, `iat`, `exp`, `jti`.
|
|
6
|
+
* Anything else a token carries is passed through untouched.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/** Prefix Zuiio ID puts in front of the client id inside the `sub` claim. */
|
|
11
|
+
export const CLIENT_SUBJECT_PREFIX = "client:";
|
|
12
|
+
function isNonEmptyString(value) {
|
|
13
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
14
|
+
}
|
|
15
|
+
function isSecond(value) {
|
|
16
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
17
|
+
}
|
|
18
|
+
function isAudience(value) {
|
|
19
|
+
if (isNonEmptyString(value))
|
|
20
|
+
return true;
|
|
21
|
+
return (Array.isArray(value) && value.length > 0 && value.every(isNonEmptyString));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Runtime guard for the claims {@link verifyMachineToken} requires before it
|
|
25
|
+
* trusts a payload. Structural only — signature, issuer, audience and time are
|
|
26
|
+
* checked by the verifier itself.
|
|
27
|
+
*
|
|
28
|
+
* Returns `false` for any claim set that could not have been minted by Zuiio
|
|
29
|
+
* ID, including an empty client id in `sub`.
|
|
30
|
+
*/
|
|
31
|
+
export function isMachineTokenClaims(value) {
|
|
32
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const claims = value;
|
|
36
|
+
if (!isNonEmptyString(claims.iss))
|
|
37
|
+
return false;
|
|
38
|
+
if (!isNonEmptyString(claims.sub))
|
|
39
|
+
return false;
|
|
40
|
+
if (!isAudience(claims.aud))
|
|
41
|
+
return false;
|
|
42
|
+
if (!isSecond(claims.iat) || !isSecond(claims.exp))
|
|
43
|
+
return false;
|
|
44
|
+
if (claims.exp <= claims.iat)
|
|
45
|
+
return false;
|
|
46
|
+
if (claims.scope !== undefined && typeof claims.scope !== "string")
|
|
47
|
+
return false;
|
|
48
|
+
if (claims.jti !== undefined && typeof claims.jti !== "string")
|
|
49
|
+
return false;
|
|
50
|
+
return clientIdFromSubject(claims.sub).length > 0;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Client id carried by a token subject. `client:svc-alpha` and a bare
|
|
54
|
+
* `svc-alpha` both resolve to `svc-alpha`.
|
|
55
|
+
*/
|
|
56
|
+
export function clientIdFromSubject(subject) {
|
|
57
|
+
return subject.startsWith(CLIENT_SUBJECT_PREFIX)
|
|
58
|
+
? subject.slice(CLIENT_SUBJECT_PREFIX.length)
|
|
59
|
+
: subject;
|
|
60
|
+
}
|
|
61
|
+
/** Scopes granted by a claim set, split on whitespace. */
|
|
62
|
+
export function tokenScopes(claims) {
|
|
63
|
+
return typeof claims.scope === "string"
|
|
64
|
+
? claims.scope.split(/\s+/).filter(Boolean)
|
|
65
|
+
: [];
|
|
66
|
+
}
|
|
67
|
+
/** Whether the claim set grants `scope` as one of its space-delimited scopes. */
|
|
68
|
+
export function claimsHaveScope(claims, scope) {
|
|
69
|
+
return tokenScopes(claims).includes(scope);
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=claims.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claims.js","sourceRoot":"","sources":["../src/claims.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAS,CAAC;AAqB/C,SAAS,gBAAgB,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AAS,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ;QAChE,OAAO,KAAK,CAAC;IACf,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC7E,OAAO,mBAAmB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACpD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,OAAO,OAAO,CAAC,UAAU,CAAC,qBAAqB,CAAC;QAC9C,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,MAAM,CAAC;QAC7C,CAAC,CAAC,OAAO,CAAC;AACd,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,WAAW,CACzB,MAAyC;IAEzC,OAAO,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ;QACrC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;QAC3C,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,eAAe,CAC7B,MAAyC,EACzC,KAAa;IAEb,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@zuiio/m2m` — one machine-to-machine JWT implementation for the Zuiio
|
|
3
|
+
* ecosystem: {@link signMachineToken} on the issuer side and
|
|
4
|
+
* {@link verifyMachineToken} on every consuming service.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
export { CLIENT_SUBJECT_PREFIX, claimsHaveScope, clientIdFromSubject, isMachineTokenClaims, type MachineTokenClaims, tokenScopes, } from "./claims";
|
|
9
|
+
export { DEFAULT_ISSUER, DEFAULT_TTL_SECONDS, deriveMachineKeyId, type MachineSigningKey, type MachineTokenRequest, SIGNING_ALGORITHM, type SignMachineTokenOptions, signMachineToken, } from "./sign";
|
|
10
|
+
export { clearJwksCache, DEFAULT_ALGORITHMS, DEFAULT_ALLOWED_ISSUERS, DEFAULT_CLOCK_TOLERANCE_SECONDS, DEFAULT_JWKS_CACHE_TTL_MS, DEFAULT_JWKS_URL, type MachineTokenFailure, type MachineTokenResult, type VerifyMachineTokenOptions, verifyMachineToken, } from "./verify";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,iBAAiB,EACjB,KAAK,uBAAuB,EAC5B,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,+BAA+B,EAC/B,yBAAyB,EACzB,gBAAgB,EAChB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,kBAAkB,GACnB,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@zuiio/m2m` — one machine-to-machine JWT implementation for the Zuiio
|
|
3
|
+
* ecosystem: {@link signMachineToken} on the issuer side and
|
|
4
|
+
* {@link verifyMachineToken} on every consuming service.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
export { CLIENT_SUBJECT_PREFIX, claimsHaveScope, clientIdFromSubject, isMachineTokenClaims, tokenScopes, } from "./claims";
|
|
9
|
+
export { DEFAULT_ISSUER, DEFAULT_TTL_SECONDS, deriveMachineKeyId, SIGNING_ALGORITHM, signMachineToken, } from "./sign";
|
|
10
|
+
export { clearJwksCache, DEFAULT_ALGORITHMS, DEFAULT_ALLOWED_ISSUERS, DEFAULT_CLOCK_TOLERANCE_SECONDS, DEFAULT_JWKS_CACHE_TTL_MS, DEFAULT_JWKS_URL, verifyMachineToken, } from "./verify";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EAEpB,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAGlB,iBAAiB,EAEjB,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,+BAA+B,EAC/B,yBAAyB,EACzB,gBAAgB,EAIhB,kBAAkB,GACnB,MAAM,UAAU,CAAC"}
|
package/dist/sign.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Issuer side of Zuiio ID machine tokens.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors what `zuiio-id` mints today byte for byte: `RS256`, header
|
|
5
|
+
* `{ alg, typ: "JWT", kid }`, claims `{ iss, sub, aud, scope, iat, exp, jti }`,
|
|
6
|
+
* `sub` prefixed with `client:`, default issuer `https://id.zuiio.app`, one hour
|
|
7
|
+
* of validity. The `kid` is derived from the RSA public modulus the same way,
|
|
8
|
+
* so a JWKS published by either side matches.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/** Algorithm Zuiio ID signs machine tokens with. */
|
|
13
|
+
export declare const SIGNING_ALGORITHM = "RS256";
|
|
14
|
+
/** Issuer Zuiio ID mints under. */
|
|
15
|
+
export declare const DEFAULT_ISSUER = "https://id.zuiio.app";
|
|
16
|
+
/** Token lifetime Zuiio ID hands out, in seconds. */
|
|
17
|
+
export declare const DEFAULT_TTL_SECONDS = 3600;
|
|
18
|
+
/** Claims the caller supplies; the signer fills in `iss`, `sub`, `iat`, `exp`, `jti`. */
|
|
19
|
+
export interface MachineTokenRequest {
|
|
20
|
+
/** Registered client id; becomes `sub: "client:<clientId>"`. */
|
|
21
|
+
clientId: string;
|
|
22
|
+
/** Target service the token is issued for. */
|
|
23
|
+
audience: string;
|
|
24
|
+
/** Space-delimited scopes granted to the client. */
|
|
25
|
+
scope?: string;
|
|
26
|
+
/** Issuer host. Defaults to {@link DEFAULT_ISSUER}. */
|
|
27
|
+
issuer?: string;
|
|
28
|
+
/** Lifetime in seconds. Defaults to {@link DEFAULT_TTL_SECONDS}. */
|
|
29
|
+
expiresInSeconds?: number;
|
|
30
|
+
}
|
|
31
|
+
/** RSA private key used to sign, as a `CryptoKey` or a private JWK. */
|
|
32
|
+
export type MachineSigningKey = CryptoKey | JsonWebKey;
|
|
33
|
+
/** Options for {@link signMachineToken}. */
|
|
34
|
+
export interface SignMachineTokenOptions {
|
|
35
|
+
/** RSA private key. Must be `RS256`-capable. */
|
|
36
|
+
signingKey: MachineSigningKey;
|
|
37
|
+
/**
|
|
38
|
+
* Key id placed in the JWT header. Defaults to the id derived from the key
|
|
39
|
+
* (see {@link deriveMachineKeyId}); keys without an RSA modulus carry no
|
|
40
|
+
* `kid` unless one is given here.
|
|
41
|
+
*/
|
|
42
|
+
kid?: string;
|
|
43
|
+
/** Issued-at override, seconds since the epoch. Defaults to now. */
|
|
44
|
+
now?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Stable key id for a signing key, identical to the `kid` Zuiio ID publishes on
|
|
48
|
+
* its JWKS: the first 22 base64url characters of `SHA-256("<n>.<e>")`.
|
|
49
|
+
*
|
|
50
|
+
* Returns `undefined` for keys without an RSA public modulus (`CryptoKey`
|
|
51
|
+
* handles and EC keys), in which case tokens are signed without a `kid` and the
|
|
52
|
+
* verifier falls back to algorithm-based key selection.
|
|
53
|
+
*/
|
|
54
|
+
export declare function deriveMachineKeyId(signingKey: MachineSigningKey): Promise<string | undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* Mints an `RS256` machine token for a registered client.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const token = await signMachineToken(
|
|
61
|
+
* { clientId: "svc-alpha", audience: "agent-gateway", scope: "agent:invoke" },
|
|
62
|
+
* { signingKey: privateJwk },
|
|
63
|
+
* );
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function signMachineToken(claims: MachineTokenRequest, options: SignMachineTokenOptions): Promise<string>;
|
|
67
|
+
//# sourceMappingURL=sign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../src/sign.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,oDAAoD;AACpD,eAAO,MAAM,iBAAiB,UAAU,CAAC;AAEzC,mCAAmC;AACnC,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAErD,qDAAqD;AACrD,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAKxC,yFAAyF;AACzF,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,uEAAuE;AACvE,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,UAAU,CAAC;AAEvD,4CAA4C;AAC5C,MAAM,WAAW,uBAAuB;IACtC,gDAAgD;IAChD,UAAU,EAAE,iBAAiB,CAAC;IAC9B;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AA6BD;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,iBAAiB,GAC5B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAM7B;AASD;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,CAAC,CAmCjB"}
|
package/dist/sign.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Issuer side of Zuiio ID machine tokens.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors what `zuiio-id` mints today byte for byte: `RS256`, header
|
|
5
|
+
* `{ alg, typ: "JWT", kid }`, claims `{ iss, sub, aud, scope, iat, exp, jti }`,
|
|
6
|
+
* `sub` prefixed with `client:`, default issuer `https://id.zuiio.app`, one hour
|
|
7
|
+
* of validity. The `kid` is derived from the RSA public modulus the same way,
|
|
8
|
+
* so a JWKS published by either side matches.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { SignJWT } from "jose";
|
|
13
|
+
import { CLIENT_SUBJECT_PREFIX } from "./claims";
|
|
14
|
+
/** Algorithm Zuiio ID signs machine tokens with. */
|
|
15
|
+
export const SIGNING_ALGORITHM = "RS256";
|
|
16
|
+
/** Issuer Zuiio ID mints under. */
|
|
17
|
+
export const DEFAULT_ISSUER = "https://id.zuiio.app";
|
|
18
|
+
/** Token lifetime Zuiio ID hands out, in seconds. */
|
|
19
|
+
export const DEFAULT_TTL_SECONDS = 3600;
|
|
20
|
+
const BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
21
|
+
function base64UrlEncode(bytes) {
|
|
22
|
+
let out = "";
|
|
23
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
24
|
+
const b0 = bytes[i] ?? 0;
|
|
25
|
+
const b1 = bytes[i + 1];
|
|
26
|
+
const b2 = bytes[i + 2];
|
|
27
|
+
out += BASE64URL_ALPHABET[b0 >> 2];
|
|
28
|
+
out += BASE64URL_ALPHABET[((b0 & 0x03) << 4) | ((b1 ?? 0) >> 4)];
|
|
29
|
+
if (b1 === undefined)
|
|
30
|
+
break;
|
|
31
|
+
out += BASE64URL_ALPHABET[((b1 & 0x0f) << 2) | ((b2 ?? 0) >> 6)];
|
|
32
|
+
if (b2 === undefined)
|
|
33
|
+
break;
|
|
34
|
+
out += BASE64URL_ALPHABET[b2 & 0x3f];
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
function rsaPublicPart(key) {
|
|
39
|
+
if (typeof key !== "object" || key === null || !("kty" in key))
|
|
40
|
+
return null;
|
|
41
|
+
if (key.kty !== "RSA")
|
|
42
|
+
return null;
|
|
43
|
+
const { n, e } = key;
|
|
44
|
+
if (typeof n !== "string" || typeof e !== "string")
|
|
45
|
+
return null;
|
|
46
|
+
if (n.length === 0 || e.length === 0)
|
|
47
|
+
return null;
|
|
48
|
+
return { n, e };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Stable key id for a signing key, identical to the `kid` Zuiio ID publishes on
|
|
52
|
+
* its JWKS: the first 22 base64url characters of `SHA-256("<n>.<e>")`.
|
|
53
|
+
*
|
|
54
|
+
* Returns `undefined` for keys without an RSA public modulus (`CryptoKey`
|
|
55
|
+
* handles and EC keys), in which case tokens are signed without a `kid` and the
|
|
56
|
+
* verifier falls back to algorithm-based key selection.
|
|
57
|
+
*/
|
|
58
|
+
export async function deriveMachineKeyId(signingKey) {
|
|
59
|
+
const publicPart = rsaPublicPart(signingKey);
|
|
60
|
+
if (!publicPart)
|
|
61
|
+
return undefined;
|
|
62
|
+
const material = new TextEncoder().encode(`${publicPart.n}.${publicPart.e}`);
|
|
63
|
+
const digest = await crypto.subtle.digest("SHA-256", material);
|
|
64
|
+
return base64UrlEncode(new Uint8Array(digest)).slice(0, 22);
|
|
65
|
+
}
|
|
66
|
+
function assertNonEmpty(value, field) {
|
|
67
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
68
|
+
throw new TypeError(`signMachineToken: ${field} is required`);
|
|
69
|
+
}
|
|
70
|
+
return value.trim();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Mints an `RS256` machine token for a registered client.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const token = await signMachineToken(
|
|
78
|
+
* { clientId: "svc-alpha", audience: "agent-gateway", scope: "agent:invoke" },
|
|
79
|
+
* { signingKey: privateJwk },
|
|
80
|
+
* );
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export async function signMachineToken(claims, options) {
|
|
84
|
+
const clientId = assertNonEmpty(claims.clientId, "clientId");
|
|
85
|
+
const audience = assertNonEmpty(claims.audience, "audience");
|
|
86
|
+
const ttlSeconds = claims.expiresInSeconds ?? DEFAULT_TTL_SECONDS;
|
|
87
|
+
if (!Number.isFinite(ttlSeconds) || ttlSeconds <= 0) {
|
|
88
|
+
throw new TypeError("signMachineToken: expiresInSeconds must be a positive number");
|
|
89
|
+
}
|
|
90
|
+
if (!options.signingKey) {
|
|
91
|
+
throw new TypeError("signMachineToken: signingKey is required");
|
|
92
|
+
}
|
|
93
|
+
const issuedAt = Math.floor(options.now ?? Date.now() / 1000);
|
|
94
|
+
const kid = options.kid ?? (await deriveMachineKeyId(options.signingKey));
|
|
95
|
+
const payload = {
|
|
96
|
+
iss: claims.issuer?.trim() || DEFAULT_ISSUER,
|
|
97
|
+
sub: `${CLIENT_SUBJECT_PREFIX}${clientId}`,
|
|
98
|
+
aud: audience,
|
|
99
|
+
iat: issuedAt,
|
|
100
|
+
exp: issuedAt + Math.floor(ttlSeconds),
|
|
101
|
+
jti: crypto.randomUUID(),
|
|
102
|
+
};
|
|
103
|
+
if (claims.scope !== undefined) {
|
|
104
|
+
payload.scope = claims.scope;
|
|
105
|
+
}
|
|
106
|
+
return new SignJWT(payload)
|
|
107
|
+
.setProtectedHeader({
|
|
108
|
+
alg: SIGNING_ALGORITHM,
|
|
109
|
+
typ: "JWT",
|
|
110
|
+
...(kid ? { kid } : {}),
|
|
111
|
+
})
|
|
112
|
+
.sign(options.signingKey);
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=sign.js.map
|
package/dist/sign.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.js","sourceRoot":"","sources":["../src/sign.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEjD,oDAAoD;AACpD,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAEzC,mCAAmC;AACnC,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAErD,qDAAqD;AACrD,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAExC,MAAM,kBAAkB,GACtB,kEAAkE,CAAC;AAiCrE,SAAS,eAAe,CAAC,KAAiB;IACxC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,C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|
|
4
|
+
* Every failure is reported as a value, never as an exception: callers switch
|
|
5
|
+
* on {@link MachineTokenResult.ok}. The token itself is never logged and never
|
|
6
|
+
* echoed back in a failure reason.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { type FetchImplementation, type JWTVerifyGetKey } from "jose";
|
|
11
|
+
import { type MachineTokenClaims } from "./claims";
|
|
12
|
+
/** Issuer hosts Zuiio ID has published tokens under. */
|
|
13
|
+
export declare const DEFAULT_ALLOWED_ISSUERS: readonly string[];
|
|
14
|
+
/** JWKS endpoint of the default issuer. */
|
|
15
|
+
export declare const DEFAULT_JWKS_URL = "https://id.zuiio.app/api/oauth/jwks";
|
|
16
|
+
/** Asymmetric algorithms Zuiio ID issues. Symmetric and `none` are never allowed. */
|
|
17
|
+
export declare const DEFAULT_ALGORITHMS: readonly string[];
|
|
18
|
+
/** Clock skew tolerated on `exp`, `iat` and `nbf`, in seconds. */
|
|
19
|
+
export declare const DEFAULT_CLOCK_TOLERANCE_SECONDS = 30;
|
|
20
|
+
/** How long a downloaded JWKS is reused before it is fetched again, in milliseconds. */
|
|
21
|
+
export declare const DEFAULT_JWKS_CACHE_TTL_MS = 3600000;
|
|
22
|
+
/** Why a token was rejected. */
|
|
23
|
+
export type MachineTokenFailure = "expired" | "bad_signature" | "wrong_issuer" | "wrong_audience" | "missing_scope" | "malformed" | "jwks_unavailable";
|
|
24
|
+
/** Discriminated result of {@link verifyMachineToken}. */
|
|
25
|
+
export type MachineTokenResult = {
|
|
26
|
+
ok: true;
|
|
27
|
+
claims: MachineTokenClaims;
|
|
28
|
+
clientId: string;
|
|
29
|
+
} | {
|
|
30
|
+
ok: false;
|
|
31
|
+
reason: MachineTokenFailure;
|
|
32
|
+
};
|
|
33
|
+
/** Options for {@link verifyMachineToken}. */
|
|
34
|
+
export interface VerifyMachineTokenOptions {
|
|
35
|
+
/** Audience this service accepts tokens for. Required. */
|
|
36
|
+
expectedAudience: string;
|
|
37
|
+
/** Issuer hosts to accept. Defaults to {@link DEFAULT_ALLOWED_ISSUERS}. */
|
|
38
|
+
allowedIssuers?: readonly string[];
|
|
39
|
+
/** Scope the caller must hold, e.g. `agent:invoke`. */
|
|
40
|
+
requiredScope?: string;
|
|
41
|
+
/** Accepted signing algorithms. Defaults to {@link DEFAULT_ALGORITHMS}. */
|
|
42
|
+
algorithms?: readonly string[];
|
|
43
|
+
/** JWKS endpoint. Defaults to {@link DEFAULT_JWKS_URL}. */
|
|
44
|
+
jwksUrl?: string;
|
|
45
|
+
/** Clock skew allowance in seconds. Defaults to {@link DEFAULT_CLOCK_TOLERANCE_SECONDS}. */
|
|
46
|
+
clockToleranceSeconds?: number;
|
|
47
|
+
/** JWKS reuse window in milliseconds. Defaults to {@link DEFAULT_JWKS_CACHE_TTL_MS}. */
|
|
48
|
+
jwksCacheTtlMs?: number;
|
|
49
|
+
/** JWKS request timeout in milliseconds. */
|
|
50
|
+
jwksTimeoutMs?: number;
|
|
51
|
+
/** Pre-built key resolver, bypassing the remote JWKS cache. */
|
|
52
|
+
jwks?: JWTVerifyGetKey;
|
|
53
|
+
/** `fetch` used to download the JWKS — bindings and tests. */
|
|
54
|
+
fetchImpl?: FetchImplementation;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Drops every cached remote JWKS. Only needed by tests and key-rotation
|
|
58
|
+
* tooling; production code relies on the TTL.
|
|
59
|
+
*/
|
|
60
|
+
export declare function clearJwksCache(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Verifies a Zuiio ID machine token against the issuer's JWKS.
|
|
63
|
+
*
|
|
64
|
+
* Checks signature, `iss`, `aud`, `exp`/`iat` (with clock tolerance), the
|
|
65
|
+
* algorithm allowlist, the required claim shape, then the optional scope.
|
|
66
|
+
* Never throws for a bad token — see {@link MachineTokenFailure}.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const result = await verifyMachineToken(bearer, {
|
|
71
|
+
* expectedAudience: "agent-gateway",
|
|
72
|
+
* requiredScope: "agent:invoke",
|
|
73
|
+
* });
|
|
74
|
+
* if (!result.ok) return new Response(result.reason, { status: 401 });
|
|
75
|
+
* const { clientId, claims } = result;
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function verifyMachineToken(token: string, options: VerifyMachineTokenOptions): Promise<MachineTokenResult>;
|
|
79
|
+
//# sourceMappingURL=verify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAIL,KAAK,mBAAmB,EACxB,KAAK,eAAe,EAErB,MAAM,MAAM,CAAC;AACd,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,UAAU,CAAC;AAElB,wDAAwD;AACxD,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EAGpD,CAAC;AAEF,2CAA2C;AAC3C,eAAO,MAAM,gBAAgB,wCAAwC,CAAC;AAEtE,qFAAqF;AACrF,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAAuB,CAAC;AAExE,kEAAkE;AAClE,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAElD,wFAAwF;AACxF,eAAO,MAAM,yBAAyB,UAAY,CAAC;AAKnD,gCAAgC;AAChC,MAAM,MAAM,mBAAmB,GAC3B,SAAS,GACT,eAAe,GACf,cAAc,GACd,gBAAgB,GAChB,eAAe,GACf,WAAW,GACX,kBAAkB,CAAC;AAEvB,0DAA0D;AAC1D,MAAM,MAAM,kBAAkB,GAC1B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,kBAAkB,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAE/C,8CAA8C;AAC9C,MAAM,WAAW,yBAAyB;IACxC,0DAA0D;IAC1D,gBAAgB,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,uDAAuD;IACvD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4FAA4F;IAC5F,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,wFAAwF;IACxF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4CAA4C;IAC5C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+DAA+D;IAC/D,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,mBAAmB,CAAC;CACjC;AAWD;;;GAGG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAuFD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,kBAAkB,CAAC,CA4D7B"}
|
package/dist/verify.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verification of Zuiio ID machine-to-machine tokens.
|
|
3
|
+
*
|
|
4
|
+
* Every failure is reported as a value, never as an exception: callers switch
|
|
5
|
+
* on {@link MachineTokenResult.ok}. The token itself is never logged and never
|
|
6
|
+
* echoed back in a failure reason.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { createRemoteJWKSet, customFetch, errors, jwtVerify, } from "jose";
|
|
11
|
+
import { claimsHaveScope, clientIdFromSubject, isMachineTokenClaims, } from "./claims";
|
|
12
|
+
/** Issuer hosts Zuiio ID has published tokens under. */
|
|
13
|
+
export const DEFAULT_ALLOWED_ISSUERS = [
|
|
14
|
+
"https://id.zuiio.app",
|
|
15
|
+
"https://id.zuiiotech.com",
|
|
16
|
+
];
|
|
17
|
+
/** JWKS endpoint of the default issuer. */
|
|
18
|
+
export const DEFAULT_JWKS_URL = "https://id.zuiio.app/api/oauth/jwks";
|
|
19
|
+
/** Asymmetric algorithms Zuiio ID issues. Symmetric and `none` are never allowed. */
|
|
20
|
+
export const DEFAULT_ALGORITHMS = ["RS256", "ES256"];
|
|
21
|
+
/** Clock skew tolerated on `exp`, `iat` and `nbf`, in seconds. */
|
|
22
|
+
export const DEFAULT_CLOCK_TOLERANCE_SECONDS = 30;
|
|
23
|
+
/** How long a downloaded JWKS is reused before it is fetched again, in milliseconds. */
|
|
24
|
+
export const DEFAULT_JWKS_CACHE_TTL_MS = 3_600_000;
|
|
25
|
+
const JWKS_COOLDOWN_MS = 30_000;
|
|
26
|
+
const JWKS_TIMEOUT_MS = 5_000;
|
|
27
|
+
const remoteJwksCache = new Map();
|
|
28
|
+
/**
|
|
29
|
+
* Drops every cached remote JWKS. Only needed by tests and key-rotation
|
|
30
|
+
* tooling; production code relies on the TTL.
|
|
31
|
+
*/
|
|
32
|
+
export function clearJwksCache() {
|
|
33
|
+
remoteJwksCache.clear();
|
|
34
|
+
}
|
|
35
|
+
function remoteJwks(jwksUrl, ttlMs, timeoutMs, fetchImpl) {
|
|
36
|
+
const now = Date.now();
|
|
37
|
+
const cached = remoteJwksCache.get(jwksUrl);
|
|
38
|
+
if (cached &&
|
|
39
|
+
cached.ttlMs === ttlMs &&
|
|
40
|
+
cached.fetchImpl === fetchImpl &&
|
|
41
|
+
now - cached.createdAt < ttlMs) {
|
|
42
|
+
return cached.getKey;
|
|
43
|
+
}
|
|
44
|
+
const getKey = createRemoteJWKSet(new URL(jwksUrl), {
|
|
45
|
+
cacheMaxAge: ttlMs,
|
|
46
|
+
cooldownDuration: JWKS_COOLDOWN_MS,
|
|
47
|
+
timeoutDuration: timeoutMs,
|
|
48
|
+
...(fetchImpl ? { [customFetch]: fetchImpl } : {}),
|
|
49
|
+
});
|
|
50
|
+
remoteJwksCache.set(jwksUrl, { getKey, createdAt: now, ttlMs, fetchImpl });
|
|
51
|
+
return getKey;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Wraps a resolver so a JWKS that cannot be downloaded or parsed is reported as
|
|
55
|
+
* `jwks_unavailable` instead of a signature failure. "No matching key" stays a
|
|
56
|
+
* signature failure — the key set was available, the token just does not
|
|
57
|
+
* belong to it.
|
|
58
|
+
*/
|
|
59
|
+
function trackJwks(getKey) {
|
|
60
|
+
let failed = false;
|
|
61
|
+
const tracked = async (protectedHeader, token) => {
|
|
62
|
+
try {
|
|
63
|
+
return await getKey(protectedHeader, token);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (!(error instanceof errors.JWKSNoMatchingKey) &&
|
|
67
|
+
!(error instanceof errors.JWKSMultipleMatchingKeys)) {
|
|
68
|
+
failed = true;
|
|
69
|
+
}
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
return { getKey: tracked, unavailable: () => failed };
|
|
74
|
+
}
|
|
75
|
+
function classify(error, jwksUnavailable) {
|
|
76
|
+
if (jwksUnavailable)
|
|
77
|
+
return "jwks_unavailable";
|
|
78
|
+
if (error instanceof errors.JWTExpired)
|
|
79
|
+
return "expired";
|
|
80
|
+
if (error instanceof errors.JWTClaimValidationFailed) {
|
|
81
|
+
if (error.claim === "aud")
|
|
82
|
+
return "wrong_audience";
|
|
83
|
+
if (error.claim === "iss")
|
|
84
|
+
return "wrong_issuer";
|
|
85
|
+
if (error.claim === "exp")
|
|
86
|
+
return "expired";
|
|
87
|
+
return "malformed";
|
|
88
|
+
}
|
|
89
|
+
if (error instanceof errors.JOSEError) {
|
|
90
|
+
switch (error.code) {
|
|
91
|
+
case "ERR_JWKS_NO_MATCHING_KEY":
|
|
92
|
+
case "ERR_JOSE_ALG_NOT_ALLOWED":
|
|
93
|
+
case "ERR_JWS_SIGNATURE_VERIFICATION_FAILED":
|
|
94
|
+
return "bad_signature";
|
|
95
|
+
case "ERR_JWKS_TIMEOUT":
|
|
96
|
+
case "ERR_JWKS_INVALID":
|
|
97
|
+
return "jwks_unavailable";
|
|
98
|
+
default:
|
|
99
|
+
return "malformed";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return "malformed";
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Verifies a Zuiio ID machine token against the issuer's JWKS.
|
|
106
|
+
*
|
|
107
|
+
* Checks signature, `iss`, `aud`, `exp`/`iat` (with clock tolerance), the
|
|
108
|
+
* algorithm allowlist, the required claim shape, then the optional scope.
|
|
109
|
+
* Never throws for a bad token — see {@link MachineTokenFailure}.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const result = await verifyMachineToken(bearer, {
|
|
114
|
+
* expectedAudience: "agent-gateway",
|
|
115
|
+
* requiredScope: "agent:invoke",
|
|
116
|
+
* });
|
|
117
|
+
* if (!result.ok) return new Response(result.reason, { status: 401 });
|
|
118
|
+
* const { clientId, claims } = result;
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export async function verifyMachineToken(token, options) {
|
|
122
|
+
if (typeof token !== "string" || token.length === 0) {
|
|
123
|
+
return { ok: false, reason: "malformed" };
|
|
124
|
+
}
|
|
125
|
+
const expectedAudience = options.expectedAudience?.trim();
|
|
126
|
+
if (!expectedAudience) {
|
|
127
|
+
throw new TypeError("verifyMachineToken: options.expectedAudience is required");
|
|
128
|
+
}
|
|
129
|
+
const allowedIssuers = options.allowedIssuers && options.allowedIssuers.length > 0
|
|
130
|
+
? [...options.allowedIssuers]
|
|
131
|
+
: [...DEFAULT_ALLOWED_ISSUERS];
|
|
132
|
+
let resolver;
|
|
133
|
+
try {
|
|
134
|
+
resolver =
|
|
135
|
+
options.jwks ??
|
|
136
|
+
remoteJwks(options.jwksUrl ?? DEFAULT_JWKS_URL, options.jwksCacheTtlMs ?? DEFAULT_JWKS_CACHE_TTL_MS, options.jwksTimeoutMs ?? JWKS_TIMEOUT_MS, options.fetchImpl);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return { ok: false, reason: "jwks_unavailable" };
|
|
140
|
+
}
|
|
141
|
+
const jwks = trackJwks(resolver);
|
|
142
|
+
let payload;
|
|
143
|
+
try {
|
|
144
|
+
const verified = await jwtVerify(token, jwks.getKey, {
|
|
145
|
+
issuer: allowedIssuers,
|
|
146
|
+
audience: expectedAudience,
|
|
147
|
+
algorithms: [...(options.algorithms ?? DEFAULT_ALGORITHMS)],
|
|
148
|
+
clockTolerance: options.clockToleranceSeconds ?? DEFAULT_CLOCK_TOLERANCE_SECONDS,
|
|
149
|
+
});
|
|
150
|
+
payload = verified.payload;
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
return { ok: false, reason: classify(error, jwks.unavailable()) };
|
|
154
|
+
}
|
|
155
|
+
if (!isMachineTokenClaims(payload)) {
|
|
156
|
+
return { ok: false, reason: "malformed" };
|
|
157
|
+
}
|
|
158
|
+
if (options.requiredScope &&
|
|
159
|
+
!claimsHaveScope(payload, options.requiredScope)) {
|
|
160
|
+
return { ok: false, reason: "missing_scope" };
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
ok: true,
|
|
164
|
+
claims: payload,
|
|
165
|
+
clientId: clientIdFromSubject(payload.sub),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=verify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,MAAM,EAGN,SAAS,GACV,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,oBAAoB,GAErB,MAAM,UAAU,CAAC;AAElB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|
{
|
|
2
2
|
"name": "@zuiio/m2m",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Machine-to-machine JWT signing and JWKS verification for Zuiio ID",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"jose": "catalog:"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/themuuln/zuiio.git",
|
|
13
|
+
"directory": "packages/m2m"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"registry": "https://registry.npmjs.org",
|
|
29
|
+
"access": "public"
|
|
30
|
+
}
|
|
31
|
+
}
|