@openid4vc/oauth2 0.3.0-alpha-20251017102623 → 0.3.0-alpha-20251017122507
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/dist/index.d.mts +1363 -10884
- package/dist/index.d.ts +1768 -11289
- package/dist/index.js +43 -102
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +212 -271
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ContentType, Headers, InvalidFetchResponseError, InvalidFetchResponseError as InvalidFetchResponseError$1, URL, ValidationError, addSecondsToDate, createFetcher, createZodFetcher, dateToSeconds, decodeBase64, decodeUtf8String, encodeToBase64Url, encodeToUtf8String, encodeWwwAuthenticateHeader, formatZodError, getGlobalConfig, joinUriParts, objectToQueryParams, parseWithErrorHandling, parseWwwAuthenticateHeader, setGlobalConfig, stringToJsonWithErrorHandling, zHttpMethod, zHttpsUrl, zInteger } from "@openid4vc/utils";
|
|
2
|
-
import z, {
|
|
2
|
+
import z$1, { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/callbacks.ts
|
|
5
5
|
/**
|
|
@@ -27,26 +27,26 @@ var Oauth2Error = class extends Error {
|
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region src/common/jwk/jwk-thumbprint.ts
|
|
30
|
-
const zJwkThumbprintComponents = z.discriminatedUnion("kty", [
|
|
31
|
-
z.object({
|
|
32
|
-
kty: z.literal("EC"),
|
|
33
|
-
crv: z.string(),
|
|
34
|
-
x: z.string(),
|
|
35
|
-
y: z.string()
|
|
30
|
+
const zJwkThumbprintComponents = z$1.discriminatedUnion("kty", [
|
|
31
|
+
z$1.object({
|
|
32
|
+
kty: z$1.literal("EC"),
|
|
33
|
+
crv: z$1.string(),
|
|
34
|
+
x: z$1.string(),
|
|
35
|
+
y: z$1.string()
|
|
36
36
|
}),
|
|
37
|
-
z.object({
|
|
38
|
-
kty: z.literal("OKP"),
|
|
39
|
-
crv: z.string(),
|
|
40
|
-
x: z.string()
|
|
37
|
+
z$1.object({
|
|
38
|
+
kty: z$1.literal("OKP"),
|
|
39
|
+
crv: z$1.string(),
|
|
40
|
+
x: z$1.string()
|
|
41
41
|
}),
|
|
42
|
-
z.object({
|
|
43
|
-
kty: z.literal("RSA"),
|
|
44
|
-
e: z.string(),
|
|
45
|
-
n: z.string()
|
|
42
|
+
z$1.object({
|
|
43
|
+
kty: z$1.literal("RSA"),
|
|
44
|
+
e: z$1.string(),
|
|
45
|
+
n: z$1.string()
|
|
46
46
|
}),
|
|
47
|
-
z.object({
|
|
48
|
-
kty: z.literal("oct"),
|
|
49
|
-
k: z.string()
|
|
47
|
+
z$1.object({
|
|
48
|
+
kty: z$1.literal("oct"),
|
|
49
|
+
k: z$1.string()
|
|
50
50
|
})
|
|
51
51
|
]).transform((data) => {
|
|
52
52
|
if (data.kty === "EC") return {
|
|
@@ -114,68 +114,68 @@ var Oauth2JwtParseError = class extends Oauth2Error {
|
|
|
114
114
|
|
|
115
115
|
//#endregion
|
|
116
116
|
//#region src/common/jwk/z-jwk.ts
|
|
117
|
-
const zJwk = z.object({
|
|
118
|
-
kty: z.string(),
|
|
119
|
-
crv: z.optional(z.string()),
|
|
120
|
-
x: z.optional(z.string()),
|
|
121
|
-
y: z.optional(z.string()),
|
|
122
|
-
e: z.optional(z.string()),
|
|
123
|
-
n: z.optional(z.string()),
|
|
124
|
-
alg: z.optional(z.string()),
|
|
125
|
-
d: z.optional(z.string()),
|
|
126
|
-
dp: z.optional(z.string()),
|
|
127
|
-
dq: z.optional(z.string()),
|
|
128
|
-
ext: z.optional(z.boolean()),
|
|
129
|
-
k: z.optional(z.string()),
|
|
130
|
-
key_ops: z.optional(z.array(z.string())),
|
|
131
|
-
kid: z.optional(z.string()),
|
|
132
|
-
oth: z.optional(z.array(z.object({
|
|
133
|
-
d: z.optional(z.string()),
|
|
134
|
-
r: z.optional(z.string()),
|
|
135
|
-
t: z.optional(z.string())
|
|
136
|
-
}).
|
|
137
|
-
p: z.optional(z.string()),
|
|
138
|
-
q: z.optional(z.string()),
|
|
139
|
-
qi: z.optional(z.string()),
|
|
140
|
-
use: z.optional(z.string()),
|
|
141
|
-
x5c: z.optional(z.array(z.string())),
|
|
142
|
-
x5t: z.optional(z.string()),
|
|
143
|
-
"x5t#S256": z.optional(z.string()),
|
|
144
|
-
x5u: z.optional(z.string())
|
|
145
|
-
}).
|
|
146
|
-
const zJwkSet = z.object({ keys: z.array(zJwk) }).
|
|
117
|
+
const zJwk = z$1.object({
|
|
118
|
+
kty: z$1.string(),
|
|
119
|
+
crv: z$1.optional(z$1.string()),
|
|
120
|
+
x: z$1.optional(z$1.string()),
|
|
121
|
+
y: z$1.optional(z$1.string()),
|
|
122
|
+
e: z$1.optional(z$1.string()),
|
|
123
|
+
n: z$1.optional(z$1.string()),
|
|
124
|
+
alg: z$1.optional(z$1.string()),
|
|
125
|
+
d: z$1.optional(z$1.string()),
|
|
126
|
+
dp: z$1.optional(z$1.string()),
|
|
127
|
+
dq: z$1.optional(z$1.string()),
|
|
128
|
+
ext: z$1.optional(z$1.boolean()),
|
|
129
|
+
k: z$1.optional(z$1.string()),
|
|
130
|
+
key_ops: z$1.optional(z$1.array(z$1.string())),
|
|
131
|
+
kid: z$1.optional(z$1.string()),
|
|
132
|
+
oth: z$1.optional(z$1.array(z$1.object({
|
|
133
|
+
d: z$1.optional(z$1.string()),
|
|
134
|
+
r: z$1.optional(z$1.string()),
|
|
135
|
+
t: z$1.optional(z$1.string())
|
|
136
|
+
}).loose())),
|
|
137
|
+
p: z$1.optional(z$1.string()),
|
|
138
|
+
q: z$1.optional(z$1.string()),
|
|
139
|
+
qi: z$1.optional(z$1.string()),
|
|
140
|
+
use: z$1.optional(z$1.string()),
|
|
141
|
+
x5c: z$1.optional(z$1.array(z$1.string())),
|
|
142
|
+
x5t: z$1.optional(z$1.string()),
|
|
143
|
+
"x5t#S256": z$1.optional(z$1.string()),
|
|
144
|
+
x5u: z$1.optional(z$1.string())
|
|
145
|
+
}).loose();
|
|
146
|
+
const zJwkSet = z$1.object({ keys: z$1.array(zJwk) }).loose();
|
|
147
147
|
|
|
148
148
|
//#endregion
|
|
149
149
|
//#region src/common/z-common.ts
|
|
150
|
-
const zAlgValueNotNone = z.string().refine((alg) => alg !== "none", { message: `alg value may not be 'none'` });
|
|
150
|
+
const zAlgValueNotNone = z$1.string().refine((alg) => alg !== "none", { message: `alg value may not be 'none'` });
|
|
151
151
|
|
|
152
152
|
//#endregion
|
|
153
153
|
//#region src/common/jwt/z-jwt.ts
|
|
154
|
-
const zCompactJwt = z.string().regex(/^([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)$/, { message: "Not a valid compact jwt" });
|
|
155
|
-
const zJwtConfirmationPayload = z.object({
|
|
154
|
+
const zCompactJwt = z$1.string().regex(/^([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)$/, { message: "Not a valid compact jwt" });
|
|
155
|
+
const zJwtConfirmationPayload = z$1.object({
|
|
156
156
|
jwk: zJwk.optional(),
|
|
157
|
-
jkt: z.string().optional()
|
|
158
|
-
}).
|
|
159
|
-
const zJwtPayload = z.object({
|
|
160
|
-
iss: z.string().optional(),
|
|
161
|
-
aud: z.string().optional(),
|
|
157
|
+
jkt: z$1.string().optional()
|
|
158
|
+
}).loose();
|
|
159
|
+
const zJwtPayload = z$1.object({
|
|
160
|
+
iss: z$1.string().optional(),
|
|
161
|
+
aud: z$1.string().optional(),
|
|
162
162
|
iat: zInteger.optional(),
|
|
163
163
|
exp: zInteger.optional(),
|
|
164
164
|
nbf: zInteger.optional(),
|
|
165
|
-
nonce: z.string().optional(),
|
|
166
|
-
jti: z.string().optional(),
|
|
165
|
+
nonce: z$1.string().optional(),
|
|
166
|
+
jti: z$1.string().optional(),
|
|
167
167
|
cnf: zJwtConfirmationPayload.optional(),
|
|
168
|
-
status: z.record(z.string(), z.any()).optional(),
|
|
169
|
-
trust_chain: z.
|
|
170
|
-
}).
|
|
171
|
-
const zJwtHeader = z.object({
|
|
168
|
+
status: z$1.record(z$1.string(), z$1.any()).optional(),
|
|
169
|
+
trust_chain: z$1.tuple([z$1.string()], z$1.string()).optional()
|
|
170
|
+
}).loose();
|
|
171
|
+
const zJwtHeader = z$1.object({
|
|
172
172
|
alg: zAlgValueNotNone,
|
|
173
|
-
typ: z.string().optional(),
|
|
174
|
-
kid: z.string().optional(),
|
|
173
|
+
typ: z$1.string().optional(),
|
|
174
|
+
kid: z$1.string().optional(),
|
|
175
175
|
jwk: zJwk.optional(),
|
|
176
|
-
x5c: z.array(z.string()).optional(),
|
|
177
|
-
trust_chain: z.
|
|
178
|
-
}).
|
|
176
|
+
x5c: z$1.array(z$1.string()).optional(),
|
|
177
|
+
trust_chain: z$1.tuple([z$1.string()], z$1.string()).optional()
|
|
178
|
+
}).loose();
|
|
179
179
|
|
|
180
180
|
//#endregion
|
|
181
181
|
//#region src/common/jwt/decode-jwt-header.ts
|
|
@@ -343,60 +343,12 @@ async function verifyJwt(options) {
|
|
|
343
343
|
} };
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
-
//#endregion
|
|
347
|
-
//#region ../utils/src/zod-error.ts
|
|
348
|
-
/**
|
|
349
|
-
* Some code comes from `zod-validation-error` package (MIT License) and
|
|
350
|
-
* was slightly simplified to fit our needs.
|
|
351
|
-
*/
|
|
352
|
-
const constants = {
|
|
353
|
-
identifierRegex: /[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u,
|
|
354
|
-
unionSeparator: ", or ",
|
|
355
|
-
issueSeparator: "\n - "
|
|
356
|
-
};
|
|
357
|
-
function escapeQuotes(str) {
|
|
358
|
-
return str.replace(/"/g, "\\\"");
|
|
359
|
-
}
|
|
360
|
-
function joinPath(path) {
|
|
361
|
-
if (path.length === 1) return path[0].toString();
|
|
362
|
-
return path.reduce((acc, item) => {
|
|
363
|
-
if (typeof item === "number") return `${acc}[${item.toString()}]`;
|
|
364
|
-
if (item.includes("\"")) return `${acc}["${escapeQuotes(item)}"]`;
|
|
365
|
-
if (!constants.identifierRegex.test(item)) return `${acc}["${item}"]`;
|
|
366
|
-
return acc + (acc.length === 0 ? "" : ".") + item;
|
|
367
|
-
}, "");
|
|
368
|
-
}
|
|
369
|
-
function getMessageFromZodIssue(issue) {
|
|
370
|
-
if (issue.code === ZodIssueCode.invalid_union) return getMessageFromUnionErrors(issue.unionErrors);
|
|
371
|
-
if (issue.code === ZodIssueCode.invalid_arguments) return [issue.message, ...issue.argumentsError.issues.map((issue$1) => getMessageFromZodIssue(issue$1))].join(constants.issueSeparator);
|
|
372
|
-
if (issue.code === ZodIssueCode.invalid_return_type) return [issue.message, ...issue.returnTypeError.issues.map((issue$1) => getMessageFromZodIssue(issue$1))].join(constants.issueSeparator);
|
|
373
|
-
if (issue.path.length !== 0) {
|
|
374
|
-
if (issue.path.length === 1) {
|
|
375
|
-
const identifier = issue.path[0];
|
|
376
|
-
if (typeof identifier === "number") return `${issue.message} at index ${identifier}`;
|
|
377
|
-
}
|
|
378
|
-
return `${issue.message} at "${joinPath(issue.path)}"`;
|
|
379
|
-
}
|
|
380
|
-
return issue.message;
|
|
381
|
-
}
|
|
382
|
-
function getMessageFromUnionErrors(unionErrors) {
|
|
383
|
-
return unionErrors.reduce((acc, zodError) => {
|
|
384
|
-
const newIssues = zodError.issues.map((issue) => getMessageFromZodIssue(issue)).join(constants.issueSeparator);
|
|
385
|
-
if (!acc.includes(newIssues)) acc.push(newIssues);
|
|
386
|
-
return acc;
|
|
387
|
-
}, []).join(constants.unionSeparator);
|
|
388
|
-
}
|
|
389
|
-
function formatZodError$1(error) {
|
|
390
|
-
if (!error) return "";
|
|
391
|
-
return `\t- ${error?.issues.map((issue) => getMessageFromZodIssue(issue)).join(constants.issueSeparator)}`;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
346
|
//#endregion
|
|
395
347
|
//#region ../utils/src/error/ValidationError.ts
|
|
396
348
|
var ValidationError$1 = class extends Error {
|
|
397
349
|
constructor(message, zodError) {
|
|
398
350
|
super(message);
|
|
399
|
-
this.message = `${message}\n${
|
|
351
|
+
this.message = `${message}\n${zodError ? z$1.prettifyError(zodError) : ""}`;
|
|
400
352
|
Object.defineProperty(this, "zodError", {
|
|
401
353
|
value: zodError,
|
|
402
354
|
writable: false,
|
|
@@ -425,21 +377,21 @@ async function fetchJwks(jwksUrl, fetch) {
|
|
|
425
377
|
|
|
426
378
|
//#endregion
|
|
427
379
|
//#region src/access-token/z-access-token-jwt.ts
|
|
428
|
-
const zAccessTokenProfileJwtHeader = z.object({
|
|
380
|
+
const zAccessTokenProfileJwtHeader = z$1.object({
|
|
429
381
|
...zJwtHeader.shape,
|
|
430
|
-
typ: z.enum(["application/at+jwt", "at+jwt"])
|
|
431
|
-
}).
|
|
432
|
-
const zAccessTokenProfileJwtPayload = z.object({
|
|
382
|
+
typ: z$1.enum(["application/at+jwt", "at+jwt"])
|
|
383
|
+
}).loose();
|
|
384
|
+
const zAccessTokenProfileJwtPayload = z$1.object({
|
|
433
385
|
...zJwtPayload.shape,
|
|
434
|
-
iss: z.string(),
|
|
386
|
+
iss: z$1.string(),
|
|
435
387
|
exp: zInteger,
|
|
436
388
|
iat: zInteger,
|
|
437
|
-
aud: z.string(),
|
|
438
|
-
sub: z.string(),
|
|
439
|
-
client_id: z.optional(z.string()),
|
|
440
|
-
jti: z.string(),
|
|
441
|
-
scope: z.optional(z.string())
|
|
442
|
-
}).
|
|
389
|
+
aud: z$1.string(),
|
|
390
|
+
sub: z$1.string(),
|
|
391
|
+
client_id: z$1.optional(z$1.string()),
|
|
392
|
+
jti: z$1.string(),
|
|
393
|
+
scope: z$1.optional(z$1.string())
|
|
394
|
+
}).loose();
|
|
443
395
|
|
|
444
396
|
//#endregion
|
|
445
397
|
//#region src/access-token/verify-access-token.ts
|
|
@@ -534,11 +486,11 @@ let Oauth2ErrorCodes = /* @__PURE__ */ function(Oauth2ErrorCodes$1) {
|
|
|
534
486
|
Oauth2ErrorCodes$1["WalletUnavailable"] = "wallet_unavailable";
|
|
535
487
|
return Oauth2ErrorCodes$1;
|
|
536
488
|
}({});
|
|
537
|
-
const zOauth2ErrorResponse = z.object({
|
|
538
|
-
error: z.union([z.
|
|
539
|
-
error_description: z.string().optional(),
|
|
540
|
-
error_uri: z.string().optional()
|
|
541
|
-
}).
|
|
489
|
+
const zOauth2ErrorResponse = z$1.object({
|
|
490
|
+
error: z$1.union([z$1.enum(Oauth2ErrorCodes), z$1.string()]),
|
|
491
|
+
error_description: z$1.string().optional(),
|
|
492
|
+
error_uri: z$1.string().optional()
|
|
493
|
+
}).loose();
|
|
542
494
|
|
|
543
495
|
//#endregion
|
|
544
496
|
//#region src/error/Oauth2ServerErrorResponseError.ts
|
|
@@ -552,35 +504,35 @@ var Oauth2ServerErrorResponseError = class extends Oauth2Error {
|
|
|
552
504
|
|
|
553
505
|
//#endregion
|
|
554
506
|
//#region src/client-attestation/z-client-attestation.ts
|
|
555
|
-
const zOauthClientAttestationHeader = z.literal("OAuth-Client-Attestation");
|
|
507
|
+
const zOauthClientAttestationHeader = z$1.literal("OAuth-Client-Attestation");
|
|
556
508
|
const oauthClientAttestationHeader = zOauthClientAttestationHeader.value;
|
|
557
|
-
const zClientAttestationJwtPayload = z.object({
|
|
509
|
+
const zClientAttestationJwtPayload = z$1.object({
|
|
558
510
|
...zJwtPayload.shape,
|
|
559
|
-
iss: z.string(),
|
|
560
|
-
sub: z.string(),
|
|
511
|
+
iss: z$1.string(),
|
|
512
|
+
sub: z$1.string(),
|
|
561
513
|
exp: zInteger,
|
|
562
|
-
cnf: z.object({ jwk: zJwk }).
|
|
563
|
-
wallet_name: z.string().optional(),
|
|
564
|
-
wallet_link: z.
|
|
565
|
-
}).
|
|
566
|
-
const zClientAttestationJwtHeader = z.object({
|
|
514
|
+
cnf: z$1.object({ jwk: zJwk }).loose(),
|
|
515
|
+
wallet_name: z$1.string().optional(),
|
|
516
|
+
wallet_link: z$1.url().optional()
|
|
517
|
+
}).loose();
|
|
518
|
+
const zClientAttestationJwtHeader = z$1.object({
|
|
567
519
|
...zJwtHeader.shape,
|
|
568
|
-
typ: z.literal("oauth-client-attestation+jwt")
|
|
569
|
-
}).
|
|
570
|
-
const zOauthClientAttestationPopHeader = z.literal("OAuth-Client-Attestation-PoP");
|
|
520
|
+
typ: z$1.literal("oauth-client-attestation+jwt")
|
|
521
|
+
}).loose();
|
|
522
|
+
const zOauthClientAttestationPopHeader = z$1.literal("OAuth-Client-Attestation-PoP");
|
|
571
523
|
const oauthClientAttestationPopHeader = zOauthClientAttestationPopHeader.value;
|
|
572
|
-
const zClientAttestationPopJwtPayload = z.object({
|
|
524
|
+
const zClientAttestationPopJwtPayload = z$1.object({
|
|
573
525
|
...zJwtPayload.shape,
|
|
574
|
-
iss: z.string(),
|
|
526
|
+
iss: z$1.string(),
|
|
575
527
|
exp: zInteger,
|
|
576
528
|
aud: zHttpsUrl,
|
|
577
|
-
jti: z.string(),
|
|
578
|
-
nonce: z.optional(z.string())
|
|
579
|
-
}).
|
|
580
|
-
const zClientAttestationPopJwtHeader = z.object({
|
|
529
|
+
jti: z$1.string(),
|
|
530
|
+
nonce: z$1.optional(z$1.string())
|
|
531
|
+
}).loose();
|
|
532
|
+
const zClientAttestationPopJwtHeader = z$1.object({
|
|
581
533
|
...zJwtHeader.shape,
|
|
582
|
-
typ: z.literal("oauth-client-attestation-pop+jwt")
|
|
583
|
-
}).
|
|
534
|
+
typ: z$1.literal("oauth-client-attestation-pop+jwt")
|
|
535
|
+
}).loose();
|
|
584
536
|
|
|
585
537
|
//#endregion
|
|
586
538
|
//#region src/client-attestation/client-attestation-pop.ts
|
|
@@ -739,11 +691,11 @@ async function verifyClientAttestation({ authorizationServer, clientAttestationJ
|
|
|
739
691
|
|
|
740
692
|
//#endregion
|
|
741
693
|
//#region src/z-grant-type.ts
|
|
742
|
-
const zPreAuthorizedCodeGrantIdentifier = z.literal("urn:ietf:params:oauth:grant-type:pre-authorized_code");
|
|
694
|
+
const zPreAuthorizedCodeGrantIdentifier = z$1.literal("urn:ietf:params:oauth:grant-type:pre-authorized_code");
|
|
743
695
|
const preAuthorizedCodeGrantIdentifier = zPreAuthorizedCodeGrantIdentifier.value;
|
|
744
|
-
const zAuthorizationCodeGrantIdentifier = z.literal("authorization_code");
|
|
696
|
+
const zAuthorizationCodeGrantIdentifier = z$1.literal("authorization_code");
|
|
745
697
|
const authorizationCodeGrantIdentifier = zAuthorizationCodeGrantIdentifier.value;
|
|
746
|
-
const zRefreshTokenGrantIdentifier = z.literal("refresh_token");
|
|
698
|
+
const zRefreshTokenGrantIdentifier = z$1.literal("refresh_token");
|
|
747
699
|
const refreshTokenGrantIdentifier = zRefreshTokenGrantIdentifier.value;
|
|
748
700
|
|
|
749
701
|
//#endregion
|
|
@@ -840,7 +792,7 @@ function clientAuthenticationClientAttestationJwt(options) {
|
|
|
840
792
|
|
|
841
793
|
//#endregion
|
|
842
794
|
//#region src/common/jwt/z-jwe.ts
|
|
843
|
-
const zCompactJwe = z
|
|
795
|
+
const zCompactJwe = z.string().regex(/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/, { message: "Not a valid compact jwe" });
|
|
844
796
|
|
|
845
797
|
//#endregion
|
|
846
798
|
//#region src/error/Oauth2ClientErrorResponseError.ts
|
|
@@ -913,31 +865,31 @@ async function fetchWellKnownMetadata(wellKnownMetadataUrl, schema, fetch) {
|
|
|
913
865
|
|
|
914
866
|
//#endregion
|
|
915
867
|
//#region src/metadata/authorization-server/z-authorization-server-metadata.ts
|
|
916
|
-
const knownClientAuthenticationMethod = z.enum([
|
|
868
|
+
const knownClientAuthenticationMethod = z$1.enum([
|
|
917
869
|
"client_secret_basic",
|
|
918
870
|
"client_secret_post",
|
|
919
871
|
"attest_jwt_client_auth",
|
|
920
872
|
"client_secret_jwt",
|
|
921
873
|
"private_key_jwt"
|
|
922
874
|
]);
|
|
923
|
-
const zAuthorizationServerMetadata = z.object({
|
|
875
|
+
const zAuthorizationServerMetadata = z$1.object({
|
|
924
876
|
issuer: zHttpsUrl,
|
|
925
877
|
token_endpoint: zHttpsUrl,
|
|
926
|
-
token_endpoint_auth_methods_supported: z.optional(z.array(z.union([knownClientAuthenticationMethod, z.string()]))),
|
|
927
|
-
authorization_endpoint: z.optional(zHttpsUrl),
|
|
928
|
-
jwks_uri: z.optional(zHttpsUrl),
|
|
929
|
-
grant_types_supported: z.optional(z.array(z.string())),
|
|
930
|
-
code_challenge_methods_supported: z.optional(z.array(z.string())),
|
|
931
|
-
dpop_signing_alg_values_supported: z.optional(z.array(z.string())),
|
|
932
|
-
require_pushed_authorization_requests: z.optional(z.boolean()),
|
|
933
|
-
pushed_authorization_request_endpoint: z.optional(zHttpsUrl),
|
|
934
|
-
introspection_endpoint: z.optional(zHttpsUrl),
|
|
935
|
-
introspection_endpoint_auth_methods_supported: z.optional(z.array(z.union([knownClientAuthenticationMethod, z.string()]))),
|
|
936
|
-
introspection_endpoint_auth_signing_alg_values_supported: z.optional(z.array(zAlgValueNotNone)),
|
|
937
|
-
authorization_challenge_endpoint: z.optional(zHttpsUrl),
|
|
938
|
-
"pre-authorized_grant_anonymous_access_supported": z.optional(z.boolean()),
|
|
939
|
-
client_attestation_pop_nonce_required: z.boolean().optional()
|
|
940
|
-
}).
|
|
878
|
+
token_endpoint_auth_methods_supported: z$1.optional(z$1.array(z$1.union([knownClientAuthenticationMethod, z$1.string()]))),
|
|
879
|
+
authorization_endpoint: z$1.optional(zHttpsUrl),
|
|
880
|
+
jwks_uri: z$1.optional(zHttpsUrl),
|
|
881
|
+
grant_types_supported: z$1.optional(z$1.array(z$1.string())),
|
|
882
|
+
code_challenge_methods_supported: z$1.optional(z$1.array(z$1.string())),
|
|
883
|
+
dpop_signing_alg_values_supported: z$1.optional(z$1.array(z$1.string())),
|
|
884
|
+
require_pushed_authorization_requests: z$1.optional(z$1.boolean()),
|
|
885
|
+
pushed_authorization_request_endpoint: z$1.optional(zHttpsUrl),
|
|
886
|
+
introspection_endpoint: z$1.optional(zHttpsUrl),
|
|
887
|
+
introspection_endpoint_auth_methods_supported: z$1.optional(z$1.array(z$1.union([knownClientAuthenticationMethod, z$1.string()]))),
|
|
888
|
+
introspection_endpoint_auth_signing_alg_values_supported: z$1.optional(z$1.array(zAlgValueNotNone)),
|
|
889
|
+
authorization_challenge_endpoint: z$1.optional(zHttpsUrl),
|
|
890
|
+
"pre-authorized_grant_anonymous_access_supported": z$1.optional(z$1.boolean()),
|
|
891
|
+
client_attestation_pop_nonce_required: z$1.boolean().optional()
|
|
892
|
+
}).loose().refine(({ introspection_endpoint_auth_methods_supported: methodsSupported, introspection_endpoint_auth_signing_alg_values_supported: algValuesSupported }) => {
|
|
941
893
|
if (!methodsSupported) return true;
|
|
942
894
|
if (!methodsSupported.includes("private_key_jwt") && !methodsSupported.includes("client_secret_jwt")) return true;
|
|
943
895
|
return algValuesSupported !== void 0 && algValuesSupported.length > 0;
|
|
@@ -952,26 +904,15 @@ const wellKnownOpenIdConfigurationServerSuffix = ".well-known/openid-configurati
|
|
|
952
904
|
* a 404, the openid-configuration metadata will be fetched.
|
|
953
905
|
*/
|
|
954
906
|
async function fetchAuthorizationServerMetadata(issuer, fetch) {
|
|
955
|
-
const openIdConfigurationWellKnownMetadataUrl = joinUriParts(issuer, [wellKnownOpenIdConfigurationServerSuffix]);
|
|
956
907
|
const parsedIssuerUrl = new URL(issuer);
|
|
908
|
+
const openIdConfigurationWellKnownMetadataUrl = joinUriParts(issuer, [wellKnownOpenIdConfigurationServerSuffix]);
|
|
957
909
|
const authorizationServerWellKnownMetadataUrl = joinUriParts(parsedIssuerUrl.origin, [wellKnownAuthorizationServerSuffix, parsedIssuerUrl.pathname]);
|
|
958
|
-
const authorizationServerResult = await fetchWellKnownMetadata(authorizationServerWellKnownMetadataUrl, zAuthorizationServerMetadata, fetch);
|
|
959
|
-
if (authorizationServerResult) {
|
|
960
|
-
if (authorizationServerResult.issuer !== issuer) throw new Oauth2Error(`The 'issuer' parameter '${authorizationServerResult.issuer}' in the well known authorization server metadata at '${authorizationServerWellKnownMetadataUrl}' does not match the provided issuer '${issuer}'.`);
|
|
961
|
-
return authorizationServerResult;
|
|
962
|
-
}
|
|
963
910
|
const nonCompliantAuthorizationServerWellKnownMetadataUrl = joinUriParts(issuer, [wellKnownAuthorizationServerSuffix]);
|
|
964
|
-
|
|
965
|
-
if (
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
const openIdConfigurationResult = await fetchWellKnownMetadata(openIdConfigurationWellKnownMetadataUrl, zAuthorizationServerMetadata, fetch);
|
|
970
|
-
if (openIdConfigurationResult) {
|
|
971
|
-
if (openIdConfigurationResult.issuer !== issuer) throw new Oauth2Error(`The 'issuer' parameter '${openIdConfigurationResult.issuer}' in the well known openid configuration metadata at '${openIdConfigurationWellKnownMetadataUrl}' does not match the provided issuer '${issuer}'.`);
|
|
972
|
-
return openIdConfigurationResult;
|
|
973
|
-
}
|
|
974
|
-
return null;
|
|
911
|
+
let authorizationServerResult = await fetchWellKnownMetadata(authorizationServerWellKnownMetadataUrl, zAuthorizationServerMetadata, fetch);
|
|
912
|
+
if (!authorizationServerResult && nonCompliantAuthorizationServerWellKnownMetadataUrl !== authorizationServerWellKnownMetadataUrl) authorizationServerResult = await fetchWellKnownMetadata(nonCompliantAuthorizationServerWellKnownMetadataUrl, zAuthorizationServerMetadata, fetch);
|
|
913
|
+
if (!authorizationServerResult) authorizationServerResult = await fetchWellKnownMetadata(openIdConfigurationWellKnownMetadataUrl, zAuthorizationServerMetadata, fetch);
|
|
914
|
+
if (authorizationServerResult && authorizationServerResult.issuer !== issuer) throw new Oauth2Error(`The 'issuer' parameter '${authorizationServerResult.issuer}' in the well known authorization server metadata at '${authorizationServerWellKnownMetadataUrl}' does not match the provided issuer '${issuer}'.`);
|
|
915
|
+
return authorizationServerResult;
|
|
975
916
|
}
|
|
976
917
|
function getAuthorizationServerMetadataFromList(authorizationServersMetadata, issuer) {
|
|
977
918
|
const authorizationServerMetadata = authorizationServersMetadata.find((authorizationServerMetadata$1) => authorizationServerMetadata$1.issuer === issuer);
|
|
@@ -1016,39 +957,39 @@ async function createAccessTokenJwt(options) {
|
|
|
1016
957
|
|
|
1017
958
|
//#endregion
|
|
1018
959
|
//#region src/access-token/z-access-token.ts
|
|
1019
|
-
const zAccessTokenRequest = z.intersection(z.object({
|
|
1020
|
-
"pre-authorized_code": z.optional(z.string()),
|
|
1021
|
-
code: z.optional(z.string()),
|
|
1022
|
-
redirect_uri: z.
|
|
1023
|
-
refresh_token: z.optional(z.string()),
|
|
1024
|
-
resource: z.optional(zHttpsUrl),
|
|
1025
|
-
code_verifier: z.optional(z.string()),
|
|
1026
|
-
grant_type: z.union([
|
|
960
|
+
const zAccessTokenRequest = z$1.intersection(z$1.object({
|
|
961
|
+
"pre-authorized_code": z$1.optional(z$1.string()),
|
|
962
|
+
code: z$1.optional(z$1.string()),
|
|
963
|
+
redirect_uri: z$1.url().optional(),
|
|
964
|
+
refresh_token: z$1.optional(z$1.string()),
|
|
965
|
+
resource: z$1.optional(zHttpsUrl),
|
|
966
|
+
code_verifier: z$1.optional(z$1.string()),
|
|
967
|
+
grant_type: z$1.union([
|
|
1027
968
|
zPreAuthorizedCodeGrantIdentifier,
|
|
1028
969
|
zAuthorizationCodeGrantIdentifier,
|
|
1029
970
|
zRefreshTokenGrantIdentifier,
|
|
1030
|
-
z.string()
|
|
971
|
+
z$1.string()
|
|
1031
972
|
])
|
|
1032
|
-
}).
|
|
1033
|
-
tx_code: z.optional(z.string()),
|
|
1034
|
-
user_pin: z.optional(z.string())
|
|
1035
|
-
}).
|
|
973
|
+
}).loose(), z$1.object({
|
|
974
|
+
tx_code: z$1.optional(z$1.string()),
|
|
975
|
+
user_pin: z$1.optional(z$1.string())
|
|
976
|
+
}).loose().refine(({ tx_code, user_pin }) => !tx_code || !user_pin || user_pin === tx_code, { message: `If both 'tx_code' and 'user_pin' are present they must match` }).transform(({ tx_code, user_pin,...rest }) => {
|
|
1036
977
|
return {
|
|
1037
978
|
...rest,
|
|
1038
979
|
...tx_code ?? user_pin ? { tx_code: tx_code ?? user_pin } : {}
|
|
1039
980
|
};
|
|
1040
981
|
}));
|
|
1041
|
-
const zAccessTokenResponse = z.object({
|
|
1042
|
-
access_token: z.string(),
|
|
1043
|
-
token_type: z.string(),
|
|
1044
|
-
expires_in: z.optional(z.number().int()),
|
|
1045
|
-
scope: z.optional(z.string()),
|
|
1046
|
-
state: z.optional(z.string()),
|
|
1047
|
-
refresh_token: z.optional(z.string()),
|
|
1048
|
-
c_nonce: z.optional(z.string()),
|
|
1049
|
-
c_nonce_expires_in: z.optional(z.number().int()),
|
|
1050
|
-
authorization_details: z.array(z.object({}).
|
|
1051
|
-
}).
|
|
982
|
+
const zAccessTokenResponse = z$1.object({
|
|
983
|
+
access_token: z$1.string(),
|
|
984
|
+
token_type: z$1.string(),
|
|
985
|
+
expires_in: z$1.optional(z$1.number().int()),
|
|
986
|
+
scope: z$1.optional(z$1.string()),
|
|
987
|
+
state: z$1.optional(z$1.string()),
|
|
988
|
+
refresh_token: z$1.optional(z$1.string()),
|
|
989
|
+
c_nonce: z$1.optional(z$1.string()),
|
|
990
|
+
c_nonce_expires_in: z$1.optional(z$1.number().int()),
|
|
991
|
+
authorization_details: z$1.array(z$1.object({}).loose()).optional()
|
|
992
|
+
}).loose();
|
|
1052
993
|
const zAccessTokenErrorResponse = zOauth2ErrorResponse;
|
|
1053
994
|
|
|
1054
995
|
//#endregion
|
|
@@ -1067,19 +1008,19 @@ async function createAccessTokenResponse(options) {
|
|
|
1067
1008
|
|
|
1068
1009
|
//#endregion
|
|
1069
1010
|
//#region src/dpop/z-dpop.ts
|
|
1070
|
-
const zDpopJwtPayload = z.object({
|
|
1011
|
+
const zDpopJwtPayload = z$1.object({
|
|
1071
1012
|
...zJwtPayload.shape,
|
|
1072
1013
|
iat: zInteger,
|
|
1073
1014
|
htu: zHttpsUrl,
|
|
1074
1015
|
htm: zHttpMethod,
|
|
1075
|
-
jti: z.string(),
|
|
1076
|
-
ath: z.optional(z.string())
|
|
1077
|
-
}).
|
|
1078
|
-
const zDpopJwtHeader = z.object({
|
|
1016
|
+
jti: z$1.string(),
|
|
1017
|
+
ath: z$1.optional(z$1.string())
|
|
1018
|
+
}).loose();
|
|
1019
|
+
const zDpopJwtHeader = z$1.object({
|
|
1079
1020
|
...zJwtHeader.shape,
|
|
1080
|
-
typ: z.literal("dpop+jwt"),
|
|
1021
|
+
typ: z$1.literal("dpop+jwt"),
|
|
1081
1022
|
jwk: zJwk
|
|
1082
|
-
}).
|
|
1023
|
+
}).loose();
|
|
1083
1024
|
|
|
1084
1025
|
//#endregion
|
|
1085
1026
|
//#region src/dpop/dpop.ts
|
|
@@ -1437,45 +1378,45 @@ async function verifyAccessTokenRequestPkce(options, callbacks) {
|
|
|
1437
1378
|
|
|
1438
1379
|
//#endregion
|
|
1439
1380
|
//#region src/authorization-request/z-authorization-request.ts
|
|
1440
|
-
const zAuthorizationRequest = z.object({
|
|
1441
|
-
response_type: z.string(),
|
|
1442
|
-
client_id: z.string(),
|
|
1443
|
-
issuer_state: z.optional(z.string()),
|
|
1444
|
-
redirect_uri: z.
|
|
1445
|
-
resource: z.optional(zHttpsUrl),
|
|
1446
|
-
scope: z.optional(z.string()),
|
|
1447
|
-
dpop_jkt: z.optional(z.
|
|
1448
|
-
code_challenge: z.optional(z.string()),
|
|
1449
|
-
code_challenge_method: z.optional(z.string())
|
|
1450
|
-
}).
|
|
1451
|
-
const zPushedAuthorizationRequest = z.object({
|
|
1452
|
-
request_uri: z.string(),
|
|
1453
|
-
client_id: z.string()
|
|
1454
|
-
}).
|
|
1455
|
-
const zPushedAuthorizationResponse = z.object({
|
|
1456
|
-
request_uri: z.string(),
|
|
1457
|
-
expires_in: z.number().int()
|
|
1458
|
-
}).
|
|
1381
|
+
const zAuthorizationRequest = z$1.object({
|
|
1382
|
+
response_type: z$1.string(),
|
|
1383
|
+
client_id: z$1.string(),
|
|
1384
|
+
issuer_state: z$1.optional(z$1.string()),
|
|
1385
|
+
redirect_uri: z$1.url().optional(),
|
|
1386
|
+
resource: z$1.optional(zHttpsUrl),
|
|
1387
|
+
scope: z$1.optional(z$1.string()),
|
|
1388
|
+
dpop_jkt: z$1.optional(z$1.base64url()),
|
|
1389
|
+
code_challenge: z$1.optional(z$1.string()),
|
|
1390
|
+
code_challenge_method: z$1.optional(z$1.string())
|
|
1391
|
+
}).loose();
|
|
1392
|
+
const zPushedAuthorizationRequest = z$1.object({
|
|
1393
|
+
request_uri: z$1.string(),
|
|
1394
|
+
client_id: z$1.string()
|
|
1395
|
+
}).loose();
|
|
1396
|
+
const zPushedAuthorizationResponse = z$1.object({
|
|
1397
|
+
request_uri: z$1.string(),
|
|
1398
|
+
expires_in: z$1.number().int()
|
|
1399
|
+
}).loose();
|
|
1459
1400
|
|
|
1460
1401
|
//#endregion
|
|
1461
1402
|
//#region src/authorization-challenge/z-authorization-challenge.ts
|
|
1462
|
-
const zAuthorizationChallengeRequest = z.object({
|
|
1403
|
+
const zAuthorizationChallengeRequest = z$1.object({
|
|
1463
1404
|
...zAuthorizationRequest.omit({
|
|
1464
1405
|
response_type: true,
|
|
1465
1406
|
client_id: true
|
|
1466
1407
|
}).shape,
|
|
1467
|
-
client_id: z.optional(zAuthorizationRequest.shape.client_id),
|
|
1468
|
-
auth_session: z.optional(z.string()),
|
|
1469
|
-
presentation_during_issuance_session: z.optional(z.string())
|
|
1470
|
-
}).
|
|
1471
|
-
const zAuthorizationChallengeResponse = z.object({ authorization_code: z.string() }).
|
|
1472
|
-
const zAuthorizationChallengeErrorResponse = z.object({
|
|
1408
|
+
client_id: z$1.optional(zAuthorizationRequest.shape.client_id),
|
|
1409
|
+
auth_session: z$1.optional(z$1.string()),
|
|
1410
|
+
presentation_during_issuance_session: z$1.optional(z$1.string())
|
|
1411
|
+
}).loose();
|
|
1412
|
+
const zAuthorizationChallengeResponse = z$1.object({ authorization_code: z$1.string() }).loose();
|
|
1413
|
+
const zAuthorizationChallengeErrorResponse = z$1.object({
|
|
1473
1414
|
...zOauth2ErrorResponse.shape,
|
|
1474
|
-
auth_session: z.optional(z.string()),
|
|
1475
|
-
request_uri: z.optional(z.string()),
|
|
1476
|
-
expires_in: z.optional(zInteger),
|
|
1477
|
-
presentation: z.optional(z.string())
|
|
1478
|
-
}).
|
|
1415
|
+
auth_session: z$1.optional(z$1.string()),
|
|
1416
|
+
request_uri: z$1.optional(z$1.string()),
|
|
1417
|
+
expires_in: z$1.optional(zInteger),
|
|
1418
|
+
presentation: z$1.optional(z$1.string())
|
|
1419
|
+
}).loose();
|
|
1479
1420
|
|
|
1480
1421
|
//#endregion
|
|
1481
1422
|
//#region src/authorization-challenge/create-authorization-challenge-response.ts
|
|
@@ -2368,25 +2309,25 @@ var Oauth2ResourceServer = class {
|
|
|
2368
2309
|
|
|
2369
2310
|
//#endregion
|
|
2370
2311
|
//#region src/access-token/z-token-introspection.ts
|
|
2371
|
-
const zTokenIntrospectionRequest = z.object({
|
|
2372
|
-
token: z.string(),
|
|
2373
|
-
token_type_hint: z.optional(z.string())
|
|
2374
|
-
}).
|
|
2375
|
-
const zTokenIntrospectionResponse = z.object({
|
|
2376
|
-
active: z.boolean(),
|
|
2377
|
-
scope: z.optional(z.string()),
|
|
2378
|
-
client_id: z.optional(z.string()),
|
|
2379
|
-
username: z.optional(z.string()),
|
|
2380
|
-
token_type: z.optional(z.string()),
|
|
2381
|
-
exp: z.optional(zInteger),
|
|
2382
|
-
iat: z.optional(zInteger),
|
|
2383
|
-
nbf: z.optional(zInteger),
|
|
2384
|
-
sub: z.optional(z.string()),
|
|
2385
|
-
aud: z.optional(z.string()),
|
|
2386
|
-
iss: z.optional(z.string()),
|
|
2387
|
-
jti: z.optional(z.string()),
|
|
2388
|
-
cnf: z.optional(zJwtConfirmationPayload)
|
|
2389
|
-
}).
|
|
2312
|
+
const zTokenIntrospectionRequest = z$1.object({
|
|
2313
|
+
token: z$1.string(),
|
|
2314
|
+
token_type_hint: z$1.optional(z$1.string())
|
|
2315
|
+
}).loose();
|
|
2316
|
+
const zTokenIntrospectionResponse = z$1.object({
|
|
2317
|
+
active: z$1.boolean(),
|
|
2318
|
+
scope: z$1.optional(z$1.string()),
|
|
2319
|
+
client_id: z$1.optional(z$1.string()),
|
|
2320
|
+
username: z$1.optional(z$1.string()),
|
|
2321
|
+
token_type: z$1.optional(z$1.string()),
|
|
2322
|
+
exp: z$1.optional(zInteger),
|
|
2323
|
+
iat: z$1.optional(zInteger),
|
|
2324
|
+
nbf: z$1.optional(zInteger),
|
|
2325
|
+
sub: z$1.optional(z$1.string()),
|
|
2326
|
+
aud: z$1.optional(z$1.string()),
|
|
2327
|
+
iss: z$1.optional(z$1.string()),
|
|
2328
|
+
jti: z$1.optional(z$1.string()),
|
|
2329
|
+
cnf: z$1.optional(zJwtConfirmationPayload)
|
|
2330
|
+
}).loose();
|
|
2390
2331
|
|
|
2391
2332
|
//#endregion
|
|
2392
2333
|
//#region src/access-token/introspect-token.ts
|