@openid4vc/oauth2 0.2.1-alpha-20250130103023 → 0.3.0-alpha-20250202020720
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 +9460 -1143
- package/dist/index.d.ts +9460 -1143
- package/dist/index.js +540 -529
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +505 -494
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { getGlobalConfig, setGlobalConfig } from "@openid4vc/utils";
|
|
3
3
|
|
|
4
|
-
// src/common/
|
|
5
|
-
import
|
|
4
|
+
// src/common/z-oauth2-error.ts
|
|
5
|
+
import z from "zod";
|
|
6
6
|
var Oauth2ErrorCodes = /* @__PURE__ */ ((Oauth2ErrorCodes2) => {
|
|
7
7
|
Oauth2ErrorCodes2["ServerError"] = "server_error";
|
|
8
8
|
Oauth2ErrorCodes2["InvalidTarget"] = "invalid_target";
|
|
@@ -28,52 +28,54 @@ var Oauth2ErrorCodes = /* @__PURE__ */ ((Oauth2ErrorCodes2) => {
|
|
|
28
28
|
Oauth2ErrorCodes2["InvalidEncryptionParameters"] = "invalid_encryption_parameters";
|
|
29
29
|
return Oauth2ErrorCodes2;
|
|
30
30
|
})(Oauth2ErrorCodes || {});
|
|
31
|
-
var
|
|
32
|
-
error:
|
|
33
|
-
error_description:
|
|
34
|
-
error_uri:
|
|
35
|
-
});
|
|
31
|
+
var zOauth2ErrorResponse = z.object({
|
|
32
|
+
error: z.union([z.nativeEnum(Oauth2ErrorCodes), z.string()]),
|
|
33
|
+
error_description: z.string().optional(),
|
|
34
|
+
error_uri: z.string().optional()
|
|
35
|
+
}).passthrough();
|
|
36
36
|
|
|
37
37
|
// src/common/jwk/jwk-thumbprint.ts
|
|
38
|
-
import * as v2 from "valibot";
|
|
39
38
|
import { decodeUtf8String, encodeToBase64Url, parseWithErrorHandling } from "@openid4vc/utils";
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
),
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
)
|
|
73
|
-
|
|
39
|
+
import z2 from "zod";
|
|
40
|
+
var zJwkThumbprintComponents = z2.discriminatedUnion("kty", [
|
|
41
|
+
z2.object({
|
|
42
|
+
kty: z2.literal("EC"),
|
|
43
|
+
crv: z2.string(),
|
|
44
|
+
x: z2.string(),
|
|
45
|
+
y: z2.string()
|
|
46
|
+
}),
|
|
47
|
+
z2.object({
|
|
48
|
+
kty: z2.literal("OKP"),
|
|
49
|
+
crv: z2.string(),
|
|
50
|
+
x: z2.string()
|
|
51
|
+
}),
|
|
52
|
+
z2.object({
|
|
53
|
+
kty: z2.literal("RSA"),
|
|
54
|
+
e: z2.string(),
|
|
55
|
+
n: z2.string()
|
|
56
|
+
}),
|
|
57
|
+
z2.object({
|
|
58
|
+
kty: z2.literal("oct"),
|
|
59
|
+
k: z2.string()
|
|
60
|
+
})
|
|
61
|
+
]).transform((data) => {
|
|
62
|
+
if (data.kty === "EC") {
|
|
63
|
+
return { crv: data.crv, kty: data.kty, x: data.x, y: data.y };
|
|
64
|
+
}
|
|
65
|
+
if (data.kty === "OKP") {
|
|
66
|
+
return { crv: data.crv, kty: data.kty, x: data.x };
|
|
67
|
+
}
|
|
68
|
+
if (data.kty === "RSA") {
|
|
69
|
+
return { e: data.e, kty: data.kty, n: data.n };
|
|
70
|
+
}
|
|
71
|
+
if (data.kty === "oct") {
|
|
72
|
+
return { k: data.k, kty: data.kty };
|
|
73
|
+
}
|
|
74
|
+
throw new Error("Unsupported kty");
|
|
75
|
+
});
|
|
74
76
|
async function calculateJwkThumbprint(options) {
|
|
75
77
|
const jwkThumbprintComponents = parseWithErrorHandling(
|
|
76
|
-
|
|
78
|
+
zJwkThumbprintComponents,
|
|
77
79
|
options.jwk,
|
|
78
80
|
`Provided jwk does not match a supported jwk structure. Either the 'kty' is not supported, or required values are missing.`
|
|
79
81
|
);
|
|
@@ -134,44 +136,42 @@ async function isJwkInSet({
|
|
|
134
136
|
return false;
|
|
135
137
|
}
|
|
136
138
|
|
|
137
|
-
// src/common/jwk/
|
|
138
|
-
import
|
|
139
|
-
var
|
|
140
|
-
kty:
|
|
141
|
-
crv:
|
|
142
|
-
x:
|
|
143
|
-
y:
|
|
144
|
-
e:
|
|
145
|
-
n:
|
|
146
|
-
alg:
|
|
147
|
-
d:
|
|
148
|
-
dp:
|
|
149
|
-
dq:
|
|
150
|
-
ext:
|
|
151
|
-
k:
|
|
152
|
-
key_ops:
|
|
153
|
-
kid:
|
|
154
|
-
oth:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
d:
|
|
158
|
-
r:
|
|
159
|
-
t:
|
|
160
|
-
})
|
|
139
|
+
// src/common/jwk/z-jwk.ts
|
|
140
|
+
import z3 from "zod";
|
|
141
|
+
var zJwk = z3.object({
|
|
142
|
+
kty: z3.string(),
|
|
143
|
+
crv: z3.optional(z3.string()),
|
|
144
|
+
x: z3.optional(z3.string()),
|
|
145
|
+
y: z3.optional(z3.string()),
|
|
146
|
+
e: z3.optional(z3.string()),
|
|
147
|
+
n: z3.optional(z3.string()),
|
|
148
|
+
alg: z3.optional(z3.string()),
|
|
149
|
+
d: z3.optional(z3.string()),
|
|
150
|
+
dp: z3.optional(z3.string()),
|
|
151
|
+
dq: z3.optional(z3.string()),
|
|
152
|
+
ext: z3.optional(z3.boolean()),
|
|
153
|
+
k: z3.optional(z3.string()),
|
|
154
|
+
key_ops: z3.optional(z3.string()),
|
|
155
|
+
kid: z3.optional(z3.string()),
|
|
156
|
+
oth: z3.optional(
|
|
157
|
+
z3.array(
|
|
158
|
+
z3.object({
|
|
159
|
+
d: z3.optional(z3.string()),
|
|
160
|
+
r: z3.optional(z3.string()),
|
|
161
|
+
t: z3.optional(z3.string())
|
|
162
|
+
}).passthrough()
|
|
161
163
|
)
|
|
162
164
|
),
|
|
163
|
-
p:
|
|
164
|
-
q:
|
|
165
|
-
qi:
|
|
166
|
-
use:
|
|
167
|
-
x5c:
|
|
168
|
-
x5t:
|
|
169
|
-
"x5t#S256":
|
|
170
|
-
x5u:
|
|
171
|
-
});
|
|
172
|
-
var
|
|
173
|
-
keys: v3.array(vJwk)
|
|
174
|
-
});
|
|
165
|
+
p: z3.optional(z3.string()),
|
|
166
|
+
q: z3.optional(z3.string()),
|
|
167
|
+
qi: z3.optional(z3.string()),
|
|
168
|
+
use: z3.optional(z3.string()),
|
|
169
|
+
x5c: z3.optional(z3.string()),
|
|
170
|
+
x5t: z3.optional(z3.string()),
|
|
171
|
+
"x5t#S256": z3.optional(z3.string()),
|
|
172
|
+
x5u: z3.optional(z3.string())
|
|
173
|
+
}).passthrough();
|
|
174
|
+
var zJwkSet = z3.object({ keys: z3.array(zJwk) }).passthrough();
|
|
175
175
|
|
|
176
176
|
// src/common/jwt/verify-jwt.ts
|
|
177
177
|
import { dateToSeconds } from "@openid4vc/utils";
|
|
@@ -245,47 +245,43 @@ var Oauth2JwtParseError = class extends Oauth2Error {
|
|
|
245
245
|
}
|
|
246
246
|
};
|
|
247
247
|
|
|
248
|
-
// src/common/jwt/
|
|
249
|
-
import {
|
|
250
|
-
import
|
|
248
|
+
// src/common/jwt/z-jwt.ts
|
|
249
|
+
import { zInteger } from "@openid4vc/utils";
|
|
250
|
+
import z5 from "zod";
|
|
251
251
|
|
|
252
|
-
// src/common/
|
|
253
|
-
import
|
|
254
|
-
var
|
|
255
|
-
v4.string(),
|
|
256
|
-
v4.check((alg) => alg !== "none", `alg value may not be 'none'`)
|
|
257
|
-
);
|
|
252
|
+
// src/common/z-common.ts
|
|
253
|
+
import z4 from "zod";
|
|
254
|
+
var zAlgValueNotNone = z4.string().refine((alg) => alg !== "none", { message: `alg value may not be 'none'` });
|
|
258
255
|
|
|
259
|
-
// src/common/jwt/
|
|
260
|
-
var
|
|
261
|
-
|
|
262
|
-
v5.regex(/^([a-zA-Z0-9_=]+)\.([a-zA-Z0-9_=]+)\.([a-zA-Z0-9_\-\+\/=]*)$/, "Not a valid compact jwt")
|
|
263
|
-
);
|
|
264
|
-
var vJwtConfirmationPayload = v5.looseObject({
|
|
265
|
-
jwk: v5.optional(vJwk),
|
|
266
|
-
// RFC9449. jwk thumbprint of the dpop public key to which the access token is bound
|
|
267
|
-
jkt: v5.optional(v5.string())
|
|
256
|
+
// src/common/jwt/z-jwt.ts
|
|
257
|
+
var zCompactJwt = z5.string().regex(/^([a-zA-Z0-9_=]+)\.([a-zA-Z0-9_=]+)\.([a-zA-Z0-9_\-\+\/=]*)$/, {
|
|
258
|
+
message: "Not a valid compact jwt"
|
|
268
259
|
});
|
|
269
|
-
var
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
260
|
+
var zJwtConfirmationPayload = z5.object({
|
|
261
|
+
jwk: zJwk.optional(),
|
|
262
|
+
// RFC9449. jwk thumbprint of the dpop public key to which the access token is bound
|
|
263
|
+
jkt: z5.string().optional()
|
|
264
|
+
}).passthrough();
|
|
265
|
+
var zJwtPayload = z5.object({
|
|
266
|
+
iss: z5.string().optional(),
|
|
267
|
+
aud: z5.string().optional(),
|
|
268
|
+
iat: zInteger.optional(),
|
|
269
|
+
exp: zInteger.optional(),
|
|
270
|
+
nbf: zInteger.optional(),
|
|
271
|
+
nonce: z5.string().optional(),
|
|
272
|
+
jti: z5.string().optional(),
|
|
273
|
+
cnf: zJwtConfirmationPayload.optional(),
|
|
278
274
|
// Reserved for status parameters
|
|
279
|
-
status:
|
|
280
|
-
});
|
|
281
|
-
var
|
|
282
|
-
alg:
|
|
283
|
-
typ:
|
|
284
|
-
kid:
|
|
285
|
-
jwk:
|
|
286
|
-
x5c:
|
|
287
|
-
trust_chain:
|
|
288
|
-
});
|
|
275
|
+
status: z5.record(z5.string(), z5.any()).optional()
|
|
276
|
+
}).passthrough();
|
|
277
|
+
var zJwtHeader = z5.object({
|
|
278
|
+
alg: zAlgValueNotNone,
|
|
279
|
+
typ: z5.string().optional(),
|
|
280
|
+
kid: z5.string().optional(),
|
|
281
|
+
jwk: zJwk.optional(),
|
|
282
|
+
x5c: z5.array(z5.string()).optional(),
|
|
283
|
+
trust_chain: z5.array(z5.string()).optional()
|
|
284
|
+
}).passthrough();
|
|
289
285
|
|
|
290
286
|
// src/common/jwt/decode-jwt.ts
|
|
291
287
|
function decodeJwt(options) {
|
|
@@ -307,8 +303,8 @@ function decodeJwt(options) {
|
|
|
307
303
|
} catch (error) {
|
|
308
304
|
throw new Oauth2JwtParseError("Error parsing JWT");
|
|
309
305
|
}
|
|
310
|
-
const header = parseWithErrorHandling2(options.headerSchema ??
|
|
311
|
-
const payload = parseWithErrorHandling2(options.payloadSchema ??
|
|
306
|
+
const header = parseWithErrorHandling2(options.headerSchema ?? zJwtHeader, headerJson);
|
|
307
|
+
const payload = parseWithErrorHandling2(options.payloadSchema ?? zJwtPayload, payloadJson);
|
|
312
308
|
return {
|
|
313
309
|
header,
|
|
314
310
|
payload,
|
|
@@ -470,101 +466,133 @@ ${JSON.stringify(errorResponse, null, 2)}`,
|
|
|
470
466
|
}
|
|
471
467
|
};
|
|
472
468
|
|
|
473
|
-
// src/metadata/authorization-server/
|
|
474
|
-
import {
|
|
475
|
-
import
|
|
476
|
-
var
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
},
|
|
510
|
-
`Metadata value 'introspection_endpoint_auth_signing_alg_values_supported' must be defined if metadata 'introspection_endpoint_auth_methods_supported' value contains values 'private_key_jwt' or 'client_secret_jwt'`
|
|
511
|
-
)
|
|
469
|
+
// src/metadata/authorization-server/z-authorization-server-metadata.ts
|
|
470
|
+
import { zHttpsUrl } from "@openid4vc/utils";
|
|
471
|
+
import z6 from "zod";
|
|
472
|
+
var zAuthorizationServerMetadata = z6.object({
|
|
473
|
+
issuer: zHttpsUrl,
|
|
474
|
+
token_endpoint: zHttpsUrl,
|
|
475
|
+
token_endpoint_auth_methods_supported: z6.optional(z6.array(z6.string())),
|
|
476
|
+
authorization_endpoint: z6.optional(zHttpsUrl),
|
|
477
|
+
jwks_uri: z6.optional(zHttpsUrl),
|
|
478
|
+
// RFC7636
|
|
479
|
+
code_challenge_methods_supported: z6.optional(z6.array(z6.string())),
|
|
480
|
+
// RFC9449
|
|
481
|
+
dpop_signing_alg_values_supported: z6.optional(z6.array(z6.string())),
|
|
482
|
+
// RFC9126
|
|
483
|
+
require_pushed_authorization_requests: z6.optional(z6.boolean()),
|
|
484
|
+
pushed_authorization_request_endpoint: z6.optional(zHttpsUrl),
|
|
485
|
+
// RFC9068
|
|
486
|
+
introspection_endpoint: z6.optional(zHttpsUrl),
|
|
487
|
+
introspection_endpoint_auth_methods_supported: z6.optional(
|
|
488
|
+
z6.array(z6.union([z6.literal("client_secret_jwt"), z6.literal("private_key_jwt"), z6.string()]))
|
|
489
|
+
),
|
|
490
|
+
introspection_endpoint_auth_signing_alg_values_supported: z6.optional(z6.array(zAlgValueNotNone)),
|
|
491
|
+
// FiPA (no RFC yet)
|
|
492
|
+
authorization_challenge_endpoint: z6.optional(zHttpsUrl),
|
|
493
|
+
// From OID4VCI specification
|
|
494
|
+
pre_authorized_grant_anonymous_access_supported: z6.optional(z6.boolean())
|
|
495
|
+
}).passthrough().refine(
|
|
496
|
+
({
|
|
497
|
+
introspection_endpoint_auth_methods_supported: methodsSupported,
|
|
498
|
+
introspection_endpoint_auth_signing_alg_values_supported: algValuesSupported
|
|
499
|
+
}) => {
|
|
500
|
+
if (!methodsSupported) return true;
|
|
501
|
+
if (!methodsSupported.includes("private_key_jwt") && !methodsSupported.includes("client_secret_jwt")) return true;
|
|
502
|
+
return algValuesSupported !== void 0 && algValuesSupported.length > 0;
|
|
503
|
+
},
|
|
504
|
+
`Metadata value 'introspection_endpoint_auth_signing_alg_values_supported' must be defined if metadata 'introspection_endpoint_auth_methods_supported' value contains values 'private_key_jwt' or 'client_secret_jwt'`
|
|
512
505
|
);
|
|
513
506
|
|
|
514
507
|
// src/metadata/authorization-server/authorization-server-metadata.ts
|
|
515
508
|
import { joinUriParts } from "@openid4vc/utils";
|
|
516
509
|
|
|
517
510
|
// src/metadata/fetch-well-known-metadata.ts
|
|
518
|
-
import { ContentType,
|
|
511
|
+
import { ContentType, createZodFetcher } from "@openid4vc/utils";
|
|
519
512
|
import { InvalidFetchResponseError } from "@openid4vc/utils";
|
|
520
513
|
|
|
521
|
-
// ../utils/src/
|
|
522
|
-
import
|
|
523
|
-
|
|
524
|
-
//
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
514
|
+
// ../utils/src/error/ValidationError.ts
|
|
515
|
+
import { ZodIssueCode } from "zod";
|
|
516
|
+
var constants = {
|
|
517
|
+
// biome-ignore lint/suspicious/noMisleadingCharacterClass: expected
|
|
518
|
+
identifierRegex: /[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u,
|
|
519
|
+
unionSeparator: ", or ",
|
|
520
|
+
issueSeparator: "\n - "
|
|
521
|
+
};
|
|
522
|
+
var ValidationError = class extends Error {
|
|
523
|
+
escapeQuotes(str) {
|
|
524
|
+
return str.replace(/"/g, '\\"');
|
|
525
|
+
}
|
|
526
|
+
joinPath(path) {
|
|
527
|
+
if (path.length === 1) {
|
|
528
|
+
return path[0].toString();
|
|
529
|
+
}
|
|
530
|
+
return path.reduce((acc, item) => {
|
|
531
|
+
if (typeof item === "number") {
|
|
532
|
+
return `${acc}[${item.toString()}]`;
|
|
533
|
+
}
|
|
534
|
+
if (item.includes('"')) {
|
|
535
|
+
return `${acc}["${this.escapeQuotes(item)}"]`;
|
|
538
536
|
}
|
|
537
|
+
if (!constants.identifierRegex.test(item)) {
|
|
538
|
+
return `${acc}["${item}"]`;
|
|
539
|
+
}
|
|
540
|
+
const separator = acc.length === 0 ? "" : ".";
|
|
541
|
+
return acc + separator + item;
|
|
542
|
+
}, "");
|
|
543
|
+
}
|
|
544
|
+
getMessageFromUnionErrors(unionErrors) {
|
|
545
|
+
return unionErrors.reduce((acc, zodError) => {
|
|
546
|
+
const newIssues = zodError.issues.map((issue) => this.getMessageFromZodIssue(issue)).join(constants.issueSeparator);
|
|
547
|
+
if (!acc.includes(newIssues)) acc.push(newIssues);
|
|
548
|
+
return acc;
|
|
549
|
+
}, []).join(constants.unionSeparator);
|
|
550
|
+
}
|
|
551
|
+
getMessageFromZodIssue(issue) {
|
|
552
|
+
if (issue.code === ZodIssueCode.invalid_union) {
|
|
553
|
+
return this.getMessageFromUnionErrors(issue.unionErrors);
|
|
539
554
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
// ../utils/src/parse.ts
|
|
545
|
-
function valibotRecursiveFlattenIssues(issues) {
|
|
546
|
-
let flattened = v7.flatten(issues);
|
|
547
|
-
for (const issue of issues) {
|
|
548
|
-
if (issue.issues) {
|
|
549
|
-
flattened = mergeDeep(flattened, valibotRecursiveFlattenIssues(issue.issues));
|
|
555
|
+
if (issue.code === ZodIssueCode.invalid_arguments) {
|
|
556
|
+
return [issue.message, ...issue.argumentsError.issues.map((issue2) => this.getMessageFromZodIssue(issue2))].join(
|
|
557
|
+
constants.issueSeparator
|
|
558
|
+
);
|
|
550
559
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
${
|
|
561
|
-
|
|
560
|
+
if (issue.code === ZodIssueCode.invalid_return_type) {
|
|
561
|
+
return [issue.message, ...issue.returnTypeError.issues.map((issue2) => this.getMessageFromZodIssue(issue2))].join(
|
|
562
|
+
constants.issueSeparator
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
if (issue.path.length !== 0) {
|
|
566
|
+
if (issue.path.length === 1) {
|
|
567
|
+
const identifier = issue.path[0];
|
|
568
|
+
if (typeof identifier === "number") {
|
|
569
|
+
return `${issue.message} at index ${identifier}`;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return `${issue.message} at "${this.joinPath(issue.path)}"`;
|
|
573
|
+
}
|
|
574
|
+
return issue.message;
|
|
575
|
+
}
|
|
576
|
+
formatError(error) {
|
|
577
|
+
if (!error) return "";
|
|
578
|
+
return error?.issues.map((issue) => this.getMessageFromZodIssue(issue)).join(constants.issueSeparator);
|
|
579
|
+
}
|
|
580
|
+
constructor(message, zodError) {
|
|
581
|
+
super(message);
|
|
582
|
+
const formattedError = this.formatError(zodError);
|
|
583
|
+
this.message = `${message}
|
|
584
|
+
- ${formattedError}`;
|
|
585
|
+
Object.defineProperty(this, "zodError", {
|
|
586
|
+
value: zodError,
|
|
587
|
+
writable: false,
|
|
588
|
+
enumerable: false
|
|
589
|
+
});
|
|
562
590
|
}
|
|
563
591
|
};
|
|
564
592
|
|
|
565
593
|
// src/metadata/fetch-well-known-metadata.ts
|
|
566
594
|
async function fetchWellKnownMetadata(wellKnownMetadataUrl, schema, fetch) {
|
|
567
|
-
const fetcher =
|
|
595
|
+
const fetcher = createZodFetcher(fetch);
|
|
568
596
|
const { result, response } = await fetcher(schema, ContentType.Json, wellKnownMetadataUrl);
|
|
569
597
|
if (response.status === 404) {
|
|
570
598
|
return null;
|
|
@@ -576,10 +604,10 @@ async function fetchWellKnownMetadata(wellKnownMetadataUrl, schema, fetch) {
|
|
|
576
604
|
response
|
|
577
605
|
);
|
|
578
606
|
}
|
|
579
|
-
if (!result
|
|
580
|
-
throw new ValidationError(`Validation of metadata from '${wellKnownMetadataUrl}' failed`, result?.
|
|
607
|
+
if (!result?.success) {
|
|
608
|
+
throw new ValidationError(`Validation of metadata from '${wellKnownMetadataUrl}' failed`, result?.error);
|
|
581
609
|
}
|
|
582
|
-
return result.
|
|
610
|
+
return result.data;
|
|
583
611
|
}
|
|
584
612
|
|
|
585
613
|
// src/metadata/authorization-server/authorization-server-metadata.ts
|
|
@@ -590,7 +618,7 @@ async function fetchAuthorizationServerMetadata(issuer, fetch) {
|
|
|
590
618
|
const authorizationServerWellKnownMetadataUrl = joinUriParts(issuer, [wellKnownAuthorizationServerSuffix]);
|
|
591
619
|
const authorizationServerResult = await fetchWellKnownMetadata(
|
|
592
620
|
authorizationServerWellKnownMetadataUrl,
|
|
593
|
-
|
|
621
|
+
zAuthorizationServerMetadata,
|
|
594
622
|
fetch
|
|
595
623
|
);
|
|
596
624
|
if (authorizationServerResult) {
|
|
@@ -603,7 +631,7 @@ async function fetchAuthorizationServerMetadata(issuer, fetch) {
|
|
|
603
631
|
}
|
|
604
632
|
const openIdConfigurationResult = await fetchWellKnownMetadata(
|
|
605
633
|
openIdConfigurationWellKnownMetadataUrl,
|
|
606
|
-
|
|
634
|
+
zAuthorizationServerMetadata,
|
|
607
635
|
fetch
|
|
608
636
|
);
|
|
609
637
|
if (openIdConfigurationResult) {
|
|
@@ -629,17 +657,17 @@ function getAuthorizationServerMetadataFromList(authorizationServersMetadata, is
|
|
|
629
657
|
}
|
|
630
658
|
|
|
631
659
|
// src/metadata/fetch-jwks-uri.ts
|
|
632
|
-
import { ContentType as ContentType2,
|
|
660
|
+
import { ContentType as ContentType2, createZodFetcher as createZodFetcher2 } from "@openid4vc/utils";
|
|
633
661
|
import { InvalidFetchResponseError as InvalidFetchResponseError2 } from "@openid4vc/utils";
|
|
634
662
|
async function fetchJwks(authorizationServer, fetch) {
|
|
635
|
-
const fetcher =
|
|
663
|
+
const fetcher = createZodFetcher2(fetch);
|
|
636
664
|
const jwksUrl = authorizationServer.jwks_uri;
|
|
637
665
|
if (!jwksUrl) {
|
|
638
666
|
throw new Oauth2Error(
|
|
639
667
|
`Authorization server '${authorizationServer.issuer}' does not have a 'jwks_uri' parameter to fetch JWKs.`
|
|
640
668
|
);
|
|
641
669
|
}
|
|
642
|
-
const { result, response } = await fetcher(
|
|
670
|
+
const { result, response } = await fetcher(zJwkSet, ContentType2.JwkSet, jwksUrl);
|
|
643
671
|
if (!response.ok) {
|
|
644
672
|
throw new InvalidFetchResponseError2(
|
|
645
673
|
`Fetching JWKs from jwks_uri '${jwksUrl}' resulted in an unsuccessfull response with status code '${response.status}'.`,
|
|
@@ -647,32 +675,32 @@ async function fetchJwks(authorizationServer, fetch) {
|
|
|
647
675
|
response
|
|
648
676
|
);
|
|
649
677
|
}
|
|
650
|
-
if (!result
|
|
651
|
-
throw new ValidationError(`Validation of JWKs from jwks_uri '${jwksUrl}' failed`, result?.
|
|
678
|
+
if (!result?.success) {
|
|
679
|
+
throw new ValidationError(`Validation of JWKs from jwks_uri '${jwksUrl}' failed`, result?.error);
|
|
652
680
|
}
|
|
653
|
-
return result.
|
|
681
|
+
return result.data;
|
|
654
682
|
}
|
|
655
683
|
|
|
656
|
-
// src/access-token/
|
|
657
|
-
import {
|
|
658
|
-
import
|
|
659
|
-
var
|
|
660
|
-
...
|
|
661
|
-
typ:
|
|
662
|
-
});
|
|
663
|
-
var
|
|
664
|
-
...
|
|
665
|
-
iss:
|
|
666
|
-
exp:
|
|
667
|
-
iat:
|
|
668
|
-
aud:
|
|
669
|
-
sub:
|
|
684
|
+
// src/access-token/z-access-token-jwt.ts
|
|
685
|
+
import { zInteger as zInteger2 } from "@openid4vc/utils";
|
|
686
|
+
import z7 from "zod";
|
|
687
|
+
var zAccessTokenProfileJwtHeader = z7.object({
|
|
688
|
+
...zJwtHeader.shape,
|
|
689
|
+
typ: z7.enum(["application/at+jwt", "at+jwt"])
|
|
690
|
+
}).passthrough();
|
|
691
|
+
var zAccessTokenProfileJwtPayload = z7.object({
|
|
692
|
+
...zJwtPayload.shape,
|
|
693
|
+
iss: z7.string(),
|
|
694
|
+
exp: zInteger2,
|
|
695
|
+
iat: zInteger2,
|
|
696
|
+
aud: z7.string(),
|
|
697
|
+
sub: z7.string(),
|
|
670
698
|
// REQUIRED according to RFC 9068, but OID4VCI allows anonymous access
|
|
671
|
-
client_id:
|
|
672
|
-
jti:
|
|
699
|
+
client_id: z7.optional(z7.string()),
|
|
700
|
+
jti: z7.string(),
|
|
673
701
|
// SHOULD be included in the authorization request contained it
|
|
674
|
-
scope:
|
|
675
|
-
});
|
|
702
|
+
scope: z7.optional(z7.string())
|
|
703
|
+
}).passthrough();
|
|
676
704
|
|
|
677
705
|
// src/access-token/verify-access-token.ts
|
|
678
706
|
var SupportedAuthenticationScheme = /* @__PURE__ */ ((SupportedAuthenticationScheme2) => {
|
|
@@ -683,8 +711,8 @@ var SupportedAuthenticationScheme = /* @__PURE__ */ ((SupportedAuthenticationSch
|
|
|
683
711
|
async function verifyJwtProfileAccessToken(options) {
|
|
684
712
|
const decodedJwt = decodeJwt({
|
|
685
713
|
jwt: options.accessToken,
|
|
686
|
-
headerSchema:
|
|
687
|
-
payloadSchema:
|
|
714
|
+
headerSchema: zAccessTokenProfileJwtHeader,
|
|
715
|
+
payloadSchema: zAccessTokenProfileJwtPayload
|
|
688
716
|
});
|
|
689
717
|
const authorizationServer = options.authorizationServers.find(({ issuer }) => decodedJwt.payload.iss === issuer);
|
|
690
718
|
if (!authorizationServer) {
|
|
@@ -727,23 +755,23 @@ import {
|
|
|
727
755
|
parseWithErrorHandling as parseWithErrorHandling3
|
|
728
756
|
} from "@openid4vc/utils";
|
|
729
757
|
|
|
730
|
-
// src/dpop/
|
|
731
|
-
import
|
|
732
|
-
import
|
|
733
|
-
var
|
|
734
|
-
...
|
|
735
|
-
iat:
|
|
736
|
-
htu:
|
|
737
|
-
htm:
|
|
738
|
-
jti:
|
|
758
|
+
// src/dpop/z-dpop.ts
|
|
759
|
+
import { zHttpMethod, zHttpsUrl as zHttpsUrl2, zInteger as zInteger3 } from "@openid4vc/utils";
|
|
760
|
+
import z8 from "zod";
|
|
761
|
+
var zDpopJwtPayload = z8.object({
|
|
762
|
+
...zJwtPayload.shape,
|
|
763
|
+
iat: zInteger3,
|
|
764
|
+
htu: zHttpsUrl2,
|
|
765
|
+
htm: zHttpMethod,
|
|
766
|
+
jti: z8.string(),
|
|
739
767
|
// Only required when presenting in combination with access token
|
|
740
|
-
ath:
|
|
741
|
-
});
|
|
742
|
-
var
|
|
743
|
-
...
|
|
744
|
-
typ:
|
|
745
|
-
jwk:
|
|
746
|
-
});
|
|
768
|
+
ath: z8.optional(z8.string())
|
|
769
|
+
}).passthrough();
|
|
770
|
+
var zDpopJwtHeader = z8.object({
|
|
771
|
+
...zJwtHeader.shape,
|
|
772
|
+
typ: z8.literal("dpop+jwt"),
|
|
773
|
+
jwk: zJwk
|
|
774
|
+
}).passthrough();
|
|
747
775
|
|
|
748
776
|
// src/dpop/dpop.ts
|
|
749
777
|
async function createDpopHeadersForRequest(options) {
|
|
@@ -757,12 +785,12 @@ async function createDpopJwt(options) {
|
|
|
757
785
|
if (options.accessToken) {
|
|
758
786
|
ath = encodeToBase64Url2(await options.callbacks.hash(decodeUtf8String2(options.accessToken), "SHA-256" /* Sha256 */));
|
|
759
787
|
}
|
|
760
|
-
const header = parseWithErrorHandling3(
|
|
788
|
+
const header = parseWithErrorHandling3(zDpopJwtHeader, {
|
|
761
789
|
typ: "dpop+jwt",
|
|
762
790
|
jwk: options.signer.publicJwk,
|
|
763
791
|
alg: options.signer.alg
|
|
764
792
|
});
|
|
765
|
-
const payload = parseWithErrorHandling3(
|
|
793
|
+
const payload = parseWithErrorHandling3(zDpopJwtPayload, {
|
|
766
794
|
htu: htuFromRequestUrl(options.request.url),
|
|
767
795
|
iat: dateToSeconds2(options.issuedAt),
|
|
768
796
|
htm: options.request.method,
|
|
@@ -780,8 +808,8 @@ async function createDpopJwt(options) {
|
|
|
780
808
|
async function verifyDpopJwt(options) {
|
|
781
809
|
const { header, payload } = decodeJwt({
|
|
782
810
|
jwt: options.dpopJwt,
|
|
783
|
-
headerSchema:
|
|
784
|
-
payloadSchema:
|
|
811
|
+
headerSchema: zDpopJwtHeader,
|
|
812
|
+
payloadSchema: zDpopJwtPayload
|
|
785
813
|
});
|
|
786
814
|
if (options.allowedSigningAlgs && !options.allowedSigningAlgs.includes(header.alg)) {
|
|
787
815
|
throw new Oauth2Error(
|
|
@@ -985,37 +1013,37 @@ async function resourceRequest(options) {
|
|
|
985
1013
|
import { ValidationError as ValidationError2 } from "@openid4vc/utils";
|
|
986
1014
|
|
|
987
1015
|
// src/access-token/introspect-token.ts
|
|
988
|
-
import { ContentType as ContentType3,
|
|
1016
|
+
import { ContentType as ContentType3, createZodFetcher as createZodFetcher3, objectToQueryParams, parseWithErrorHandling as parseWithErrorHandling4 } from "@openid4vc/utils";
|
|
989
1017
|
import { InvalidFetchResponseError as InvalidFetchResponseError3 } from "@openid4vc/utils";
|
|
990
1018
|
import { Headers } from "@openid4vc/utils";
|
|
991
1019
|
|
|
992
|
-
// src/access-token/
|
|
993
|
-
import {
|
|
994
|
-
import
|
|
995
|
-
var
|
|
996
|
-
token:
|
|
997
|
-
token_type_hint:
|
|
998
|
-
});
|
|
999
|
-
var
|
|
1000
|
-
active:
|
|
1001
|
-
scope:
|
|
1002
|
-
client_id:
|
|
1003
|
-
username:
|
|
1004
|
-
token_type:
|
|
1005
|
-
exp:
|
|
1006
|
-
iat:
|
|
1007
|
-
nbf:
|
|
1008
|
-
sub:
|
|
1009
|
-
aud:
|
|
1010
|
-
iss:
|
|
1011
|
-
jti:
|
|
1012
|
-
cnf:
|
|
1013
|
-
});
|
|
1020
|
+
// src/access-token/z-token-introspection.ts
|
|
1021
|
+
import { zInteger as zInteger4 } from "@openid4vc/utils";
|
|
1022
|
+
import z9 from "zod";
|
|
1023
|
+
var zTokenIntrospectionRequest = z9.object({
|
|
1024
|
+
token: z9.string(),
|
|
1025
|
+
token_type_hint: z9.optional(z9.string())
|
|
1026
|
+
}).passthrough();
|
|
1027
|
+
var zTokenIntrospectionResponse = z9.object({
|
|
1028
|
+
active: z9.boolean(),
|
|
1029
|
+
scope: z9.optional(z9.string()),
|
|
1030
|
+
client_id: z9.optional(z9.string()),
|
|
1031
|
+
username: z9.optional(z9.string()),
|
|
1032
|
+
token_type: z9.optional(z9.string()),
|
|
1033
|
+
exp: z9.optional(zInteger4),
|
|
1034
|
+
iat: z9.optional(zInteger4),
|
|
1035
|
+
nbf: z9.optional(zInteger4),
|
|
1036
|
+
sub: z9.optional(z9.string()),
|
|
1037
|
+
aud: z9.optional(z9.string()),
|
|
1038
|
+
iss: z9.optional(z9.string()),
|
|
1039
|
+
jti: z9.optional(z9.string()),
|
|
1040
|
+
cnf: z9.optional(zJwtConfirmationPayload)
|
|
1041
|
+
}).passthrough();
|
|
1014
1042
|
|
|
1015
1043
|
// src/access-token/introspect-token.ts
|
|
1016
1044
|
async function introspectToken(options) {
|
|
1017
|
-
const
|
|
1018
|
-
const introspectionRequest = parseWithErrorHandling4(
|
|
1045
|
+
const fetchWithZod = createZodFetcher3(options.callbacks.fetch);
|
|
1046
|
+
const introspectionRequest = parseWithErrorHandling4(zTokenIntrospectionRequest, {
|
|
1019
1047
|
token: options.token,
|
|
1020
1048
|
token_type_hint: options.tokenTypeHint,
|
|
1021
1049
|
...options.additionalPayload
|
|
@@ -1035,8 +1063,8 @@ async function introspectToken(options) {
|
|
|
1035
1063
|
contentType: ContentType3.XWwwFormUrlencoded,
|
|
1036
1064
|
headers
|
|
1037
1065
|
});
|
|
1038
|
-
const { result, response } = await
|
|
1039
|
-
|
|
1066
|
+
const { result, response } = await fetchWithZod(
|
|
1067
|
+
zTokenIntrospectionResponse,
|
|
1040
1068
|
ContentType3.Json,
|
|
1041
1069
|
introspectionEndpoint,
|
|
1042
1070
|
{
|
|
@@ -1052,7 +1080,7 @@ async function introspectToken(options) {
|
|
|
1052
1080
|
response
|
|
1053
1081
|
);
|
|
1054
1082
|
}
|
|
1055
|
-
return result.
|
|
1083
|
+
return result.data;
|
|
1056
1084
|
}
|
|
1057
1085
|
|
|
1058
1086
|
// src/resource-request/verify-resource-request.ts
|
|
@@ -1229,8 +1257,8 @@ function getSupportedClientAuthenticationMethod(authorizationServer, endpointTyp
|
|
|
1229
1257
|
}
|
|
1230
1258
|
function clientAuthenticationDynamic(options) {
|
|
1231
1259
|
return (callbackOptions) => {
|
|
1232
|
-
const { url
|
|
1233
|
-
const endpointType =
|
|
1260
|
+
const { url, authorizationServerMetata } = callbackOptions;
|
|
1261
|
+
const endpointType = url === authorizationServerMetata.introspection_endpoint ? "introspection" : "endpoint";
|
|
1234
1262
|
const method = getSupportedClientAuthenticationMethod(authorizationServerMetata, endpointType);
|
|
1235
1263
|
if (method === "client_secret_basic" /* ClientSecretBasic */) {
|
|
1236
1264
|
return clientAuthenticationClientSecretBasic(options)(callbackOptions);
|
|
@@ -1268,12 +1296,12 @@ import { parseWithErrorHandling as parseWithErrorHandling11 } from "@openid4vc/u
|
|
|
1268
1296
|
// src/access-token/create-access-token.ts
|
|
1269
1297
|
import { addSecondsToDate, dateToSeconds as dateToSeconds3, encodeToBase64Url as encodeToBase64Url4, parseWithErrorHandling as parseWithErrorHandling5 } from "@openid4vc/utils";
|
|
1270
1298
|
async function createAccessTokenJwt(options) {
|
|
1271
|
-
const header = parseWithErrorHandling5(
|
|
1299
|
+
const header = parseWithErrorHandling5(zAccessTokenProfileJwtHeader, {
|
|
1272
1300
|
...jwtHeaderFromJwtSigner(options.signer),
|
|
1273
1301
|
typ: "at+jwt"
|
|
1274
1302
|
});
|
|
1275
1303
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
1276
|
-
const payload = parseWithErrorHandling5(
|
|
1304
|
+
const payload = parseWithErrorHandling5(zAccessTokenProfileJwtPayload, {
|
|
1277
1305
|
iat: dateToSeconds3(now),
|
|
1278
1306
|
exp: dateToSeconds3(addSecondsToDate(now, options.expiresInSeconds)),
|
|
1279
1307
|
aud: options.audience,
|
|
@@ -1303,84 +1331,75 @@ async function createAccessTokenJwt(options) {
|
|
|
1303
1331
|
// src/access-token/create-access-token-response.ts
|
|
1304
1332
|
import { parseWithErrorHandling as parseWithErrorHandling6 } from "@openid4vc/utils";
|
|
1305
1333
|
|
|
1306
|
-
// src/access-token/
|
|
1307
|
-
import
|
|
1308
|
-
import {
|
|
1309
|
-
|
|
1310
|
-
// src/
|
|
1311
|
-
import
|
|
1312
|
-
var
|
|
1313
|
-
var preAuthorizedCodeGrantIdentifier =
|
|
1314
|
-
var
|
|
1315
|
-
var authorizationCodeGrantIdentifier =
|
|
1316
|
-
var
|
|
1317
|
-
var refreshTokenGrantIdentifier =
|
|
1318
|
-
|
|
1319
|
-
// src/access-token/
|
|
1320
|
-
var
|
|
1321
|
-
|
|
1334
|
+
// src/access-token/z-access-token.ts
|
|
1335
|
+
import z11 from "zod";
|
|
1336
|
+
import { zHttpsUrl as zHttpsUrl3 } from "@openid4vc/utils";
|
|
1337
|
+
|
|
1338
|
+
// src/z-grant-type.ts
|
|
1339
|
+
import z10 from "zod";
|
|
1340
|
+
var zPreAuthorizedCodeGrantIdentifier = z10.literal("urn:ietf:params:oauth:grant-type:pre-authorized_code");
|
|
1341
|
+
var preAuthorizedCodeGrantIdentifier = zPreAuthorizedCodeGrantIdentifier.value;
|
|
1342
|
+
var zAuthorizationCodeGrantIdentifier = z10.literal("authorization_code");
|
|
1343
|
+
var authorizationCodeGrantIdentifier = zAuthorizationCodeGrantIdentifier.value;
|
|
1344
|
+
var zRefreshTokenGrantIdentifier = z10.literal("refresh_token");
|
|
1345
|
+
var refreshTokenGrantIdentifier = zRefreshTokenGrantIdentifier.value;
|
|
1346
|
+
|
|
1347
|
+
// src/access-token/z-access-token.ts
|
|
1348
|
+
var zAccessTokenRequest = z11.intersection(
|
|
1349
|
+
z11.object({
|
|
1322
1350
|
// Pre authorized code flow
|
|
1323
|
-
"pre-authorized_code":
|
|
1351
|
+
"pre-authorized_code": z11.optional(z11.string()),
|
|
1324
1352
|
// Authorization code flow
|
|
1325
|
-
code:
|
|
1326
|
-
redirect_uri:
|
|
1353
|
+
code: z11.optional(z11.string()),
|
|
1354
|
+
redirect_uri: z11.string().url().optional(),
|
|
1327
1355
|
// Refresh token grant
|
|
1328
|
-
refresh_token:
|
|
1329
|
-
resource:
|
|
1330
|
-
code_verifier:
|
|
1331
|
-
grant_type:
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1356
|
+
refresh_token: z11.optional(z11.string()),
|
|
1357
|
+
resource: z11.optional(zHttpsUrl3),
|
|
1358
|
+
code_verifier: z11.optional(z11.string()),
|
|
1359
|
+
grant_type: z11.union([
|
|
1360
|
+
zPreAuthorizedCodeGrantIdentifier,
|
|
1361
|
+
zAuthorizationCodeGrantIdentifier,
|
|
1362
|
+
zRefreshTokenGrantIdentifier,
|
|
1335
1363
|
// string makes the previous ones unessary, but it does help with error messages
|
|
1336
|
-
|
|
1364
|
+
z11.string()
|
|
1337
1365
|
])
|
|
1338
|
-
}),
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
)
|
|
1358
|
-
|
|
1359
|
-
var vAccessTokenResponse = v12.looseObject({
|
|
1360
|
-
access_token: v12.string(),
|
|
1361
|
-
token_type: v12.string(),
|
|
1362
|
-
expires_in: v12.optional(v12.pipe(v12.number(), v12.integer())),
|
|
1363
|
-
scope: v12.optional(v12.string()),
|
|
1364
|
-
state: v12.optional(v12.string()),
|
|
1365
|
-
refresh_token: v12.optional(v12.string()),
|
|
1366
|
+
}).passthrough(),
|
|
1367
|
+
z11.object({
|
|
1368
|
+
tx_code: z11.optional(z11.string()),
|
|
1369
|
+
// user_pin is from OID4VCI draft 11
|
|
1370
|
+
user_pin: z11.optional(z11.string())
|
|
1371
|
+
}).passthrough().refine(({ tx_code, user_pin }) => !tx_code || !user_pin || user_pin === tx_code, {
|
|
1372
|
+
message: `If both 'tx_code' and 'user_pin' are present they must match`
|
|
1373
|
+
}).transform(({ tx_code, user_pin, ...rest }) => {
|
|
1374
|
+
return {
|
|
1375
|
+
...rest,
|
|
1376
|
+
...tx_code ?? user_pin ? { tx_code: tx_code ?? user_pin } : {}
|
|
1377
|
+
};
|
|
1378
|
+
})
|
|
1379
|
+
);
|
|
1380
|
+
var zAccessTokenResponse = z11.object({
|
|
1381
|
+
access_token: z11.string(),
|
|
1382
|
+
token_type: z11.string(),
|
|
1383
|
+
expires_in: z11.optional(z11.number().int()),
|
|
1384
|
+
scope: z11.optional(z11.string()),
|
|
1385
|
+
state: z11.optional(z11.string()),
|
|
1386
|
+
refresh_token: z11.optional(z11.string()),
|
|
1366
1387
|
// Oid4vci specific parameters
|
|
1367
|
-
c_nonce:
|
|
1368
|
-
c_nonce_expires_in:
|
|
1388
|
+
c_nonce: z11.optional(z11.string()),
|
|
1389
|
+
c_nonce_expires_in: z11.optional(z11.number().int()),
|
|
1369
1390
|
// TODO: add additional params
|
|
1370
|
-
authorization_details:
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
});
|
|
1379
|
-
var vAccessTokenErrorResponse = vOauth2ErrorResponse;
|
|
1391
|
+
authorization_details: z11.array(
|
|
1392
|
+
z11.object({
|
|
1393
|
+
// requried when type is openid_credential (so we probably need a discriminator)
|
|
1394
|
+
// credential_identifiers: z.array(z.string()),
|
|
1395
|
+
}).passthrough()
|
|
1396
|
+
).optional()
|
|
1397
|
+
}).passthrough();
|
|
1398
|
+
var zAccessTokenErrorResponse = zOauth2ErrorResponse;
|
|
1380
1399
|
|
|
1381
1400
|
// src/access-token/create-access-token-response.ts
|
|
1382
1401
|
async function createAccessTokenResponse(options) {
|
|
1383
|
-
const accessTokenResponse = parseWithErrorHandling6(
|
|
1402
|
+
const accessTokenResponse = parseWithErrorHandling6(zAccessTokenResponse, {
|
|
1384
1403
|
access_token: options.accessToken,
|
|
1385
1404
|
token_type: options.tokenType,
|
|
1386
1405
|
expires_in: options.expiresInSeconds,
|
|
@@ -1392,18 +1411,16 @@ async function createAccessTokenResponse(options) {
|
|
|
1392
1411
|
}
|
|
1393
1412
|
|
|
1394
1413
|
// src/access-token/parse-access-token-request.ts
|
|
1395
|
-
import { valibotRecursiveFlattenIssues as valibotRecursiveFlattenIssues2 } from "@openid4vc/utils";
|
|
1396
|
-
import * as v13 from "valibot";
|
|
1397
1414
|
function parseAccessTokenRequest(options) {
|
|
1398
|
-
const parsedAccessTokenRequest =
|
|
1415
|
+
const parsedAccessTokenRequest = zAccessTokenRequest.safeParse(options.accessTokenRequest);
|
|
1399
1416
|
if (!parsedAccessTokenRequest.success) {
|
|
1400
1417
|
throw new Oauth2ServerErrorResponseError({
|
|
1401
1418
|
error: "invalid_request" /* InvalidRequest */,
|
|
1402
1419
|
error_description: `Error occured during validation of authorization request.
|
|
1403
|
-
${JSON.stringify(
|
|
1420
|
+
${JSON.stringify(parsedAccessTokenRequest.error.issues, null, 2)}`
|
|
1404
1421
|
});
|
|
1405
1422
|
}
|
|
1406
|
-
const accessTokenRequest = parsedAccessTokenRequest.
|
|
1423
|
+
const accessTokenRequest = parsedAccessTokenRequest.data;
|
|
1407
1424
|
let grant;
|
|
1408
1425
|
if (accessTokenRequest.grant_type === preAuthorizedCodeGrantIdentifier) {
|
|
1409
1426
|
if (!accessTokenRequest["pre-authorized_code"]) {
|
|
@@ -1629,67 +1646,67 @@ async function verifyAccessTokenRequestPkce(options, callbacks) {
|
|
|
1629
1646
|
// src/authorization-challenge/create-authorization-challenge-response.ts
|
|
1630
1647
|
import { parseWithErrorHandling as parseWithErrorHandling7 } from "@openid4vc/utils";
|
|
1631
1648
|
|
|
1632
|
-
// src/authorization-challenge/
|
|
1633
|
-
import {
|
|
1634
|
-
import
|
|
1635
|
-
|
|
1636
|
-
// src/authorization-request/
|
|
1637
|
-
import {
|
|
1638
|
-
import
|
|
1639
|
-
var
|
|
1640
|
-
response_type:
|
|
1641
|
-
client_id:
|
|
1642
|
-
issuer_state:
|
|
1643
|
-
redirect_uri:
|
|
1644
|
-
resource:
|
|
1645
|
-
scope:
|
|
1649
|
+
// src/authorization-challenge/z-authorization-challenge.ts
|
|
1650
|
+
import { zInteger as zInteger5 } from "@openid4vc/utils";
|
|
1651
|
+
import z13 from "zod";
|
|
1652
|
+
|
|
1653
|
+
// src/authorization-request/z-authorization-request.ts
|
|
1654
|
+
import { zHttpsUrl as zHttpsUrl4 } from "@openid4vc/utils";
|
|
1655
|
+
import z12 from "zod";
|
|
1656
|
+
var zAuthorizationRequest = z12.object({
|
|
1657
|
+
response_type: z12.string(),
|
|
1658
|
+
client_id: z12.string(),
|
|
1659
|
+
issuer_state: z12.optional(z12.string()),
|
|
1660
|
+
redirect_uri: z12.string().url().optional(),
|
|
1661
|
+
resource: z12.optional(zHttpsUrl4),
|
|
1662
|
+
scope: z12.optional(z12.string()),
|
|
1646
1663
|
// DPoP jwk thumbprint
|
|
1647
|
-
dpop_jkt:
|
|
1648
|
-
code_challenge:
|
|
1649
|
-
code_challenge_method:
|
|
1650
|
-
});
|
|
1651
|
-
var
|
|
1652
|
-
request_uri:
|
|
1653
|
-
client_id:
|
|
1654
|
-
});
|
|
1655
|
-
var
|
|
1656
|
-
request_uri:
|
|
1657
|
-
expires_in:
|
|
1658
|
-
});
|
|
1659
|
-
|
|
1660
|
-
// src/authorization-challenge/
|
|
1661
|
-
var
|
|
1664
|
+
dpop_jkt: z12.optional(z12.string()),
|
|
1665
|
+
code_challenge: z12.optional(z12.string()),
|
|
1666
|
+
code_challenge_method: z12.optional(z12.string())
|
|
1667
|
+
}).passthrough();
|
|
1668
|
+
var zPushedAuthorizationRequest = z12.object({
|
|
1669
|
+
request_uri: z12.string(),
|
|
1670
|
+
client_id: z12.string()
|
|
1671
|
+
}).passthrough();
|
|
1672
|
+
var zPushedAuthorizationResponse = z12.object({
|
|
1673
|
+
request_uri: z12.string(),
|
|
1674
|
+
expires_in: z12.number().int()
|
|
1675
|
+
}).passthrough();
|
|
1676
|
+
|
|
1677
|
+
// src/authorization-challenge/z-authorization-challenge.ts
|
|
1678
|
+
var zAuthorizationChallengeRequest = z13.object({
|
|
1662
1679
|
// authorization challenge request can include same parameters as an authorization request
|
|
1663
1680
|
// except for response_type (always `code`), and `client_id` is optional (becase
|
|
1664
1681
|
// it's possible to do client authentication using different methods)
|
|
1665
|
-
...
|
|
1666
|
-
client_id:
|
|
1667
|
-
auth_session:
|
|
1682
|
+
...zAuthorizationRequest.omit({ response_type: true, client_id: true }).shape,
|
|
1683
|
+
client_id: z13.optional(zAuthorizationRequest.shape.client_id),
|
|
1684
|
+
auth_session: z13.optional(z13.string()),
|
|
1668
1685
|
// DRAFT presentation during issuance
|
|
1669
|
-
presentation_during_issuance_session:
|
|
1670
|
-
});
|
|
1671
|
-
var
|
|
1672
|
-
authorization_code:
|
|
1673
|
-
});
|
|
1674
|
-
var
|
|
1675
|
-
...
|
|
1676
|
-
auth_session:
|
|
1677
|
-
request_uri:
|
|
1678
|
-
expires_in:
|
|
1686
|
+
presentation_during_issuance_session: z13.optional(z13.string())
|
|
1687
|
+
}).passthrough();
|
|
1688
|
+
var zAuthorizationChallengeResponse = z13.object({
|
|
1689
|
+
authorization_code: z13.string()
|
|
1690
|
+
}).passthrough();
|
|
1691
|
+
var zAuthorizationChallengeErrorResponse = z13.object({
|
|
1692
|
+
...zOauth2ErrorResponse.shape,
|
|
1693
|
+
auth_session: z13.optional(z13.string()),
|
|
1694
|
+
request_uri: z13.optional(z13.string()),
|
|
1695
|
+
expires_in: z13.optional(zInteger5),
|
|
1679
1696
|
// DRAFT: presentation during issuance
|
|
1680
|
-
presentation:
|
|
1681
|
-
});
|
|
1697
|
+
presentation: z13.optional(z13.string())
|
|
1698
|
+
}).passthrough();
|
|
1682
1699
|
|
|
1683
1700
|
// src/authorization-challenge/create-authorization-challenge-response.ts
|
|
1684
1701
|
function createAuthorizationChallengeResponse(options) {
|
|
1685
|
-
const authorizationChallengeResponse = parseWithErrorHandling7(
|
|
1702
|
+
const authorizationChallengeResponse = parseWithErrorHandling7(zAuthorizationChallengeResponse, {
|
|
1686
1703
|
...options.additionalPayload,
|
|
1687
1704
|
authorization_code: options.authorizationCode
|
|
1688
1705
|
});
|
|
1689
1706
|
return { authorizationChallengeResponse };
|
|
1690
1707
|
}
|
|
1691
1708
|
function createAuthorizationChallengeErrorResponse(options) {
|
|
1692
|
-
const authorizationChallengeErrorResponse = parseWithErrorHandling7(
|
|
1709
|
+
const authorizationChallengeErrorResponse = parseWithErrorHandling7(zAuthorizationChallengeErrorResponse, {
|
|
1693
1710
|
...options.additionalPayload,
|
|
1694
1711
|
// General FiPA
|
|
1695
1712
|
error: options.error,
|
|
@@ -1708,7 +1725,7 @@ function createAuthorizationChallengeErrorResponse(options) {
|
|
|
1708
1725
|
import { parseWithErrorHandling as parseWithErrorHandling8 } from "@openid4vc/utils";
|
|
1709
1726
|
function parseAuthorizationChallengeRequest(options) {
|
|
1710
1727
|
const authorizationChallengeRequest = parseWithErrorHandling8(
|
|
1711
|
-
|
|
1728
|
+
zAuthorizationChallengeRequest,
|
|
1712
1729
|
options.authorizationChallengeRequest
|
|
1713
1730
|
);
|
|
1714
1731
|
return { authorizationChallengeRequest };
|
|
@@ -1717,58 +1734,58 @@ function parseAuthorizationChallengeRequest(options) {
|
|
|
1717
1734
|
// src/client-attestation/clent-attestation.ts
|
|
1718
1735
|
import { dateToSeconds as dateToSeconds4, parseWithErrorHandling as parseWithErrorHandling9 } from "@openid4vc/utils";
|
|
1719
1736
|
|
|
1720
|
-
// src/client-attestation/
|
|
1721
|
-
import
|
|
1722
|
-
import
|
|
1723
|
-
var
|
|
1724
|
-
var oauthClientAttestationHeader =
|
|
1725
|
-
var
|
|
1726
|
-
...
|
|
1727
|
-
iss:
|
|
1728
|
-
sub:
|
|
1729
|
-
exp:
|
|
1730
|
-
cnf:
|
|
1731
|
-
jwk:
|
|
1732
|
-
key_type:
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1737
|
+
// src/client-attestation/z-client-attestation.ts
|
|
1738
|
+
import { zHttpsUrl as zHttpsUrl5, zInteger as zInteger6 } from "@openid4vc/utils";
|
|
1739
|
+
import z14 from "zod";
|
|
1740
|
+
var zOauthClientAttestationHeader = z14.literal("OAuth-Client-Attestation");
|
|
1741
|
+
var oauthClientAttestationHeader = zOauthClientAttestationHeader.value;
|
|
1742
|
+
var zClientAttestationJwtPayload = z14.object({
|
|
1743
|
+
...zJwtPayload.shape,
|
|
1744
|
+
iss: z14.string(),
|
|
1745
|
+
sub: z14.string(),
|
|
1746
|
+
exp: zInteger6,
|
|
1747
|
+
cnf: z14.object({
|
|
1748
|
+
jwk: zJwk,
|
|
1749
|
+
key_type: z14.optional(
|
|
1750
|
+
z14.union([
|
|
1751
|
+
z14.enum(["software", "hardware", "tee", "secure_enclave", "strong_box", "secure_element", "hsm"]),
|
|
1752
|
+
z14.string()
|
|
1736
1753
|
])
|
|
1737
1754
|
),
|
|
1738
|
-
user_authentication:
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1755
|
+
user_authentication: z14.optional(
|
|
1756
|
+
z14.union([
|
|
1757
|
+
z14.enum(["system_biometry", "system_pin", "internal_biometry", "internal_pin", "secure_element_pin"]),
|
|
1758
|
+
z14.string()
|
|
1742
1759
|
])
|
|
1743
1760
|
)
|
|
1744
|
-
}),
|
|
1745
|
-
aal:
|
|
1746
|
-
});
|
|
1747
|
-
var
|
|
1748
|
-
...
|
|
1749
|
-
typ:
|
|
1750
|
-
});
|
|
1751
|
-
var
|
|
1752
|
-
var oauthClientAttestationPopHeader =
|
|
1753
|
-
var
|
|
1754
|
-
...
|
|
1755
|
-
iss:
|
|
1756
|
-
exp:
|
|
1757
|
-
aud:
|
|
1758
|
-
jti:
|
|
1759
|
-
nonce:
|
|
1760
|
-
});
|
|
1761
|
-
var
|
|
1762
|
-
...
|
|
1763
|
-
typ:
|
|
1764
|
-
});
|
|
1761
|
+
}).passthrough(),
|
|
1762
|
+
aal: z14.optional(z14.string())
|
|
1763
|
+
}).passthrough();
|
|
1764
|
+
var zClientAttestationJwtHeader = z14.object({
|
|
1765
|
+
...zJwtHeader.shape,
|
|
1766
|
+
typ: z14.literal("oauth-client-attestation+jwt")
|
|
1767
|
+
}).passthrough();
|
|
1768
|
+
var zOauthClientAttestationPopHeader = z14.literal("OAuth-Client-Attestation-PoP");
|
|
1769
|
+
var oauthClientAttestationPopHeader = zOauthClientAttestationPopHeader.value;
|
|
1770
|
+
var zClientAttestationPopJwtPayload = z14.object({
|
|
1771
|
+
...zJwtPayload.shape,
|
|
1772
|
+
iss: z14.string(),
|
|
1773
|
+
exp: zInteger6,
|
|
1774
|
+
aud: zHttpsUrl5,
|
|
1775
|
+
jti: z14.string(),
|
|
1776
|
+
nonce: z14.optional(z14.string())
|
|
1777
|
+
}).passthrough();
|
|
1778
|
+
var zClientAttestationPopJwtHeader = z14.object({
|
|
1779
|
+
...zJwtHeader.shape,
|
|
1780
|
+
typ: z14.literal("oauth-client-attestation-pop+jwt")
|
|
1781
|
+
}).passthrough();
|
|
1765
1782
|
|
|
1766
1783
|
// src/client-attestation/clent-attestation.ts
|
|
1767
1784
|
async function verifyClientAttestationJwt(options) {
|
|
1768
1785
|
const { header, payload } = decodeJwt({
|
|
1769
1786
|
jwt: options.clientAttestationJwt,
|
|
1770
|
-
headerSchema:
|
|
1771
|
-
payloadSchema:
|
|
1787
|
+
headerSchema: zClientAttestationJwtHeader,
|
|
1788
|
+
payloadSchema: zClientAttestationJwtPayload
|
|
1772
1789
|
});
|
|
1773
1790
|
const { signer } = await verifyJwt({
|
|
1774
1791
|
signer: jwtSignerFromJwt({ header, payload }),
|
|
@@ -1786,11 +1803,11 @@ async function verifyClientAttestationJwt(options) {
|
|
|
1786
1803
|
};
|
|
1787
1804
|
}
|
|
1788
1805
|
async function createClientAttestationJwt(options) {
|
|
1789
|
-
const header = parseWithErrorHandling9(
|
|
1806
|
+
const header = parseWithErrorHandling9(zClientAttestationJwtHeader, {
|
|
1790
1807
|
typ: "oauth-client-attestation+jwt",
|
|
1791
1808
|
...jwtHeaderFromJwtSigner(options.signer)
|
|
1792
1809
|
});
|
|
1793
|
-
const payload = parseWithErrorHandling9(
|
|
1810
|
+
const payload = parseWithErrorHandling9(zClientAttestationJwtPayload, {
|
|
1794
1811
|
iss: options.issuer,
|
|
1795
1812
|
iat: dateToSeconds4(options.issuedAt),
|
|
1796
1813
|
exp: dateToSeconds4(options.expiresAt),
|
|
@@ -1844,8 +1861,8 @@ async function createClientAttestationForRequest(options) {
|
|
|
1844
1861
|
async function verifyClientAttestationPopJwt(options) {
|
|
1845
1862
|
const { header, payload } = decodeJwt({
|
|
1846
1863
|
jwt: options.clientAttestationPopJwt,
|
|
1847
|
-
headerSchema:
|
|
1848
|
-
payloadSchema:
|
|
1864
|
+
headerSchema: zClientAttestationPopJwtHeader,
|
|
1865
|
+
payloadSchema: zClientAttestationPopJwtPayload
|
|
1849
1866
|
});
|
|
1850
1867
|
if (payload.iss !== options.clientAttestation.payload.sub) {
|
|
1851
1868
|
throw new Oauth2Error(
|
|
@@ -1878,17 +1895,17 @@ async function verifyClientAttestationPopJwt(options) {
|
|
|
1878
1895
|
};
|
|
1879
1896
|
}
|
|
1880
1897
|
async function createClientAttestationPopJwt(options) {
|
|
1881
|
-
const header = parseWithErrorHandling10(
|
|
1898
|
+
const header = parseWithErrorHandling10(zClientAttestationPopJwtHeader, {
|
|
1882
1899
|
typ: "oauth-client-attestation-pop+jwt",
|
|
1883
1900
|
alg: options.signer.alg
|
|
1884
1901
|
});
|
|
1885
1902
|
const clientAttestation = decodeJwt({
|
|
1886
1903
|
jwt: options.clientAttestation,
|
|
1887
|
-
headerSchema:
|
|
1888
|
-
payloadSchema:
|
|
1904
|
+
headerSchema: zClientAttestationJwtHeader,
|
|
1905
|
+
payloadSchema: zClientAttestationJwtPayload
|
|
1889
1906
|
});
|
|
1890
1907
|
const expiresAt = options.expiresAt ?? addSecondsToDate2(options.issuedAt ?? /* @__PURE__ */ new Date(), 1 * 60);
|
|
1891
|
-
const payload = parseWithErrorHandling10(
|
|
1908
|
+
const payload = parseWithErrorHandling10(zClientAttestationPopJwtPayload, {
|
|
1892
1909
|
aud: options.authorizationServer,
|
|
1893
1910
|
iss: clientAttestation.payload.sub,
|
|
1894
1911
|
iat: dateToSeconds5(options.issuedAt),
|
|
@@ -1911,7 +1928,7 @@ var Oauth2AuthorizationServer = class {
|
|
|
1911
1928
|
}
|
|
1912
1929
|
createAuthorizationServerMetadata(authorizationServerMetadata) {
|
|
1913
1930
|
return parseWithErrorHandling11(
|
|
1914
|
-
|
|
1931
|
+
zAuthorizationServerMetadata,
|
|
1915
1932
|
authorizationServerMetadata,
|
|
1916
1933
|
"Error validating authorization server metadata"
|
|
1917
1934
|
);
|
|
@@ -2036,9 +2053,8 @@ var Oauth2ResourceServer = class {
|
|
|
2036
2053
|
import { objectToQueryParams as objectToQueryParams5 } from "@openid4vc/utils";
|
|
2037
2054
|
|
|
2038
2055
|
// src/access-token/retrieve-access-token.ts
|
|
2039
|
-
import { ContentType as ContentType4,
|
|
2056
|
+
import { ContentType as ContentType4, createZodFetcher as createZodFetcher4, objectToQueryParams as objectToQueryParams2, parseWithErrorHandling as parseWithErrorHandling12 } from "@openid4vc/utils";
|
|
2040
2057
|
import { InvalidFetchResponseError as InvalidFetchResponseError4 } from "@openid4vc/utils";
|
|
2041
|
-
import * as v17 from "valibot";
|
|
2042
2058
|
async function retrievePreAuthorizedCodeAccessToken(options) {
|
|
2043
2059
|
const request = {
|
|
2044
2060
|
grant_type: preAuthorizedCodeGrantIdentifier,
|
|
@@ -2091,9 +2107,9 @@ async function retrieveRefreshTokenAccessToken(options) {
|
|
|
2091
2107
|
});
|
|
2092
2108
|
}
|
|
2093
2109
|
async function retrieveAccessToken(options) {
|
|
2094
|
-
const
|
|
2110
|
+
const fetchWithZod = createZodFetcher4(options.callbacks.fetch);
|
|
2095
2111
|
const accessTokenRequest = parseWithErrorHandling12(
|
|
2096
|
-
|
|
2112
|
+
zAccessTokenRequest,
|
|
2097
2113
|
options.request,
|
|
2098
2114
|
"Error validating access token request"
|
|
2099
2115
|
);
|
|
@@ -2121,8 +2137,8 @@ async function retrieveAccessToken(options) {
|
|
|
2121
2137
|
...accessTokenRequest,
|
|
2122
2138
|
...clientAttestation?.body
|
|
2123
2139
|
});
|
|
2124
|
-
const { response, result } = await
|
|
2125
|
-
|
|
2140
|
+
const { response, result } = await fetchWithZod(
|
|
2141
|
+
zAccessTokenResponse,
|
|
2126
2142
|
ContentType4.Json,
|
|
2127
2143
|
options.authorizationServerMetadata.token_endpoint,
|
|
2128
2144
|
{
|
|
@@ -2136,14 +2152,13 @@ async function retrieveAccessToken(options) {
|
|
|
2136
2152
|
}
|
|
2137
2153
|
);
|
|
2138
2154
|
if (!response.ok || !result) {
|
|
2139
|
-
const tokenErrorResponse =
|
|
2140
|
-
vAccessTokenErrorResponse,
|
|
2155
|
+
const tokenErrorResponse = zAccessTokenErrorResponse.safeParse(
|
|
2141
2156
|
await response.clone().json().catch(() => null)
|
|
2142
2157
|
);
|
|
2143
2158
|
if (tokenErrorResponse.success) {
|
|
2144
2159
|
throw new Oauth2ClientErrorResponseError(
|
|
2145
2160
|
`Unable to retrieve access token from '${options.authorizationServerMetadata.token_endpoint}'. Received token error response with status ${response.status}`,
|
|
2146
|
-
tokenErrorResponse.
|
|
2161
|
+
tokenErrorResponse.data,
|
|
2147
2162
|
response
|
|
2148
2163
|
);
|
|
2149
2164
|
}
|
|
@@ -2154,7 +2169,7 @@ async function retrieveAccessToken(options) {
|
|
|
2154
2169
|
);
|
|
2155
2170
|
}
|
|
2156
2171
|
if (!result.success) {
|
|
2157
|
-
throw new ValidationError("Error validating access token response", result.
|
|
2172
|
+
throw new ValidationError("Error validating access token response", result.error);
|
|
2158
2173
|
}
|
|
2159
2174
|
const dpopNonce = extractDpopNonceFromHeaders(response.headers) ?? void 0;
|
|
2160
2175
|
return {
|
|
@@ -2162,7 +2177,7 @@ async function retrieveAccessToken(options) {
|
|
|
2162
2177
|
...dpop,
|
|
2163
2178
|
nonce: dpopNonce
|
|
2164
2179
|
} : void 0,
|
|
2165
|
-
accessTokenResponse: result.
|
|
2180
|
+
accessTokenResponse: result.data
|
|
2166
2181
|
};
|
|
2167
2182
|
}
|
|
2168
2183
|
});
|
|
@@ -2172,14 +2187,13 @@ async function retrieveAccessToken(options) {
|
|
|
2172
2187
|
import {
|
|
2173
2188
|
ContentType as ContentType5,
|
|
2174
2189
|
ValidationError as ValidationError3,
|
|
2175
|
-
|
|
2190
|
+
createZodFetcher as createZodFetcher5,
|
|
2176
2191
|
objectToQueryParams as objectToQueryParams3,
|
|
2177
2192
|
parseWithErrorHandling as parseWithErrorHandling13
|
|
2178
2193
|
} from "@openid4vc/utils";
|
|
2179
2194
|
import { InvalidFetchResponseError as InvalidFetchResponseError5 } from "@openid4vc/utils";
|
|
2180
|
-
import * as v18 from "valibot";
|
|
2181
2195
|
async function sendAuthorizationChallengeRequest(options) {
|
|
2182
|
-
const
|
|
2196
|
+
const fetchWithZod = createZodFetcher5(options.callbacks.fetch);
|
|
2183
2197
|
const authorizationServerMetadata = options.authorizationServerMetadata;
|
|
2184
2198
|
const authorizationChallengeEndpoint = authorizationServerMetadata.authorization_challenge_endpoint;
|
|
2185
2199
|
if (!authorizationChallengeEndpoint) {
|
|
@@ -2197,7 +2211,7 @@ async function sendAuthorizationChallengeRequest(options) {
|
|
|
2197
2211
|
clientAttestation: options.clientAttestation,
|
|
2198
2212
|
callbacks: options.callbacks
|
|
2199
2213
|
}) : void 0;
|
|
2200
|
-
const authorizationChallengeRequest = parseWithErrorHandling13(
|
|
2214
|
+
const authorizationChallengeRequest = parseWithErrorHandling13(zAuthorizationChallengeRequest, {
|
|
2201
2215
|
...options.additionalRequestPayload,
|
|
2202
2216
|
auth_session: options.authSession,
|
|
2203
2217
|
client_id: options.clientId,
|
|
@@ -2220,8 +2234,8 @@ async function sendAuthorizationChallengeRequest(options) {
|
|
|
2220
2234
|
callbacks: options.callbacks,
|
|
2221
2235
|
nonce: dpop.nonce
|
|
2222
2236
|
}) : void 0;
|
|
2223
|
-
const { response, result } = await
|
|
2224
|
-
|
|
2237
|
+
const { response, result } = await fetchWithZod(
|
|
2238
|
+
zAuthorizationChallengeResponse,
|
|
2225
2239
|
ContentType5.Json,
|
|
2226
2240
|
authorizationChallengeEndpoint,
|
|
2227
2241
|
{
|
|
@@ -2235,14 +2249,13 @@ async function sendAuthorizationChallengeRequest(options) {
|
|
|
2235
2249
|
}
|
|
2236
2250
|
);
|
|
2237
2251
|
if (!response.ok || !result) {
|
|
2238
|
-
const authorizationChallengeErrorResponse =
|
|
2239
|
-
vAuthorizationChallengeErrorResponse,
|
|
2252
|
+
const authorizationChallengeErrorResponse = zAuthorizationChallengeErrorResponse.safeParse(
|
|
2240
2253
|
await response.clone().json().catch(() => null)
|
|
2241
2254
|
);
|
|
2242
2255
|
if (authorizationChallengeErrorResponse.success) {
|
|
2243
2256
|
throw new Oauth2ClientAuthorizationChallengeError(
|
|
2244
2257
|
`Error requesting authorization code from authorization challenge endpoint '${authorizationServerMetadata.authorization_challenge_endpoint}'. Received response with status ${response.status}`,
|
|
2245
|
-
authorizationChallengeErrorResponse.
|
|
2258
|
+
authorizationChallengeErrorResponse.data,
|
|
2246
2259
|
response
|
|
2247
2260
|
);
|
|
2248
2261
|
}
|
|
@@ -2253,7 +2266,7 @@ async function sendAuthorizationChallengeRequest(options) {
|
|
|
2253
2266
|
);
|
|
2254
2267
|
}
|
|
2255
2268
|
if (!result.success) {
|
|
2256
|
-
throw new ValidationError3("Error validating authorization challenge response", result.
|
|
2269
|
+
throw new ValidationError3("Error validating authorization challenge response", result.error);
|
|
2257
2270
|
}
|
|
2258
2271
|
const dpopNonce = extractDpopNonceFromHeaders(response.headers) ?? void 0;
|
|
2259
2272
|
return {
|
|
@@ -2262,16 +2275,15 @@ async function sendAuthorizationChallengeRequest(options) {
|
|
|
2262
2275
|
...dpop,
|
|
2263
2276
|
nonce: dpopNonce
|
|
2264
2277
|
} : void 0,
|
|
2265
|
-
authorizationChallengeResponse: result.
|
|
2278
|
+
authorizationChallengeResponse: result.data
|
|
2266
2279
|
};
|
|
2267
2280
|
}
|
|
2268
2281
|
});
|
|
2269
2282
|
}
|
|
2270
2283
|
|
|
2271
2284
|
// src/authorization-request/create-authorization-request.ts
|
|
2272
|
-
import { ContentType as ContentType6,
|
|
2285
|
+
import { ContentType as ContentType6, createZodFetcher as createZodFetcher6, objectToQueryParams as objectToQueryParams4 } from "@openid4vc/utils";
|
|
2273
2286
|
import { InvalidFetchResponseError as InvalidFetchResponseError6 } from "@openid4vc/utils";
|
|
2274
|
-
import * as v19 from "valibot";
|
|
2275
2287
|
async function createAuthorizationRequestUrl(options) {
|
|
2276
2288
|
const authorizationServerMetadata = options.authorizationServerMetadata;
|
|
2277
2289
|
const pushedAuthorizationRequestEndpoint = authorizationServerMetadata.pushed_authorization_request_endpoint;
|
|
@@ -2361,14 +2373,14 @@ async function createAuthorizationRequestUrl(options) {
|
|
|
2361
2373
|
};
|
|
2362
2374
|
}
|
|
2363
2375
|
async function pushAuthorizationRequest(options) {
|
|
2364
|
-
const
|
|
2376
|
+
const fetchWithZod = createZodFetcher6(options.fetch);
|
|
2365
2377
|
if (options.authorizationRequest.request_uri) {
|
|
2366
2378
|
throw new Oauth2Error(
|
|
2367
2379
|
`Authorization request contains 'request_uri' parameter. This is not allowed for pushed authorization reuqests.`
|
|
2368
2380
|
);
|
|
2369
2381
|
}
|
|
2370
|
-
const { response, result } = await
|
|
2371
|
-
|
|
2382
|
+
const { response, result } = await fetchWithZod(
|
|
2383
|
+
zPushedAuthorizationResponse,
|
|
2372
2384
|
ContentType6.Json,
|
|
2373
2385
|
options.pushedAuthorizationRequestEndpoint,
|
|
2374
2386
|
{
|
|
@@ -2381,14 +2393,13 @@ async function pushAuthorizationRequest(options) {
|
|
|
2381
2393
|
}
|
|
2382
2394
|
);
|
|
2383
2395
|
if (!response.ok || !result) {
|
|
2384
|
-
const parErrorResponse =
|
|
2385
|
-
vOauth2ErrorResponse,
|
|
2396
|
+
const parErrorResponse = zOauth2ErrorResponse.safeParse(
|
|
2386
2397
|
await response.clone().json().catch(() => null)
|
|
2387
2398
|
);
|
|
2388
2399
|
if (parErrorResponse.success) {
|
|
2389
2400
|
throw new Oauth2ClientErrorResponseError(
|
|
2390
2401
|
`Unable to push authorization request to '${options.pushedAuthorizationRequestEndpoint}'. Received response with status ${response.status}`,
|
|
2391
|
-
parErrorResponse.
|
|
2402
|
+
parErrorResponse.data,
|
|
2392
2403
|
response
|
|
2393
2404
|
);
|
|
2394
2405
|
}
|
|
@@ -2399,12 +2410,12 @@ async function pushAuthorizationRequest(options) {
|
|
|
2399
2410
|
);
|
|
2400
2411
|
}
|
|
2401
2412
|
if (!result.success) {
|
|
2402
|
-
throw new ValidationError("Error validating pushed authorization response", result.
|
|
2413
|
+
throw new ValidationError("Error validating pushed authorization response", result.error);
|
|
2403
2414
|
}
|
|
2404
2415
|
const dpopNonce = extractDpopNonceFromHeaders(response.headers);
|
|
2405
2416
|
return {
|
|
2406
2417
|
dpopNonce,
|
|
2407
|
-
pushedAuthorizationResponse: result.
|
|
2418
|
+
pushedAuthorizationResponse: result.data
|
|
2408
2419
|
};
|
|
2409
2420
|
}
|
|
2410
2421
|
|
|
@@ -2626,16 +2637,16 @@ export {
|
|
|
2626
2637
|
refreshTokenGrantIdentifier,
|
|
2627
2638
|
resourceRequest,
|
|
2628
2639
|
setGlobalConfig,
|
|
2629
|
-
vAuthorizationCodeGrantIdentifier,
|
|
2630
|
-
vAuthorizationServerMetadata,
|
|
2631
|
-
vCompactJwt,
|
|
2632
|
-
vJwk,
|
|
2633
|
-
vJwtHeader,
|
|
2634
|
-
vJwtPayload,
|
|
2635
|
-
vOauth2ErrorResponse,
|
|
2636
|
-
vPreAuthorizedCodeGrantIdentifier,
|
|
2637
|
-
vRefreshTokenGrantIdentifier,
|
|
2638
2640
|
verifyJwt,
|
|
2639
|
-
verifyResourceRequest
|
|
2641
|
+
verifyResourceRequest,
|
|
2642
|
+
zAuthorizationCodeGrantIdentifier,
|
|
2643
|
+
zAuthorizationServerMetadata,
|
|
2644
|
+
zCompactJwt,
|
|
2645
|
+
zJwk,
|
|
2646
|
+
zJwtHeader,
|
|
2647
|
+
zJwtPayload,
|
|
2648
|
+
zOauth2ErrorResponse,
|
|
2649
|
+
zPreAuthorizedCodeGrantIdentifier,
|
|
2650
|
+
zRefreshTokenGrantIdentifier
|
|
2640
2651
|
};
|
|
2641
2652
|
//# sourceMappingURL=index.mjs.map
|