@leed-ai/git-gateway-auth-jwt 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.
Files changed (40) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +24 -2
  3. package/dist/base64url.d.ts +5 -0
  4. package/dist/base64url.js +17 -0
  5. package/dist/base64url.js.map +1 -0
  6. package/dist/jwks-Bk8zq_xG.d.ts +48 -0
  7. package/dist/jwks-source.d.ts +30 -0
  8. package/dist/jwks-source.js +84 -0
  9. package/dist/jwks-source.js.map +1 -0
  10. package/dist/jwt-authenticator.d.ts +25 -0
  11. package/dist/jwt-authenticator.js +72 -0
  12. package/dist/jwt-authenticator.js.map +1 -0
  13. package/dist/jwt-verify.d.ts +18 -0
  14. package/dist/jwt-verify.js +157 -0
  15. package/dist/jwt-verify.js.map +1 -0
  16. package/dist/package-name.d.ts +3 -0
  17. package/dist/package-name.js +6 -0
  18. package/dist/package-name.js.map +1 -0
  19. package/dist/schemas/jwks.d.ts +2 -0
  20. package/dist/schemas/jwks.js +67 -0
  21. package/dist/schemas/jwks.js.map +1 -0
  22. package/dist/schemas/jwt-algorithm.d.ts +17 -0
  23. package/dist/schemas/jwt-algorithm.js +35 -0
  24. package/dist/schemas/jwt-algorithm.js.map +1 -0
  25. package/dist/schemas/jwt-authenticator-config.d.ts +41 -0
  26. package/dist/schemas/jwt-authenticator-config.js +57 -0
  27. package/dist/schemas/jwt-authenticator-config.js.map +1 -0
  28. package/dist/schemas/jwt-parts.d.ts +20 -0
  29. package/dist/schemas/jwt-parts.js +40 -0
  30. package/dist/schemas/jwt-parts.js.map +1 -0
  31. package/package.json +103 -4
  32. package/src/base64url.ts +16 -0
  33. package/src/jwks-source.ts +109 -0
  34. package/src/jwt-authenticator.ts +100 -0
  35. package/src/jwt-verify.ts +135 -0
  36. package/src/package-name.ts +4 -0
  37. package/src/schemas/jwks.ts +96 -0
  38. package/src/schemas/jwt-algorithm.ts +28 -0
  39. package/src/schemas/jwt-authenticator-config.ts +111 -0
  40. package/src/schemas/jwt-parts.ts +60 -0
@@ -0,0 +1,157 @@
1
+ import { decodeBase64Url } from "./base64url.js";
2
+ import { JwtClaims, JwtHeader } from "./schemas/jwt-parts.js";
3
+ // src/jwt-verify.ts
4
+ /** A base64url JSON segment, parsed. */
5
+ const segment = (part) => JSON.parse(new TextDecoder().decode(decodeBase64Url(part)));
6
+ /** Splits and parses a compact JWS JWT; null when it is not one. */
7
+ function decodeJwt(token) {
8
+ const parts = token.split(".");
9
+ if (parts.length !== 3) return null;
10
+ const [header = "", payload = "", signature = ""] = parts;
11
+ try {
12
+ const parsedHeader = JwtHeader.safeParse(segment(header));
13
+ const parsedClaims = JwtClaims.safeParse(segment(payload));
14
+ if (!parsedHeader.success || !parsedClaims.success) return null;
15
+ return {
16
+ header: parsedHeader.data,
17
+ claims: parsedClaims.data,
18
+ signingInput: new TextEncoder().encode(`${header}.${payload}`),
19
+ signature: decodeBase64Url(signature)
20
+ };
21
+ } catch {
22
+ return null;
23
+ }
24
+ }
25
+ function publicJwk(key) {
26
+ const jwk = {
27
+ kty: key.kty,
28
+ ext: true
29
+ };
30
+ for (const member of [
31
+ "n",
32
+ "e",
33
+ "crv",
34
+ "x",
35
+ "y"
36
+ ]) {
37
+ const value = key[member];
38
+ if (value !== void 0) jwk[member] = value;
39
+ }
40
+ return jwk;
41
+ }
42
+ const ALGORITHMS = {
43
+ RS256: {
44
+ kty: "RSA",
45
+ import: {
46
+ name: "RSASSA-PKCS1-v1_5",
47
+ hash: "SHA-256"
48
+ },
49
+ verify: { name: "RSASSA-PKCS1-v1_5" }
50
+ },
51
+ RS384: {
52
+ kty: "RSA",
53
+ import: {
54
+ name: "RSASSA-PKCS1-v1_5",
55
+ hash: "SHA-384"
56
+ },
57
+ verify: { name: "RSASSA-PKCS1-v1_5" }
58
+ },
59
+ RS512: {
60
+ kty: "RSA",
61
+ import: {
62
+ name: "RSASSA-PKCS1-v1_5",
63
+ hash: "SHA-512"
64
+ },
65
+ verify: { name: "RSASSA-PKCS1-v1_5" }
66
+ },
67
+ PS256: {
68
+ kty: "RSA",
69
+ import: {
70
+ name: "RSA-PSS",
71
+ hash: "SHA-256"
72
+ },
73
+ verify: {
74
+ name: "RSA-PSS",
75
+ saltLength: 32
76
+ }
77
+ },
78
+ PS384: {
79
+ kty: "RSA",
80
+ import: {
81
+ name: "RSA-PSS",
82
+ hash: "SHA-384"
83
+ },
84
+ verify: {
85
+ name: "RSA-PSS",
86
+ saltLength: 48
87
+ }
88
+ },
89
+ PS512: {
90
+ kty: "RSA",
91
+ import: {
92
+ name: "RSA-PSS",
93
+ hash: "SHA-512"
94
+ },
95
+ verify: {
96
+ name: "RSA-PSS",
97
+ saltLength: 64
98
+ }
99
+ },
100
+ ES256: {
101
+ kty: "EC",
102
+ import: {
103
+ name: "ECDSA",
104
+ namedCurve: "P-256"
105
+ },
106
+ verify: {
107
+ name: "ECDSA",
108
+ hash: "SHA-256"
109
+ }
110
+ },
111
+ ES384: {
112
+ kty: "EC",
113
+ import: {
114
+ name: "ECDSA",
115
+ namedCurve: "P-384"
116
+ },
117
+ verify: {
118
+ name: "ECDSA",
119
+ hash: "SHA-384"
120
+ }
121
+ },
122
+ EdDSA: {
123
+ kty: "OKP",
124
+ import: { name: "Ed25519" },
125
+ verify: { name: "Ed25519" }
126
+ },
127
+ Ed25519: {
128
+ kty: "OKP",
129
+ import: { name: "Ed25519" },
130
+ verify: { name: "Ed25519" }
131
+ }
132
+ };
133
+ /** The two names of EdDSA on Ed25519: the polymorphic "EdDSA" and the fully-specified "Ed25519". */
134
+ const OKP_NAMES = /* @__PURE__ */ new Set(["EdDSA", "Ed25519"]);
135
+ /** Whether `key` may verify a token signed with `algorithm` (key type, curve and any "alg"/"use" agree). */
136
+ function keyFits(key, algorithm) {
137
+ const spec = ALGORITHMS[algorithm];
138
+ if (key.kty !== spec.kty) return false;
139
+ if (key.alg !== void 0 && key.alg !== algorithm && !(OKP_NAMES.has(key.alg) && OKP_NAMES.has(algorithm))) return false;
140
+ if (key.use !== void 0 && key.use !== "sig") return false;
141
+ if (spec.import.namedCurve !== void 0 && key.crv !== spec.import.namedCurve) return false;
142
+ return !OKP_NAMES.has(algorithm) || key.crv === "Ed25519";
143
+ }
144
+ /** Verifies a decoded JWT's signature with one public key; false on any mismatch or import failure. */
145
+ async function verifySignature(jwt, algorithm, key) {
146
+ if (!keyFits(key, algorithm)) return false;
147
+ const spec = ALGORITHMS[algorithm];
148
+ try {
149
+ const imported = await crypto.subtle.importKey("jwk", publicJwk(key), spec.import, false, ["verify"]);
150
+ return await crypto.subtle.verify(spec.verify, imported, jwt.signature, jwt.signingInput);
151
+ } catch {
152
+ return false;
153
+ }
154
+ }
155
+ export { decodeJwt, keyFits, verifySignature };
156
+
157
+ //# sourceMappingURL=jwt-verify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-verify.js","names":[],"sources":["../src/jwt-verify.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { decodeBase64Url } from './base64url.ts';\nimport type { Jwk } from './schemas/jwks.ts';\nimport type { JwtAlgorithm } from './schemas/jwt-algorithm.ts';\nimport { JwtClaims, JwtHeader } from './schemas/jwt-parts.ts';\n\n/** A JWT split into its parts, the header and claims parsed but nothing verified yet. */\nexport interface DecodedJwt {\n readonly header: JwtHeader;\n readonly claims: JwtClaims;\n /** The bytes the signature covers: \"<header>.<payload>\" as sent. */\n readonly signingInput: Uint8Array;\n readonly signature: Uint8Array;\n}\n\n/** A base64url JSON segment, parsed. */\nconst segment = (part: string): unknown => JSON.parse(new TextDecoder().decode(decodeBase64Url(part)));\n\n/** Splits and parses a compact JWS JWT; null when it is not one. */\nexport function decodeJwt(token: string): DecodedJwt | null {\n const parts = token.split('.');\n if (parts.length !== 3) return null;\n const [header = '', payload = '', signature = ''] = parts;\n try {\n const parsedHeader = JwtHeader.safeParse(segment(header));\n const parsedClaims = JwtClaims.safeParse(segment(payload));\n if (!parsedHeader.success || !parsedClaims.success) return null;\n return {\n header: parsedHeader.data,\n claims: parsedClaims.data,\n signingInput: new TextEncoder().encode(`${header}.${payload}`),\n signature: decodeBase64Url(signature),\n };\n } catch {\n return null;\n }\n}\n\n/** Web Crypto parameters for importing a key and verifying with it. */\ninterface Algorithms {\n readonly kty: Jwk['kty'];\n readonly import: { readonly name: string; readonly hash?: string; readonly namedCurve?: string };\n readonly verify: { readonly name: string; readonly hash?: string; readonly saltLength?: number };\n}\n\n/** The public members of a key Web Crypto imports, without the ones the authenticator ignores. */\ninterface PublicJwk {\n kty: string;\n ext: boolean;\n n?: string;\n e?: string;\n crv?: string;\n x?: string;\n y?: string;\n}\n\nfunction publicJwk(key: Jwk): PublicJwk {\n const jwk: PublicJwk = { kty: key.kty, ext: true };\n for (const member of ['n', 'e', 'crv', 'x', 'y'] as const) {\n const value = key[member];\n if (value !== undefined) jwk[member] = value;\n }\n return jwk;\n}\n\nconst ALGORITHMS: Readonly<Record<JwtAlgorithm, Algorithms>> = {\n RS256: {\n kty: 'RSA',\n import: { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' },\n verify: { name: 'RSASSA-PKCS1-v1_5' },\n },\n RS384: {\n kty: 'RSA',\n import: { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-384' },\n verify: { name: 'RSASSA-PKCS1-v1_5' },\n },\n RS512: {\n kty: 'RSA',\n import: { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-512' },\n verify: { name: 'RSASSA-PKCS1-v1_5' },\n },\n PS256: {\n kty: 'RSA',\n import: { name: 'RSA-PSS', hash: 'SHA-256' },\n verify: { name: 'RSA-PSS', saltLength: 32 },\n },\n PS384: {\n kty: 'RSA',\n import: { name: 'RSA-PSS', hash: 'SHA-384' },\n verify: { name: 'RSA-PSS', saltLength: 48 },\n },\n PS512: {\n kty: 'RSA',\n import: { name: 'RSA-PSS', hash: 'SHA-512' },\n verify: { name: 'RSA-PSS', saltLength: 64 },\n },\n ES256: {\n kty: 'EC',\n import: { name: 'ECDSA', namedCurve: 'P-256' },\n verify: { name: 'ECDSA', hash: 'SHA-256' },\n },\n ES384: {\n kty: 'EC',\n import: { name: 'ECDSA', namedCurve: 'P-384' },\n verify: { name: 'ECDSA', hash: 'SHA-384' },\n },\n EdDSA: { kty: 'OKP', import: { name: 'Ed25519' }, verify: { name: 'Ed25519' } },\n Ed25519: { kty: 'OKP', import: { name: 'Ed25519' }, verify: { name: 'Ed25519' } },\n};\n\n/** The two names of EdDSA on Ed25519: the polymorphic \"EdDSA\" and the fully-specified \"Ed25519\". */\nconst OKP_NAMES: ReadonlySet<string> = new Set(['EdDSA', 'Ed25519']);\n\n/** Whether `key` may verify a token signed with `algorithm` (key type, curve and any \"alg\"/\"use\" agree). */\nexport function keyFits(key: Jwk, algorithm: JwtAlgorithm): boolean {\n const spec = ALGORITHMS[algorithm];\n if (key.kty !== spec.kty) return false;\n if (key.alg !== undefined && key.alg !== algorithm && !(OKP_NAMES.has(key.alg) && OKP_NAMES.has(algorithm)))\n return false;\n if (key.use !== undefined && key.use !== 'sig') return false;\n if (spec.import.namedCurve !== undefined && key.crv !== spec.import.namedCurve) return false;\n return !OKP_NAMES.has(algorithm) || key.crv === 'Ed25519';\n}\n\n/** Verifies a decoded JWT's signature with one public key; false on any mismatch or import failure. */\nexport async function verifySignature(jwt: DecodedJwt, algorithm: JwtAlgorithm, key: Jwk): Promise<boolean> {\n if (!keyFits(key, algorithm)) return false;\n const spec = ALGORITHMS[algorithm];\n try {\n const imported = await crypto.subtle.importKey('jwk', publicJwk(key), spec.import, false, ['verify']);\n return await crypto.subtle.verify(spec.verify, imported, jwt.signature, jwt.signingInput);\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;AAgBA,MAAM,WAAW,SAA0B,KAAK,MAAM,IAAI,YAAY,CAAC,CAAC,OAAO,gBAAgB,IAAI,CAAC,CAAC;;AAGrG,SAAgB,UAAU,OAAkC;CAC1D,MAAM,QAAQ,MAAM,MAAM,GA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AAG,KAAK,QAAQ,OAAO,CAAC,QAAQ,CAAC;EACpG,OAAO,MAAM,OAAO,OAAO,OAAO,KAAK,QAAQ,UAAU,IAAI,WAAW,IAAI,YAAY;CAC1F,QAAQ;EACN,OAAO;CACT;AACF"}
@@ -0,0 +1,3 @@
1
+ /** The npm name this package is published under. */
2
+ export declare const packageName: '@leed-ai/git-gateway-auth-jwt';
3
+ //# sourceMappingURL=package-name.d.ts.map
@@ -0,0 +1,6 @@
1
+ // src/package-name.ts
2
+ /** The npm name this package is published under. */
3
+ const packageName = "@leed-ai/git-gateway-auth-jwt";
4
+ export { packageName };
5
+
6
+ //# sourceMappingURL=package-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-name.js","names":[],"sources":["../src/package-name.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/** The npm name this package is published under. */\nexport const packageName = '@leed-ai/git-gateway-auth-jwt' as const;\n"],"mappings":";;AAGA,MAAa,cAAc"}
@@ -0,0 +1,2 @@
1
+ import { n as JwkSet, r as OidcDiscovery, t as Jwk } from "../jwks-Bk8zq_xG.js";
2
+ export { Jwk, JwkSet, OidcDiscovery };
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+ // src/schemas/jwks.ts
3
+ const base64url = z.string().regex(/^[A-Za-z0-9_-]+$/);
4
+ /** One public key of a JWK Set. */
5
+ const Jwk = z.looseObject({
6
+ kty: z.enum([
7
+ "RSA",
8
+ "EC",
9
+ "OKP"
10
+ ]).meta({
11
+ description: "Key type.",
12
+ enumDescriptions: {
13
+ RSA: "An RSA public key (n, e).",
14
+ EC: "An elliptic-curve public key (crv, x, y).",
15
+ OKP: "An Ed25519 public key (crv, x)."
16
+ }
17
+ }),
18
+ kid: z.string().min(1).max(255).optional().describe("Key id, matched against a token header's \"kid\"; absent on single-key sets."),
19
+ alg: z.string().min(1).max(20).optional().describe("The algorithm the key is for; when present a token must use it."),
20
+ use: z.string().min(1).max(20).optional().describe("Intended use; keys whose use is not \"sig\" are ignored. Absent means any."),
21
+ n: base64url.optional().describe("RSA modulus, base64url."),
22
+ e: base64url.optional().describe("RSA public exponent, base64url."),
23
+ crv: z.string().min(1).max(20).optional().describe("Curve: P-256 or P-384 for EC, Ed25519 for OKP."),
24
+ x: base64url.optional().describe("Curve point x coordinate (EC) or public key (OKP), base64url."),
25
+ y: base64url.optional().describe("Curve point y coordinate (EC), base64url.")
26
+ }).meta({
27
+ id: "Jwk",
28
+ title: "JSON Web Key",
29
+ description: "One public signing key from a JWK Set (RFC 7517). Members the authenticator does not use are kept but ignored.",
30
+ examples: [{
31
+ kty: "EC",
32
+ kid: "key-1",
33
+ alg: "ES256",
34
+ use: "sig",
35
+ crv: "P-256",
36
+ x: "f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU",
37
+ y: "x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0"
38
+ }]
39
+ });
40
+ /** A JWK Set document. */
41
+ const JwkSet = z.looseObject({ keys: z.array(Jwk).max(100).describe("The issuer's public keys, at most 100.") }).meta({
42
+ id: "JwkSet",
43
+ title: "JWK Set",
44
+ description: "The document at an issuer's jwks_uri (RFC 7517 §5): its public signing keys.",
45
+ examples: [{ keys: [{
46
+ kty: "RSA",
47
+ kid: "rsa-1",
48
+ n: "sXchDaQebHnPiGvyDOAT4saGEUetSyo9MKLOoWFsueri",
49
+ e: "AQAB"
50
+ }] }]
51
+ });
52
+ /** The part of an OpenID Provider configuration the authenticator reads. */
53
+ const OidcDiscovery = z.looseObject({
54
+ issuer: z.string().min(1).describe("The provider's issuer identifier; must equal the configured issuer."),
55
+ jwks_uri: z.url({ protocol: /^https?$/ }).describe("Where the provider publishes its JWK Set.")
56
+ }).meta({
57
+ id: "OidcDiscovery",
58
+ title: "OIDC discovery document",
59
+ description: "The fields of <issuer>/.well-known/openid-configuration (OpenID Connect Discovery 1.0) the authenticator uses.",
60
+ examples: [{
61
+ issuer: "https://auth.example.com",
62
+ jwks_uri: "https://auth.example.com/.well-known/jwks.json"
63
+ }]
64
+ });
65
+ export { Jwk, JwkSet, OidcDiscovery };
66
+
67
+ //# sourceMappingURL=jwks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwks.js","names":[],"sources":["../../src/schemas/jwks.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\nconst base64url = z.string().regex(/^[A-Za-z0-9_-]+$/);\n\n/** One public key of a JWK Set. */\nexport const Jwk = z\n .looseObject({\n kty: z.enum(['RSA', 'EC', 'OKP']).meta({\n description: 'Key type.',\n enumDescriptions: {\n RSA: 'An RSA public key (n, e).',\n EC: 'An elliptic-curve public key (crv, x, y).',\n OKP: 'An Ed25519 public key (crv, x).',\n },\n }),\n kid: z\n .string()\n .min(1)\n .max(255)\n .optional()\n .describe('Key id, matched against a token header\\'s \"kid\"; absent on single-key sets.'),\n alg: z\n .string()\n .min(1)\n .max(20)\n .optional()\n .describe('The algorithm the key is for; when present a token must use it.'),\n use: z\n .string()\n .min(1)\n .max(20)\n .optional()\n .describe('Intended use; keys whose use is not \"sig\" are ignored. Absent means any.'),\n n: base64url.optional().describe('RSA modulus, base64url.'),\n e: base64url.optional().describe('RSA public exponent, base64url.'),\n crv: z.string().min(1).max(20).optional().describe('Curve: P-256 or P-384 for EC, Ed25519 for OKP.'),\n x: base64url.optional().describe('Curve point x coordinate (EC) or public key (OKP), base64url.'),\n y: base64url.optional().describe('Curve point y coordinate (EC), base64url.'),\n })\n .meta({\n id: 'Jwk',\n title: 'JSON Web Key',\n description:\n 'One public signing key from a JWK Set (RFC 7517). Members the authenticator does not use are kept but ignored.',\n examples: [\n {\n kty: 'EC',\n kid: 'key-1',\n alg: 'ES256',\n use: 'sig',\n crv: 'P-256',\n x: 'f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU',\n y: 'x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0',\n },\n ],\n });\n\n/** A JSON Web Key, inferred from {@link Jwk}. */\nexport type Jwk = z.infer<typeof Jwk>;\n\n/** A JWK Set document. */\nexport const JwkSet = z\n .looseObject({\n keys: z.array(Jwk).max(100).describe(\"The issuer's public keys, at most 100.\"),\n })\n .meta({\n id: 'JwkSet',\n title: 'JWK Set',\n description: \"The document at an issuer's jwks_uri (RFC 7517 §5): its public signing keys.\",\n examples: [\n { keys: [{ kty: 'RSA', kid: 'rsa-1', n: 'sXchDaQebHnPiGvyDOAT4saGEUetSyo9MKLOoWFsueri', e: 'AQAB' }] },\n ],\n });\n\n/** A JWK Set, inferred from {@link JwkSet}. */\nexport type JwkSet = z.infer<typeof JwkSet>;\n\n/** The part of an OpenID Provider configuration the authenticator reads. */\nexport const OidcDiscovery = z\n .looseObject({\n issuer: z.string().min(1).describe(\"The provider's issuer identifier; must equal the configured issuer.\"),\n jwks_uri: z.url({ protocol: /^https?$/ }).describe('Where the provider publishes its JWK Set.'),\n })\n .meta({\n id: 'OidcDiscovery',\n title: 'OIDC discovery document',\n description:\n 'The fields of <issuer>/.well-known/openid-configuration (OpenID Connect Discovery 1.0) the authenticator uses.',\n examples: [\n { issuer: 'https://auth.example.com', jwks_uri: 'https://auth.example.com/.well-known/jwks.json' },\n ],\n });\n\n/** An OIDC discovery document, inferred from {@link OidcDiscovery}. */\nexport type OidcDiscovery = z.infer<typeof OidcDiscovery>;\n"],"mappings":";;AAGA,MAAM,YAAY,EAAE,OAAO,CAAC,CAAC,MAAM,kBAAkB;;AAGrD,MAAa,MAAM,EAChB,YAAY;CACX,KAAK,EAAE,KAAK;EAAC;EAAO;EAAM;CAAK,CAAC,CAAC,CAAC,KAAK;EACrC,aAAa;EACb,kBAAkB;GAChB,KAAK;GACL,IAAI;GACJ,KAAK;EACP;CACF,CAAC;CACD,KAAK,EACF,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,SAAS,CAAC,CACV,SAAS,8EAA6E;CACzF,KAAK,EACF,OAAO,CAA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CACF,UAAU,CACR;EAAE,QAAQ;EAA4B,UAAU;CAAiD,CACnG;AACF,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { z } from "zod";
2
+ /** A JWS signature algorithm the authenticator can verify with Web Crypto. */
3
+ export declare const JwtAlgorithm: z.ZodEnum<{
4
+ ES256: "ES256";
5
+ ES384: "ES384";
6
+ Ed25519: "Ed25519";
7
+ EdDSA: "EdDSA";
8
+ PS256: "PS256";
9
+ PS384: "PS384";
10
+ PS512: "PS512";
11
+ RS256: "RS256";
12
+ RS384: "RS384";
13
+ RS512: "RS512";
14
+ }>;
15
+ /** A JWS algorithm, inferred from {@link JwtAlgorithm}. */
16
+ export type JwtAlgorithm = z.infer<typeof JwtAlgorithm>;
17
+ //# sourceMappingURL=jwt-algorithm.d.ts.map
@@ -0,0 +1,35 @@
1
+ import { z } from "zod";
2
+ // src/schemas/jwt-algorithm.ts
3
+ /** A JWS signature algorithm the authenticator can verify with Web Crypto. */
4
+ const JwtAlgorithm = z.enum([
5
+ "RS256",
6
+ "RS384",
7
+ "RS512",
8
+ "PS256",
9
+ "PS384",
10
+ "PS512",
11
+ "ES256",
12
+ "ES384",
13
+ "EdDSA",
14
+ "Ed25519"
15
+ ]).meta({
16
+ id: "JwtAlgorithm",
17
+ title: "JWT algorithm",
18
+ description: "A JWS \"alg\" the JWT authenticator verifies with Web Crypto. Symmetric algorithms (HS*) and \"none\" are never accepted.",
19
+ enumDescriptions: {
20
+ RS256: "RSASSA-PKCS1-v1_5 with SHA-256 (RSA key).",
21
+ RS384: "RSASSA-PKCS1-v1_5 with SHA-384 (RSA key).",
22
+ RS512: "RSASSA-PKCS1-v1_5 with SHA-512 (RSA key).",
23
+ PS256: "RSASSA-PSS with SHA-256 (RSA key).",
24
+ PS384: "RSASSA-PSS with SHA-384 (RSA key).",
25
+ PS512: "RSASSA-PSS with SHA-512 (RSA key).",
26
+ ES256: "ECDSA on P-256 with SHA-256 (EC key).",
27
+ ES384: "ECDSA on P-384 with SHA-384 (EC key).",
28
+ EdDSA: "EdDSA with an Ed25519 key (OKP key, crv Ed25519).",
29
+ Ed25519: "Ed25519, the fully-specified name of EdDSA on Ed25519 (RFC 9864); same keys as EdDSA."
30
+ },
31
+ examples: ["RS256", "ES256"]
32
+ });
33
+ export { JwtAlgorithm };
34
+
35
+ //# sourceMappingURL=jwt-algorithm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-algorithm.js","names":[],"sources":["../../src/schemas/jwt-algorithm.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\n/** A JWS signature algorithm the authenticator can verify with Web Crypto. */\nexport const JwtAlgorithm = z\n .enum(['RS256', 'RS384', 'RS512', 'PS256', 'PS384', 'PS512', 'ES256', 'ES384', 'EdDSA', 'Ed25519'])\n .meta({\n id: 'JwtAlgorithm',\n title: 'JWT algorithm',\n description:\n 'A JWS \"alg\" the JWT authenticator verifies with Web Crypto. Symmetric algorithms (HS*) and \"none\" are never accepted.',\n enumDescriptions: {\n RS256: 'RSASSA-PKCS1-v1_5 with SHA-256 (RSA key).',\n RS384: 'RSASSA-PKCS1-v1_5 with SHA-384 (RSA key).',\n RS512: 'RSASSA-PKCS1-v1_5 with SHA-512 (RSA key).',\n PS256: 'RSASSA-PSS with SHA-256 (RSA key).',\n PS384: 'RSASSA-PSS with SHA-384 (RSA key).',\n PS512: 'RSASSA-PSS with SHA-512 (RSA key).',\n ES256: 'ECDSA on P-256 with SHA-256 (EC key).',\n ES384: 'ECDSA on P-384 with SHA-384 (EC key).',\n EdDSA: 'EdDSA with an Ed25519 key (OKP key, crv Ed25519).',\n Ed25519: 'Ed25519, the fully-specified name of EdDSA on Ed25519 (RFC 9864); same keys as EdDSA.',\n },\n examples: ['RS256', 'ES256'],\n });\n\n/** A JWS algorithm, inferred from {@link JwtAlgorithm}. */\nexport type JwtAlgorithm = z.infer<typeof JwtAlgorithm>;\n"],"mappings":";;;AAIA,MAAa,eAAe,EACzB,KAAK;CAAC;CAAS;CAAS;CAAS;CAAS;CAAS;CAAS;CAAS;CAAS;CAAS;AAAS,CAAC,CAAC,CAClG,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,kBAAkB;EAChB,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,SAAS;CACX;CACA,UAAU,CAAC,SAAS,OAAO;AAC7B,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { z } from "zod";
2
+ /** Which JWT claims become which Principal fields. */
3
+ export declare const JwtClaimMapping: z.ZodObject<{
4
+ subject: z.ZodDefault<z.ZodString>;
5
+ name: z.ZodDefault<z.ZodString>;
6
+ email: z.ZodDefault<z.ZodString>;
7
+ roles: z.ZodDefault<z.ZodString>;
8
+ }, z.core.$strict>;
9
+ /** A claim mapping as written (defaults optional). */
10
+ export type JwtClaimMappingInput = z.input<typeof JwtClaimMapping>;
11
+ /** Configuration of the JWT (JWKS/OIDC) authenticator. */
12
+ export declare const JwtAuthenticatorConfig: z.ZodObject<{
13
+ issuer: z.ZodURL;
14
+ audience: z.ZodArray<z.ZodString>;
15
+ jwksUrl: z.ZodDefault<z.ZodNullable<z.ZodURL>>;
16
+ algorithms: z.ZodDefault<z.ZodArray<z.ZodEnum<{
17
+ ES256: "ES256";
18
+ ES384: "ES384";
19
+ Ed25519: "Ed25519";
20
+ EdDSA: "EdDSA";
21
+ PS256: "PS256";
22
+ PS384: "PS384";
23
+ PS512: "PS512";
24
+ RS256: "RS256";
25
+ RS384: "RS384";
26
+ RS512: "RS512";
27
+ }>>>;
28
+ clockToleranceSeconds: z.ZodDefault<z.ZodInt>;
29
+ jwksCacheSeconds: z.ZodDefault<z.ZodInt>;
30
+ claims: z.ZodDefault<z.ZodObject<{
31
+ subject: z.ZodDefault<z.ZodString>;
32
+ name: z.ZodDefault<z.ZodString>;
33
+ email: z.ZodDefault<z.ZodString>;
34
+ roles: z.ZodDefault<z.ZodString>;
35
+ }, z.core.$strict>>;
36
+ }, z.core.$strict>;
37
+ /** A JWT authenticator configuration as written (defaults optional). */
38
+ export type JwtAuthenticatorConfigInput = z.input<typeof JwtAuthenticatorConfig>;
39
+ /** A complete JWT authenticator configuration, inferred from {@link JwtAuthenticatorConfig}. */
40
+ export type JwtAuthenticatorConfig = z.output<typeof JwtAuthenticatorConfig>;
41
+ //# sourceMappingURL=jwt-authenticator-config.d.ts.map
@@ -0,0 +1,57 @@
1
+ import { JwtAlgorithm } from "./jwt-algorithm.js";
2
+ import { z } from "zod";
3
+ // src/schemas/jwt-authenticator-config.ts
4
+ const claimName = (what, fallback) => z.string().min(1).max(100).default(fallback).describe(`Name of the claim holding ${what}; default "${fallback}".`);
5
+ /** Which JWT claims become which Principal fields. */
6
+ const JwtClaimMapping = z.object({
7
+ subject: claimName("the principal subject (a non-empty string; required in every token)", "sub"),
8
+ name: claimName("the display name (optional; ignored unless a non-empty single-line string)", "name"),
9
+ email: claimName("the email address (optional; ignored unless a valid address)", "email"),
10
+ roles: claimName("the roles: an array of strings, or one string of space- or comma-separated names (optional; names with whitespace are dropped)", "roles")
11
+ }).strict().meta({
12
+ id: "JwtClaimMapping",
13
+ title: "JWT claim mapping",
14
+ description: "Which claims of a verified JWT fill which Principal fields.",
15
+ examples: [{
16
+ subject: "sub",
17
+ name: "name",
18
+ email: "email",
19
+ roles: "roles"
20
+ }]
21
+ });
22
+ /** Configuration of the JWT (JWKS/OIDC) authenticator. */
23
+ const JwtAuthenticatorConfig = z.object({
24
+ issuer: z.url({ protocol: /^https?$/ }).describe("The required \"iss\" claim, compared exactly; also the base of OIDC discovery when `jwksUrl` is null."),
25
+ audience: z.array(z.string().min(1).max(255).describe("One accepted audience value.")).min(1).max(20).describe("Accepted \"aud\" values: a token is accepted when its audience (a string or an array) contains any of them."),
26
+ jwksUrl: z.url({ protocol: /^https?$/ }).nullable().default(null).describe("Where the signing keys (a JWK Set) are fetched; null (the default) discovers them from <issuer>/.well-known/openid-configuration (\"jwks_uri\")."),
27
+ algorithms: z.array(JwtAlgorithm).min(1).max(10).default(["RS256", "ES256"]).describe("Signature algorithms accepted; a token signed otherwise is refused. Default [\"RS256\", \"ES256\"]."),
28
+ clockToleranceSeconds: z.int().min(0).max(300).default(60).describe("Seconds of clock skew allowed when checking \"exp\" and \"nbf\"; the principal expires this long after \"exp\" too. 0–300, default 60."),
29
+ jwksCacheSeconds: z.int().min(10).max(86400).default(600).describe("Seconds fetched keys are reused before being fetched again; a token naming an unknown \"kid\" refetches sooner. The issuer is asked at most every 10 seconds, and when a refetch fails the last keys fetched keep being used. 10–86400, default 600."),
30
+ claims: JwtClaimMapping.default({
31
+ subject: "sub",
32
+ name: "name",
33
+ email: "email",
34
+ roles: "roles"
35
+ }).describe("Which claims fill which Principal fields; defaults to sub, name, email and roles.")
36
+ }).strict().meta({
37
+ id: "JwtAuthenticatorConfig",
38
+ title: "JWT authenticator configuration",
39
+ description: "Configuration of the reference JWT authenticator: tokens (as a Bearer header or the HTTP Basic password git sends) are verified against the issuer's JWKS, and must carry the issuer, an accepted audience and an unexpired \"exp\".",
40
+ examples: [{
41
+ issuer: "https://auth.example.com",
42
+ audience: ["git.example.com"],
43
+ jwksUrl: null,
44
+ algorithms: ["RS256", "ES256"],
45
+ clockToleranceSeconds: 60,
46
+ jwksCacheSeconds: 600,
47
+ claims: {
48
+ subject: "sub",
49
+ name: "name",
50
+ email: "email",
51
+ roles: "roles"
52
+ }
53
+ }]
54
+ });
55
+ export { JwtAuthenticatorConfig, JwtClaimMapping };
56
+
57
+ //# sourceMappingURL=jwt-authenticator-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-authenticator-config.js","names":[],"sources":["../../src/schemas/jwt-authenticator-config.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\nimport { JwtAlgorithm } from './jwt-algorithm.ts';\n\nconst claimName = (what: string, fallback: string) =>\n z\n .string()\n .min(1)\n .max(100)\n .default(fallback)\n .describe(`Name of the claim holding ${what}; default \"${fallback}\".`);\n\n/** Which JWT claims become which Principal fields. */\nexport const JwtClaimMapping = z\n .object({\n subject: claimName('the principal subject (a non-empty string; required in every token)', 'sub'),\n name: claimName('the display name (optional; ignored unless a non-empty single-line string)', 'name'),\n email: claimName('the email address (optional; ignored unless a valid address)', 'email'),\n roles: claimName(\n 'the roles: an array of strings, or one string of space- or comma-separated names (optional; names with whitespace are dropped)',\n 'roles',\n ),\n })\n .strict()\n .meta({\n id: 'JwtClaimMapping',\n title: 'JWT claim mapping',\n description: 'Which claims of a verified JWT fill which Principal fields.',\n examples: [{ subject: 'sub', name: 'name', email: 'email', roles: 'roles' }],\n });\n\n/** A claim mapping as written (defaults optional). */\nexport type JwtClaimMappingInput = z.input<typeof JwtClaimMapping>;\n\n/** Configuration of the JWT (JWKS/OIDC) authenticator. */\nexport const JwtAuthenticatorConfig = z\n .object({\n issuer: z\n .url({ protocol: /^https?$/ })\n .describe(\n 'The required \"iss\" claim, compared exactly; also the base of OIDC discovery when `jwksUrl` is null.',\n ),\n audience: z\n .array(z.string().min(1).max(255).describe('One accepted audience value.'))\n .min(1)\n .max(20)\n .describe(\n 'Accepted \"aud\" values: a token is accepted when its audience (a string or an array) contains any of them.',\n ),\n jwksUrl: z\n .url({ protocol: /^https?$/ })\n .nullable()\n .default(null)\n .describe(\n 'Where the signing keys (a JWK Set) are fetched; null (the default) discovers them from <issuer>/.well-known/openid-configuration (\"jwks_uri\").',\n ),\n algorithms: z\n .array(JwtAlgorithm)\n .min(1)\n .max(10)\n .default(['RS256', 'ES256'])\n .describe(\n 'Signature algorithms accepted; a token signed otherwise is refused. Default [\"RS256\", \"ES256\"].',\n ),\n clockToleranceSeconds: z\n .int()\n .min(0)\n .max(300)\n .default(60)\n .describe(\n 'Seconds of clock skew allowed when checking \"exp\" and \"nbf\"; the principal expires this long after \"exp\" too. 0–300, default 60.',\n ),\n jwksCacheSeconds: z\n .int()\n .min(10)\n .max(86_400)\n .default(600)\n .describe(\n 'Seconds fetched keys are reused before being fetched again; a token naming an unknown \"kid\" refetches sooner. The issuer is asked at most every 10 seconds, and when a refetch fails the last keys fetched keep being used. 10–86400, default 600.',\n ),\n claims: JwtClaimMapping.default({\n subject: 'sub',\n name: 'name',\n email: 'email',\n roles: 'roles',\n }).describe('Which claims fill which Principal fields; defaults to sub, name, email and roles.'),\n })\n .strict()\n .meta({\n id: 'JwtAuthenticatorConfig',\n title: 'JWT authenticator configuration',\n description:\n 'Configuration of the reference JWT authenticator: tokens (as a Bearer header or the HTTP Basic password git sends) are verified against the issuer\\'s JWKS, and must carry the issuer, an accepted audience and an unexpired \"exp\".',\n examples: [\n {\n issuer: 'https://auth.example.com',\n audience: ['git.example.com'],\n jwksUrl: null,\n algorithms: ['RS256', 'ES256'],\n clockToleranceSeconds: 60,\n jwksCacheSeconds: 600,\n claims: { subject: 'sub', name: 'name', email: 'email', roles: 'roles' },\n },\n ],\n });\n\n/** A JWT authenticator configuration as written (defaults optional). */\nexport type JwtAuthenticatorConfigInput = z.input<typeof JwtAuthenticatorConfig>;\n/** A complete JWT authenticator configuration, inferred from {@link JwtAuthenticatorConfig}. */\nexport type JwtAuthenticatorConfig = z.output<typeof JwtAuthenticatorConfig>;\n"],"mappings":";;;AAKA,MAAM,aAAa,MAAc,aAC/B,EACG,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,QAAQ,QAAQ,CAAC,CACjB,SAAS,6BAA6B,KAAK,aAAa,SAAS,GAAG;;AAGzE,MAAa,kBAAkB,EAC5B,OAAO;CACN,SAAS,UAAU,uEAAuE,KAAK;CAC/F,MAAM,UAAU,8EAA8E,MAAM;CACpG,OAAO,UAAU,gEAAgE,OAAO;CACxF,OAAO,UACL,kIACA,OACF;AACF,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,SAAS;EAAO,MAA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C"}
@@ -0,0 +1,20 @@
1
+ import { z } from "zod";
2
+ /** The protected header of a JWS-signed JWT. */
3
+ export declare const JwtHeader: z.ZodObject<{
4
+ alg: z.ZodString;
5
+ kid: z.ZodOptional<z.ZodString>;
6
+ typ: z.ZodOptional<z.ZodString>;
7
+ }, z.core.$loose>;
8
+ /** A JWT header, inferred from {@link JwtHeader}. */
9
+ export type JwtHeader = z.infer<typeof JwtHeader>;
10
+ /** The registered claims of a JWT the authenticator checks; all other claims pass through. */
11
+ export declare const JwtClaims: z.ZodObject<{
12
+ iss: z.ZodString;
13
+ aud: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
14
+ exp: z.ZodNumber;
15
+ nbf: z.ZodOptional<z.ZodNumber>;
16
+ iat: z.ZodOptional<z.ZodNumber>;
17
+ }, z.core.$loose>;
18
+ /** JWT claims, inferred from {@link JwtClaims}. */
19
+ export type JwtClaims = z.infer<typeof JwtClaims>;
20
+ //# sourceMappingURL=jwt-parts.d.ts.map
@@ -0,0 +1,40 @@
1
+ import { z } from "zod";
2
+ // src/schemas/jwt-parts.ts
3
+ /** The protected header of a JWS-signed JWT. */
4
+ const JwtHeader = z.looseObject({
5
+ alg: z.string().min(1).max(20).describe("Signature algorithm; must be one the authenticator accepts."),
6
+ kid: z.string().min(1).max(255).optional().describe("Id of the signing key in the issuer's JWK Set; absent when the set has one key."),
7
+ typ: z.string().max(50).optional().describe("Media type, usually \"JWT\"; not checked.")
8
+ }).meta({
9
+ id: "JwtHeader",
10
+ title: "JWT header",
11
+ description: "The protected header of a signed JWT (RFC 7515 §4). Other members are allowed and ignored.",
12
+ examples: [{
13
+ alg: "RS256",
14
+ kid: "rsa-1",
15
+ typ: "JWT"
16
+ }]
17
+ });
18
+ const numericDate = (what) => z.number().finite().nonnegative().describe(`${what}, as seconds since the epoch (a JSON number).`);
19
+ /** The registered claims of a JWT the authenticator checks; all other claims pass through. */
20
+ const JwtClaims = z.looseObject({
21
+ iss: z.string().min(1).describe("Issuer; must equal the configured issuer."),
22
+ aud: z.union([z.string().min(1).describe("A single audience."), z.array(z.string().min(1).describe("One audience.")).min(1).describe("Several audiences.")]).describe("Audience; must contain one of the configured audiences."),
23
+ exp: numericDate("Expiry; required, and must be in the future (with clock tolerance)"),
24
+ nbf: numericDate("Not before; when present, must not be in the future (with clock tolerance)").optional(),
25
+ iat: numericDate("Issued at; informational").optional()
26
+ }).meta({
27
+ id: "JwtClaims",
28
+ title: "JWT claims",
29
+ description: "The payload of a JWT: the registered claims the authenticator checks (iss, aud, exp, nbf), plus any others, from which the principal is mapped.",
30
+ examples: [{
31
+ iss: "https://auth.example.com",
32
+ aud: "git.example.com",
33
+ exp: 1795e6,
34
+ sub: "user:42",
35
+ roles: ["maintainer"]
36
+ }]
37
+ });
38
+ export { JwtClaims, JwtHeader };
39
+
40
+ //# sourceMappingURL=jwt-parts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-parts.js","names":[],"sources":["../../src/schemas/jwt-parts.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\n/** The protected header of a JWS-signed JWT. */\nexport const JwtHeader = z\n .looseObject({\n alg: z.string().min(1).max(20).describe('Signature algorithm; must be one the authenticator accepts.'),\n kid: z\n .string()\n .min(1)\n .max(255)\n .optional()\n .describe(\"Id of the signing key in the issuer's JWK Set; absent when the set has one key.\"),\n typ: z.string().max(50).optional().describe('Media type, usually \"JWT\"; not checked.'),\n })\n .meta({\n id: 'JwtHeader',\n title: 'JWT header',\n description: 'The protected header of a signed JWT (RFC 7515 §4). Other members are allowed and ignored.',\n examples: [{ alg: 'RS256', kid: 'rsa-1', typ: 'JWT' }],\n });\n\n/** A JWT header, inferred from {@link JwtHeader}. */\nexport type JwtHeader = z.infer<typeof JwtHeader>;\n\nconst numericDate = (what: string) =>\n z.number().finite().nonnegative().describe(`${what}, as seconds since the epoch (a JSON number).`);\n\n/** The registered claims of a JWT the authenticator checks; all other claims pass through. */\nexport const JwtClaims = z\n .looseObject({\n iss: z.string().min(1).describe('Issuer; must equal the configured issuer.'),\n aud: z\n .union([\n z.string().min(1).describe('A single audience.'),\n z.array(z.string().min(1).describe('One audience.')).min(1).describe('Several audiences.'),\n ])\n .describe('Audience; must contain one of the configured audiences.'),\n exp: numericDate('Expiry; required, and must be in the future (with clock tolerance)'),\n nbf: numericDate('Not before; when present, must not be in the future (with clock tolerance)').optional(),\n iat: numericDate('Issued at; informational').optional(),\n })\n .meta({\n id: 'JwtClaims',\n title: 'JWT claims',\n description:\n 'The payload of a JWT: the registered claims the authenticator checks (iss, aud, exp, nbf), plus any others, from which the principal is mapped.',\n examples: [\n {\n iss: 'https://auth.example.com',\n aud: 'git.example.com',\n exp: 1_795_000_000,\n sub: 'user:42',\n roles: ['maintainer'],\n },\n ],\n });\n\n/** JWT claims, inferred from {@link JwtClaims}. */\nexport type JwtClaims = z.infer<typeof JwtClaims>;\n"],"mappings":";;;AAIA,MAAa,YAAY,EACtB,YAAY;CACX,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,6DAA6D;CACrG,KAAK,EACF,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,SAAS,CAAC,CACV,SAAS,iFAAiF;CAC7F,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,2CAAyC;AACvF,CAAC,CAAC,CACD,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,KAAK;EAAS,KAAK;EAAS,KAAK;CAAM,CAAC;AACvD,CAAC;AAKH,MAAM,eAAe,SACnB,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS,GAAG,KAAK,8CAA8C;;AAGnG,MAAa,YAAY,EACtB,YAAY;CACX,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,2CAA2C;CAC3E,KAAK,EACF,MAAM,CACL,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,oBAAoB,GAC/C,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,oBAAoB,CAC3F,CAAC,CAAC,CACD,SAAS,yDAAyD;CACrE,KAAK,YAAY,oEAAoE;CACrF,KAAK,YAAY,4EAA4E,CAAC,CAAC,SAAS;CACxG,KAAK,YAAY,0BAA0B,CAAC,CAAC,SAAS;AACxD,CAAC,CAAC,CACD,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CACR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,OAAO,CAAC,YAAY;CACtB,CACF;AACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,105 @@
1
1
  {
2
2
  "name": "@leed-ai/git-gateway-auth-jwt",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Reference git-gateway authenticator: bearer or Basic-password JWTs verified against a JWKS (OIDC).",
5
+ "keywords": [
6
+ "authentication",
7
+ "cloudflare-workers",
8
+ "git",
9
+ "git-gateway",
10
+ "jwks",
11
+ "jwt",
12
+ "oidc"
13
+ ],
14
+ "homepage": "https://github.com/leed-ai/git-gateway/tree/main/packages/auth-jwt#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/leed-ai/git-gateway/issues"
17
+ },
18
+ "license": "Apache-2.0",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/leed-ai/git-gateway.git",
22
+ "directory": "packages/auth-jwt"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "src"
27
+ ],
28
+ "type": "module",
29
+ "sideEffects": false,
30
+ "exports": {
31
+ "./base64url": {
32
+ "source": "./src/base64url.ts",
33
+ "types": "./dist/base64url.d.ts",
34
+ "default": "./dist/base64url.js"
35
+ },
36
+ "./jwks-source": {
37
+ "source": "./src/jwks-source.ts",
38
+ "types": "./dist/jwks-source.d.ts",
39
+ "default": "./dist/jwks-source.js"
40
+ },
41
+ "./jwt-authenticator": {
42
+ "source": "./src/jwt-authenticator.ts",
43
+ "types": "./dist/jwt-authenticator.d.ts",
44
+ "default": "./dist/jwt-authenticator.js"
45
+ },
46
+ "./jwt-verify": {
47
+ "source": "./src/jwt-verify.ts",
48
+ "types": "./dist/jwt-verify.d.ts",
49
+ "default": "./dist/jwt-verify.js"
50
+ },
51
+ "./package-name": {
52
+ "source": "./src/package-name.ts",
53
+ "types": "./dist/package-name.d.ts",
54
+ "default": "./dist/package-name.js"
55
+ },
56
+ "./schemas/jwks": {
57
+ "source": "./src/schemas/jwks.ts",
58
+ "types": "./dist/schemas/jwks.d.ts",
59
+ "default": "./dist/schemas/jwks.js"
60
+ },
61
+ "./schemas/jwt-algorithm": {
62
+ "source": "./src/schemas/jwt-algorithm.ts",
63
+ "types": "./dist/schemas/jwt-algorithm.d.ts",
64
+ "default": "./dist/schemas/jwt-algorithm.js"
65
+ },
66
+ "./schemas/jwt-authenticator-config": {
67
+ "source": "./src/schemas/jwt-authenticator-config.ts",
68
+ "types": "./dist/schemas/jwt-authenticator-config.d.ts",
69
+ "default": "./dist/schemas/jwt-authenticator-config.js"
70
+ },
71
+ "./schemas/jwt-parts": {
72
+ "source": "./src/schemas/jwt-parts.ts",
73
+ "types": "./dist/schemas/jwt-parts.d.ts",
74
+ "default": "./dist/schemas/jwt-parts.js"
75
+ },
76
+ "./package.json": "./package.json"
77
+ },
78
+ "publishConfig": {
79
+ "access": "public",
80
+ "provenance": true
81
+ },
82
+ "scripts": {
83
+ "build": "vp pack",
84
+ "check": "vp check",
85
+ "test": "vp test"
86
+ },
87
+ "dependencies": {
88
+ "@leed-ai/git-gateway-contract": "0.1.0"
89
+ },
90
+ "devDependencies": {
91
+ "@leed-ai/git-gateway-repo-tools": "0.0.0",
92
+ "@leed-ai/git-gateway-schema-docs": "0.0.0",
93
+ "@types/node": "^24.19.2",
94
+ "fast-check": "^4.10.3",
95
+ "typescript": "^7.0.2",
96
+ "vite-plus": "^1.7.0",
97
+ "zod": "^4.6.7"
98
+ },
99
+ "peerDependencies": {
100
+ "zod": "^4"
101
+ },
102
+ "engines": {
103
+ "node": ">=22.18.0"
104
+ }
105
+ }