@openid4vc/oauth2 0.4.6-alpha-20260201172333 → 0.5.0-alpha-20260202155954

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.mjs CHANGED
@@ -1009,6 +1009,7 @@ let Oauth2ErrorCodes = /* @__PURE__ */ function(Oauth2ErrorCodes$1) {
1009
1009
  Oauth2ErrorCodes$1["InvalidTransactionId"] = "invalid_transaction_id";
1010
1010
  Oauth2ErrorCodes$1["UnsupportedCredentialType"] = "unsupported_credential_type";
1011
1011
  Oauth2ErrorCodes$1["UnsupportedCredentialFormat"] = "unsupported_credential_format";
1012
+ Oauth2ErrorCodes$1["MissingInteractionType"] = "missing_interaction_type";
1012
1013
  Oauth2ErrorCodes$1["InvalidRequestUri"] = "invalid_request_uri";
1013
1014
  Oauth2ErrorCodes$1["InvalidRequestObject"] = "invalid_request_object";
1014
1015
  Oauth2ErrorCodes$1["RequestNotSupported"] = "request_not_supported";
@@ -1038,149 +1039,6 @@ var Oauth2ServerErrorResponseError = class extends Oauth2Error {
1038
1039
  }
1039
1040
  };
1040
1041
 
1041
- //#endregion
1042
- //#region src/common/jwt/z-jwe.ts
1043
- 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" });
1044
-
1045
- //#endregion
1046
- //#region src/jar/z-jar-authorization-request.ts
1047
- const zJarAuthorizationRequest = z.object({
1048
- request: z.optional(z.string()),
1049
- request_uri: z.optional(zHttpsUrl),
1050
- client_id: z.optional(z.string())
1051
- }).loose();
1052
- function validateJarRequestParams(options) {
1053
- const { jarRequestParams } = options;
1054
- if (jarRequestParams.request && jarRequestParams.request_uri) throw new Oauth2ServerErrorResponseError({
1055
- error: Oauth2ErrorCodes.InvalidRequestObject,
1056
- error_description: "request and request_uri cannot both be present in a JAR request"
1057
- });
1058
- if (!jarRequestParams.request && !jarRequestParams.request_uri) throw new Oauth2ServerErrorResponseError({
1059
- error: Oauth2ErrorCodes.InvalidRequestObject,
1060
- error_description: "request or request_uri must be present"
1061
- });
1062
- return jarRequestParams;
1063
- }
1064
- function isJarAuthorizationRequest(request) {
1065
- return "request" in request || "request_uri" in request;
1066
- }
1067
-
1068
- //#endregion
1069
- //#region src/jar/z-jar-request-object.ts
1070
- const zJarRequestObjectPayload = z.object({
1071
- ...zJwtPayload.shape,
1072
- client_id: z.string()
1073
- }).loose();
1074
- const zSignedAuthorizationRequestJwtHeaderTyp = z.literal("oauth-authz-req+jwt");
1075
- const signedAuthorizationRequestJwtHeaderTyp = zSignedAuthorizationRequestJwtHeaderTyp.value;
1076
- const zJwtAuthorizationRequestJwtHeaderTyp = z.literal("jwt");
1077
- const jwtAuthorizationRequestJwtHeaderTyp = zJwtAuthorizationRequestJwtHeaderTyp.value;
1078
-
1079
- //#endregion
1080
- //#region src/jar/handle-jar-request/verify-jar-request.ts
1081
- /**
1082
- * Parse a JAR (JWT Secured Authorization Request) request by validating and optionally fetch from uri.
1083
- *
1084
- * @param options - The input parameters
1085
- * @param options.jarRequestParams - The JAR authorization request parameters
1086
- * @param options.callbacks - Context containing the relevant Jose crypto operations
1087
- * @returns An object containing the transmission method ('value' or 'reference') and the JWT request object.
1088
- */
1089
- async function parseJarRequest(options) {
1090
- const { callbacks } = options;
1091
- const jarRequestParams = {
1092
- ...validateJarRequestParams(options),
1093
- ...options.jarRequestParams
1094
- };
1095
- return {
1096
- sendBy: jarRequestParams.request ? "value" : "reference",
1097
- authorizationRequestJwt: jarRequestParams.request ?? await fetchJarRequestObject({
1098
- requestUri: jarRequestParams.request_uri,
1099
- fetch: callbacks.fetch
1100
- })
1101
- };
1102
- }
1103
- /**
1104
- * Verifies a JAR (JWT Secured Authorization Request) request by validating and verifying signatures.
1105
- *
1106
- * @param options - The input parameters
1107
- * @param options.jarRequestParams - The JAR authorization request parameters
1108
- * @param options.callbacks - Context containing the relevant Jose crypto operations
1109
- * @returns The verified authorization request parameters and metadata
1110
- */
1111
- async function verifyJarRequest(options) {
1112
- const { jarRequestParams, authorizationRequestJwt, callbacks, jwtSigner } = options;
1113
- if (zCompactJwe.safeParse(authorizationRequestJwt).success) throw new Oauth2ServerErrorResponseError({
1114
- error: Oauth2ErrorCodes.InvalidRequestObject,
1115
- error_description: "Encrypted JWE request objects are not supported."
1116
- });
1117
- if (!zCompactJwt.safeParse(authorizationRequestJwt).success) throw new Oauth2ServerErrorResponseError({
1118
- error: Oauth2ErrorCodes.InvalidRequestObject,
1119
- error_description: "JAR request object is not a valid JWT."
1120
- });
1121
- const { authorizationRequestPayload, signer, jwt } = await verifyJarRequestObject({
1122
- authorizationRequestJwt,
1123
- callbacks,
1124
- jwtSigner
1125
- });
1126
- if (!authorizationRequestPayload.client_id) throw new Oauth2ServerErrorResponseError({
1127
- error: Oauth2ErrorCodes.InvalidRequestObject,
1128
- error_description: "Jar Request Object is missing the required \"client_id\" field."
1129
- });
1130
- if (jarRequestParams.client_id !== authorizationRequestPayload.client_id) throw new Oauth2ServerErrorResponseError({
1131
- error: Oauth2ErrorCodes.InvalidRequest,
1132
- error_description: "client_id does not match the request object client_id."
1133
- });
1134
- return {
1135
- jwt,
1136
- authorizationRequestPayload,
1137
- signer
1138
- };
1139
- }
1140
- async function fetchJarRequestObject(options) {
1141
- const { requestUri, fetch } = options;
1142
- const response = await createFetcher(fetch)(requestUri, {
1143
- method: "get",
1144
- headers: {
1145
- Accept: `${ContentType.OAuthAuthorizationRequestJwt}, ${ContentType.Jwt};q=0.9, text/plain`,
1146
- "Content-Type": ContentType.XWwwFormUrlencoded
1147
- }
1148
- }).catch(() => {
1149
- throw new Oauth2ServerErrorResponseError({
1150
- error_description: `Fetching request_object from request_uri '${requestUri}' failed`,
1151
- error: Oauth2ErrorCodes.InvalidRequestUri
1152
- });
1153
- });
1154
- if (!response.ok) throw new Oauth2ServerErrorResponseError({
1155
- error_description: `Fetching request_object from request_uri '${requestUri}' failed with status code '${response.status}'.`,
1156
- error: Oauth2ErrorCodes.InvalidRequestUri
1157
- });
1158
- return await response.text();
1159
- }
1160
- async function verifyJarRequestObject(options) {
1161
- const { authorizationRequestJwt, callbacks, jwtSigner } = options;
1162
- const jwt = decodeJwt({
1163
- jwt: authorizationRequestJwt,
1164
- payloadSchema: zJarRequestObjectPayload
1165
- });
1166
- const { signer } = await verifyJwt({
1167
- verifyJwtCallback: callbacks.verifyJwt,
1168
- compact: authorizationRequestJwt,
1169
- header: jwt.header,
1170
- payload: jwt.payload,
1171
- signer: jwtSigner
1172
- });
1173
- if (jwt.header.typ !== signedAuthorizationRequestJwtHeaderTyp && jwt.header.typ !== jwtAuthorizationRequestJwtHeaderTyp) throw new Oauth2ServerErrorResponseError({
1174
- error: Oauth2ErrorCodes.InvalidRequestObject,
1175
- error_description: `Invalid Jar Request Object typ header. Expected "oauth-authz-req+jwt" or "jwt", received "${jwt.header.typ}".`
1176
- });
1177
- return {
1178
- signer,
1179
- jwt,
1180
- authorizationRequestPayload: jwt.payload
1181
- };
1182
- }
1183
-
1184
1042
  //#endregion
1185
1043
  //#region src/client-attestation/z-client-attestation.ts
1186
1044
  const zOauthClientAttestationHeader = z$1.literal("OAuth-Client-Attestation");
@@ -1516,6 +1374,153 @@ function parseAuthorizationRequest(options) {
1516
1374
  };
1517
1375
  }
1518
1376
 
1377
+ //#endregion
1378
+ //#region src/common/jwt/z-jwe.ts
1379
+ 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" });
1380
+
1381
+ //#endregion
1382
+ //#region src/jar/z-jar-authorization-request.ts
1383
+ const zJarAuthorizationRequest = z.object({
1384
+ request: z.optional(z.string()),
1385
+ request_uri: z.optional(zHttpsUrl),
1386
+ client_id: z.optional(z.string())
1387
+ }).loose();
1388
+ function validateJarRequestParams(options) {
1389
+ const { jarRequestParams, allowRequestUri = true } = options;
1390
+ if (jarRequestParams.request && jarRequestParams.request_uri) throw new Oauth2ServerErrorResponseError({
1391
+ error: Oauth2ErrorCodes.InvalidRequestObject,
1392
+ error_description: "request and request_uri cannot both be present in a JAR request"
1393
+ });
1394
+ if (!jarRequestParams.request && !jarRequestParams.request_uri) throw new Oauth2ServerErrorResponseError({
1395
+ error: Oauth2ErrorCodes.InvalidRequestObject,
1396
+ error_description: "request or request_uri must be present"
1397
+ });
1398
+ if (jarRequestParams.request_uri && !allowRequestUri) throw new Oauth2ServerErrorResponseError({
1399
+ error: Oauth2ErrorCodes.InvalidRequestObject,
1400
+ error_description: "request_uri is not allowed"
1401
+ });
1402
+ return jarRequestParams;
1403
+ }
1404
+ function isJarAuthorizationRequest(request) {
1405
+ return "request" in request || "request_uri" in request;
1406
+ }
1407
+
1408
+ //#endregion
1409
+ //#region src/jar/z-jar-request-object.ts
1410
+ const zJarRequestObjectPayload = z.object({
1411
+ ...zJwtPayload.shape,
1412
+ client_id: z.string()
1413
+ }).loose();
1414
+ const zSignedAuthorizationRequestJwtHeaderTyp = z.literal("oauth-authz-req+jwt");
1415
+ const signedAuthorizationRequestJwtHeaderTyp = zSignedAuthorizationRequestJwtHeaderTyp.value;
1416
+ const zJwtAuthorizationRequestJwtHeaderTyp = z.literal("jwt");
1417
+ const jwtAuthorizationRequestJwtHeaderTyp = zJwtAuthorizationRequestJwtHeaderTyp.value;
1418
+
1419
+ //#endregion
1420
+ //#region src/jar/handle-jar-request/verify-jar-request.ts
1421
+ /**
1422
+ * Parse a JAR (JWT Secured Authorization Request) request by validating and optionally fetch from uri.
1423
+ *
1424
+ * @param options - The input parameters
1425
+ * @param options.jarRequestParams - The JAR authorization request parameters
1426
+ * @param options.callbacks - Context containing the relevant Jose crypto operations
1427
+ * @returns An object containing the transmission method ('value' or 'reference') and the JWT request object.
1428
+ */
1429
+ async function parseJarRequest(options) {
1430
+ const { callbacks } = options;
1431
+ const jarRequestParams = {
1432
+ ...validateJarRequestParams(options),
1433
+ ...options.jarRequestParams
1434
+ };
1435
+ return {
1436
+ sendBy: jarRequestParams.request ? "value" : "reference",
1437
+ authorizationRequestJwt: jarRequestParams.request ?? await fetchJarRequestObject({
1438
+ requestUri: jarRequestParams.request_uri,
1439
+ fetch: callbacks.fetch
1440
+ })
1441
+ };
1442
+ }
1443
+ /**
1444
+ * Verifies a JAR (JWT Secured Authorization Request) request by validating and verifying signatures.
1445
+ *
1446
+ * @param options - The input parameters
1447
+ * @param options.jarRequestParams - The JAR authorization request parameters
1448
+ * @param options.callbacks - Context containing the relevant Jose crypto operations
1449
+ * @returns The verified authorization request parameters and metadata
1450
+ */
1451
+ async function verifyJarRequest(options) {
1452
+ const { jarRequestParams, authorizationRequestJwt, callbacks, jwtSigner } = options;
1453
+ if (zCompactJwe.safeParse(authorizationRequestJwt).success) throw new Oauth2ServerErrorResponseError({
1454
+ error: Oauth2ErrorCodes.InvalidRequestObject,
1455
+ error_description: "Encrypted JWE request objects are not supported."
1456
+ });
1457
+ if (!zCompactJwt.safeParse(authorizationRequestJwt).success) throw new Oauth2ServerErrorResponseError({
1458
+ error: Oauth2ErrorCodes.InvalidRequestObject,
1459
+ error_description: "JAR request object is not a valid JWT."
1460
+ });
1461
+ const { authorizationRequestPayload, signer, jwt } = await verifyJarRequestObject({
1462
+ authorizationRequestJwt,
1463
+ callbacks,
1464
+ jwtSigner
1465
+ });
1466
+ if (!authorizationRequestPayload.client_id) throw new Oauth2ServerErrorResponseError({
1467
+ error: Oauth2ErrorCodes.InvalidRequestObject,
1468
+ error_description: "Jar Request Object is missing the required \"client_id\" field."
1469
+ });
1470
+ if (jarRequestParams.client_id !== authorizationRequestPayload.client_id) throw new Oauth2ServerErrorResponseError({
1471
+ error: Oauth2ErrorCodes.InvalidRequest,
1472
+ error_description: "client_id does not match the request object client_id."
1473
+ });
1474
+ return {
1475
+ jwt,
1476
+ authorizationRequestPayload,
1477
+ signer
1478
+ };
1479
+ }
1480
+ async function fetchJarRequestObject(options) {
1481
+ const { requestUri, fetch } = options;
1482
+ const response = await createFetcher(fetch)(requestUri, {
1483
+ method: "get",
1484
+ headers: {
1485
+ Accept: `${ContentType.OAuthAuthorizationRequestJwt}, ${ContentType.Jwt};q=0.9, text/plain`,
1486
+ "Content-Type": ContentType.XWwwFormUrlencoded
1487
+ }
1488
+ }).catch(() => {
1489
+ throw new Oauth2ServerErrorResponseError({
1490
+ error_description: `Fetching request_object from request_uri '${requestUri}' failed`,
1491
+ error: Oauth2ErrorCodes.InvalidRequestUri
1492
+ });
1493
+ });
1494
+ if (!response.ok) throw new Oauth2ServerErrorResponseError({
1495
+ error_description: `Fetching request_object from request_uri '${requestUri}' failed with status code '${response.status}'.`,
1496
+ error: Oauth2ErrorCodes.InvalidRequestUri
1497
+ });
1498
+ return await response.text();
1499
+ }
1500
+ async function verifyJarRequestObject(options) {
1501
+ const { authorizationRequestJwt, callbacks, jwtSigner } = options;
1502
+ const jwt = decodeJwt({
1503
+ jwt: authorizationRequestJwt,
1504
+ payloadSchema: zJarRequestObjectPayload
1505
+ });
1506
+ const { signer } = await verifyJwt({
1507
+ verifyJwtCallback: callbacks.verifyJwt,
1508
+ compact: authorizationRequestJwt,
1509
+ header: jwt.header,
1510
+ payload: jwt.payload,
1511
+ signer: jwtSigner
1512
+ });
1513
+ if (jwt.header.typ !== signedAuthorizationRequestJwtHeaderTyp && jwt.header.typ !== jwtAuthorizationRequestJwtHeaderTyp) throw new Oauth2ServerErrorResponseError({
1514
+ error: Oauth2ErrorCodes.InvalidRequestObject,
1515
+ error_description: `Invalid Jar Request Object typ header. Expected "oauth-authz-req+jwt" or "jwt", received "${jwt.header.typ}".`
1516
+ });
1517
+ return {
1518
+ signer,
1519
+ jwt,
1520
+ authorizationRequestPayload: jwt.payload
1521
+ };
1522
+ }
1523
+
1519
1524
  //#endregion
1520
1525
  //#region src/authorization-request/z-authorization-request.ts
1521
1526
  const zPushedAuthorizationRequestUriPrefix = z$1.literal("urn:ietf:params:oauth:request_uri:");
@@ -1550,7 +1555,7 @@ const zPushedAuthorizationResponse = z$1.object({
1550
1555
  */
1551
1556
  async function parsePushedAuthorizationRequest(options) {
1552
1557
  const parsed = parseWithErrorHandling(z$1.union([zAuthorizationRequest, zJarAuthorizationRequest]), options.authorizationRequest, "Invalid authorization request. Could not parse authorization request or jar.");
1553
- let parsedAuthorizationRequest;
1558
+ let authorizationRequest;
1554
1559
  let authorizationRequestJwt;
1555
1560
  if (isJarAuthorizationRequest(parsed)) {
1556
1561
  const parsedJar = await parseJarRequest({
@@ -1558,20 +1563,14 @@ async function parsePushedAuthorizationRequest(options) {
1558
1563
  callbacks: options.callbacks
1559
1564
  });
1560
1565
  const jwt = decodeJwt({ jwt: parsedJar.authorizationRequestJwt });
1561
- parsedAuthorizationRequest = zAuthorizationRequest.safeParse(jwt.payload);
1566
+ const parsedAuthorizationRequest = zAuthorizationRequest.safeParse(jwt.payload);
1562
1567
  if (!parsedAuthorizationRequest.success) throw new Oauth2ServerErrorResponseError({
1563
1568
  error: Oauth2ErrorCodes.InvalidRequest,
1564
1569
  error_description: `Invalid authorization request. Could not parse jar request payload.\n${formatZodError(parsedAuthorizationRequest.error)}`
1565
1570
  });
1571
+ authorizationRequest = parsedAuthorizationRequest.data;
1566
1572
  authorizationRequestJwt = parsedJar.authorizationRequestJwt;
1567
- } else {
1568
- parsedAuthorizationRequest = zAuthorizationRequest.safeParse(options.authorizationRequest);
1569
- if (!parsedAuthorizationRequest.success) throw new Oauth2ServerErrorResponseError({
1570
- error: Oauth2ErrorCodes.InvalidRequest,
1571
- error_description: `Error occurred during validation of pushed authorization request.\n${formatZodError(parsedAuthorizationRequest.error)}`
1572
- });
1573
- }
1574
- const authorizationRequest = parsedAuthorizationRequest.data;
1573
+ } else authorizationRequest = parsed;
1575
1574
  const { clientAttestation, dpop } = parseAuthorizationRequest({
1576
1575
  authorizationRequest,
1577
1576
  request: options.request
@@ -1597,6 +1596,72 @@ function parsePushedAuthorizationRequestUriReferenceValue(options) {
1597
1596
  return options.uri.substring(pushedAuthorizationRequestUriPrefix.length);
1598
1597
  }
1599
1598
 
1599
+ //#endregion
1600
+ //#region src/authorization-request/verify-authorization-request.ts
1601
+ async function verifyAuthorizationRequest(options) {
1602
+ const dpopResult = options.dpop ? await verifyAuthorizationRequestDpop(options.dpop, options.request, options.callbacks, options.now) : void 0;
1603
+ const clientAttestationResult = options.clientAttestation ? await verifyAuthorizationRequestClientAttestation(options.clientAttestation, options.authorizationServerMetadata, options.callbacks, dpopResult?.jwkThumbprint, options.now, options.authorizationRequest.client_id) : void 0;
1604
+ return {
1605
+ dpop: dpopResult?.jwkThumbprint ? {
1606
+ jwkThumbprint: dpopResult.jwkThumbprint,
1607
+ jwk: dpopResult.jwk
1608
+ } : void 0,
1609
+ clientAttestation: clientAttestationResult
1610
+ };
1611
+ }
1612
+ async function verifyAuthorizationRequestClientAttestation(options, authorizationServerMetadata, callbacks, dpopJwkThumbprint, now, requestClientId) {
1613
+ if (!options.clientAttestationJwt || !options.clientAttestationPopJwt) {
1614
+ if (!options.required && !options.clientAttestationJwt && !options.clientAttestationPopJwt) return;
1615
+ throw new Oauth2ServerErrorResponseError({
1616
+ error: Oauth2ErrorCodes.InvalidClient,
1617
+ error_description: `Missing required client attestation parameters in pushed authorization request. Make sure to provide the '${oauthClientAttestationHeader}' and '${oauthClientAttestationPopHeader}' header values.`
1618
+ });
1619
+ }
1620
+ const verifiedClientAttestation = await verifyClientAttestation({
1621
+ authorizationServer: authorizationServerMetadata.issuer,
1622
+ callbacks,
1623
+ clientAttestationJwt: options.clientAttestationJwt,
1624
+ clientAttestationPopJwt: options.clientAttestationPopJwt,
1625
+ now
1626
+ });
1627
+ if (requestClientId && requestClientId !== verifiedClientAttestation.clientAttestation.payload.sub) throw new Oauth2ServerErrorResponseError({
1628
+ error: Oauth2ErrorCodes.InvalidClient,
1629
+ error_description: `The client_id '${requestClientId}' in the request does not match the client id '${verifiedClientAttestation.clientAttestation.payload.sub}' in the client attestation`
1630
+ }, { status: 401 });
1631
+ if (options.ensureConfirmationKeyMatchesDpopKey && dpopJwkThumbprint) {
1632
+ if (await calculateJwkThumbprint({
1633
+ hashAlgorithm: HashAlgorithm.Sha256,
1634
+ hashCallback: callbacks.hash,
1635
+ jwk: verifiedClientAttestation.clientAttestation.payload.cnf.jwk
1636
+ }) !== dpopJwkThumbprint) throw new Oauth2ServerErrorResponseError({
1637
+ error: Oauth2ErrorCodes.InvalidRequest,
1638
+ error_description: "Expected the DPoP JWK thumbprint value to match the JWK thumbprint of the client attestation confirmation JWK. Ensure both DPoP and client attestation use the same key."
1639
+ }, { status: 401 });
1640
+ }
1641
+ return verifiedClientAttestation;
1642
+ }
1643
+ async function verifyAuthorizationRequestDpop(options, request, callbacks, now) {
1644
+ if (options.required && !options.jwt && !options.jwkThumbprint) throw new Oauth2ServerErrorResponseError({
1645
+ error: Oauth2ErrorCodes.InvalidDpopProof,
1646
+ error_description: `Missing required DPoP parameters in authorization request. Either DPoP header or 'dpop_jkt' is required.`
1647
+ });
1648
+ const verifyDpopResult = options.jwt ? await verifyDpopJwt({
1649
+ callbacks,
1650
+ dpopJwt: options.jwt,
1651
+ request,
1652
+ allowedSigningAlgs: options.allowedSigningAlgs,
1653
+ now
1654
+ }) : void 0;
1655
+ if (options.jwkThumbprint && verifyDpopResult && options.jwkThumbprint !== verifyDpopResult.jwkThumbprint) throw new Oauth2ServerErrorResponseError({
1656
+ error: Oauth2ErrorCodes.InvalidDpopProof,
1657
+ error_description: `DPoP jwk thumbprint does not match with 'dpop_jkt' provided in authorization request`
1658
+ });
1659
+ return {
1660
+ jwk: verifyDpopResult?.header.jwk,
1661
+ jwkThumbprint: verifyDpopResult?.jwkThumbprint ?? options.jwkThumbprint
1662
+ };
1663
+ }
1664
+
1600
1665
  //#endregion
1601
1666
  //#region src/authorization-response/z-authorization-response.ts
1602
1667
  const zAuthorizationResponse = z$1.object({
@@ -1926,6 +1991,44 @@ var Oauth2ClientErrorResponseError = class extends Oauth2Error {
1926
1991
  }
1927
1992
  };
1928
1993
 
1994
+ //#endregion
1995
+ //#region src/dpop/dpop-retry.ts
1996
+ async function authorizationServerRequestWithDpopRetry(options) {
1997
+ try {
1998
+ return await options.request(options.dpop);
1999
+ } catch (error) {
2000
+ if (options.dpop && error instanceof Oauth2ClientErrorResponseError) {
2001
+ const dpopRetry = shouldRetryAuthorizationServerRequestWithDPoPNonce({
2002
+ responseHeaders: error.response.headers,
2003
+ errorResponse: error.errorResponse
2004
+ });
2005
+ if (dpopRetry.retry) return options.request({
2006
+ ...options.dpop,
2007
+ nonce: dpopRetry.dpopNonce
2008
+ });
2009
+ }
2010
+ throw error;
2011
+ }
2012
+ }
2013
+ function shouldRetryAuthorizationServerRequestWithDPoPNonce(options) {
2014
+ if (options.errorResponse.error !== "use_dpop_nonce") return { retry: false };
2015
+ const dpopNonce = extractDpopNonceFromHeaders(options.responseHeaders);
2016
+ if (!dpopNonce) throw new Oauth2Error(`Error response error contains error 'use_dpop_nonce' but the response headers do not include a valid 'DPoP-Nonce' header value.`);
2017
+ return {
2018
+ retry: true,
2019
+ dpopNonce
2020
+ };
2021
+ }
2022
+ function shouldRetryResourceRequestWithDPoPNonce(options) {
2023
+ if (!options.resourceUnauthorizedError.wwwAuthenticateHeaders.find((challenge) => challenge.scheme === SupportedAuthenticationScheme.DPoP && challenge.error === Oauth2ErrorCodes.UseDpopNonce)) return { retry: false };
2024
+ const dpopNonce = extractDpopNonceFromHeaders(options.responseHeaders);
2025
+ if (!dpopNonce || typeof dpopNonce !== "string") throw new Oauth2Error(`Resource request error in 'WWW-Authenticate' response header contains error 'use_dpop_nonce' but the response headers do not include a valid 'DPoP-Nonce' value.`);
2026
+ return {
2027
+ retry: true,
2028
+ dpopNonce
2029
+ };
2030
+ }
2031
+
1929
2032
  //#endregion
1930
2033
  //#region src/error/Oauth2ClientAuthorizationChallengeError.ts
1931
2034
  var Oauth2ClientAuthorizationChallengeError = class extends Oauth2ClientErrorResponseError {
@@ -2145,6 +2248,8 @@ const zAuthorizationServerMetadata = z$1.object({
2145
2248
  introspection_endpoint_auth_methods_supported: z$1.optional(z$1.array(z$1.union([knownClientAuthenticationMethod, z$1.string()]))),
2146
2249
  introspection_endpoint_auth_signing_alg_values_supported: z$1.optional(z$1.array(zAlgValueNotNone)),
2147
2250
  authorization_challenge_endpoint: z$1.optional(zHttpsUrl),
2251
+ interactive_authorization_endpoint: z$1.optional(zHttpsUrl),
2252
+ require_interactive_authorization_request: z$1.optional(z$1.boolean()),
2148
2253
  "pre-authorized_grant_anonymous_access_supported": z$1.optional(z$1.boolean()),
2149
2254
  client_attestation_pop_nonce_required: z$1.boolean().optional(),
2150
2255
  authorization_response_iss_parameter_supported: z$1.boolean().optional()
@@ -2152,7 +2257,7 @@ const zAuthorizationServerMetadata = z$1.object({
2152
2257
  if (!methodsSupported) return true;
2153
2258
  if (!methodsSupported.includes("private_key_jwt") && !methodsSupported.includes("client_secret_jwt")) return true;
2154
2259
  return algValuesSupported !== void 0 && algValuesSupported.length > 0;
2155
- }, `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'`);
2260
+ }, `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'`).refine(({ require_interactive_authorization_request, interactive_authorization_endpoint }) => !require_interactive_authorization_request || interactive_authorization_endpoint !== void 0, `Metadata value 'require_interactive_authorization_request' MUST NOT be present if 'interactive_authorization_endpoint' is omitted`);
2156
2261
 
2157
2262
  //#endregion
2158
2263
  //#region src/metadata/authorization-server/authorization-server-metadata.ts
@@ -2605,72 +2710,6 @@ function parseAuthorizationChallengeRequest(options) {
2605
2710
  };
2606
2711
  }
2607
2712
 
2608
- //#endregion
2609
- //#region src/authorization-request/verify-authorization-request.ts
2610
- async function verifyAuthorizationRequest(options) {
2611
- const dpopResult = options.dpop ? await verifyAuthorizationRequestDpop(options.dpop, options.request, options.callbacks, options.now) : void 0;
2612
- const clientAttestationResult = options.clientAttestation ? await verifyAuthorizationRequestClientAttestation(options.clientAttestation, options.authorizationServerMetadata, options.callbacks, dpopResult?.jwkThumbprint, options.now, options.authorizationRequest.client_id) : void 0;
2613
- return {
2614
- dpop: dpopResult?.jwkThumbprint ? {
2615
- jwkThumbprint: dpopResult.jwkThumbprint,
2616
- jwk: dpopResult.jwk
2617
- } : void 0,
2618
- clientAttestation: clientAttestationResult
2619
- };
2620
- }
2621
- async function verifyAuthorizationRequestClientAttestation(options, authorizationServerMetadata, callbacks, dpopJwkThumbprint, now, requestClientId) {
2622
- if (!options.clientAttestationJwt || !options.clientAttestationPopJwt) {
2623
- if (!options.required && !options.clientAttestationJwt && !options.clientAttestationPopJwt) return;
2624
- throw new Oauth2ServerErrorResponseError({
2625
- error: Oauth2ErrorCodes.InvalidClient,
2626
- error_description: `Missing required client attestation parameters in pushed authorization request. Make sure to provide the '${oauthClientAttestationHeader}' and '${oauthClientAttestationPopHeader}' header values.`
2627
- });
2628
- }
2629
- const verifiedClientAttestation = await verifyClientAttestation({
2630
- authorizationServer: authorizationServerMetadata.issuer,
2631
- callbacks,
2632
- clientAttestationJwt: options.clientAttestationJwt,
2633
- clientAttestationPopJwt: options.clientAttestationPopJwt,
2634
- now
2635
- });
2636
- if (requestClientId && requestClientId !== verifiedClientAttestation.clientAttestation.payload.sub) throw new Oauth2ServerErrorResponseError({
2637
- error: Oauth2ErrorCodes.InvalidClient,
2638
- error_description: `The client_id '${requestClientId}' in the request does not match the client id '${verifiedClientAttestation.clientAttestation.payload.sub}' in the client attestation`
2639
- }, { status: 401 });
2640
- if (options.ensureConfirmationKeyMatchesDpopKey && dpopJwkThumbprint) {
2641
- if (await calculateJwkThumbprint({
2642
- hashAlgorithm: HashAlgorithm.Sha256,
2643
- hashCallback: callbacks.hash,
2644
- jwk: verifiedClientAttestation.clientAttestation.payload.cnf.jwk
2645
- }) !== dpopJwkThumbprint) throw new Oauth2ServerErrorResponseError({
2646
- error: Oauth2ErrorCodes.InvalidRequest,
2647
- error_description: "Expected the DPoP JWK thumbprint value to match the JWK thumbprint of the client attestation confirmation JWK. Ensure both DPoP and client attestation use the same key."
2648
- }, { status: 401 });
2649
- }
2650
- return verifiedClientAttestation;
2651
- }
2652
- async function verifyAuthorizationRequestDpop(options, request, callbacks, now) {
2653
- if (options.required && !options.jwt && !options.jwkThumbprint) throw new Oauth2ServerErrorResponseError({
2654
- error: Oauth2ErrorCodes.InvalidDpopProof,
2655
- error_description: `Missing required DPoP parameters in authorization request. Either DPoP header or 'dpop_jkt' is required.`
2656
- });
2657
- const verifyDpopResult = options.jwt ? await verifyDpopJwt({
2658
- callbacks,
2659
- dpopJwt: options.jwt,
2660
- request,
2661
- allowedSigningAlgs: options.allowedSigningAlgs,
2662
- now
2663
- }) : void 0;
2664
- if (options.jwkThumbprint && verifyDpopResult && options.jwkThumbprint !== verifyDpopResult.jwkThumbprint) throw new Oauth2ServerErrorResponseError({
2665
- error: Oauth2ErrorCodes.InvalidDpopProof,
2666
- error_description: `DPoP jwk thumbprint does not match with 'dpop_jkt' provided in authorization request`
2667
- });
2668
- return {
2669
- jwk: verifyDpopResult?.header.jwk,
2670
- jwkThumbprint: verifyDpopResult?.jwkThumbprint ?? options.jwkThumbprint
2671
- };
2672
- }
2673
-
2674
2713
  //#endregion
2675
2714
  //#region src/authorization-challenge/verify-authorization-challenge-request.ts
2676
2715
  async function verifyAuthorizationChallengeRequest(options) {
@@ -2875,44 +2914,6 @@ var Oauth2AuthorizationServer = class {
2875
2914
  }
2876
2915
  };
2877
2916
 
2878
- //#endregion
2879
- //#region src/dpop/dpop-retry.ts
2880
- async function authorizationServerRequestWithDpopRetry(options) {
2881
- try {
2882
- return await options.request(options.dpop);
2883
- } catch (error) {
2884
- if (options.dpop && error instanceof Oauth2ClientErrorResponseError) {
2885
- const dpopRetry = shouldRetryAuthorizationServerRequestWithDPoPNonce({
2886
- responseHeaders: error.response.headers,
2887
- errorResponse: error.errorResponse
2888
- });
2889
- if (dpopRetry.retry) return options.request({
2890
- ...options.dpop,
2891
- nonce: dpopRetry.dpopNonce
2892
- });
2893
- }
2894
- throw error;
2895
- }
2896
- }
2897
- function shouldRetryAuthorizationServerRequestWithDPoPNonce(options) {
2898
- if (options.errorResponse.error !== "use_dpop_nonce") return { retry: false };
2899
- const dpopNonce = extractDpopNonceFromHeaders(options.responseHeaders);
2900
- if (!dpopNonce) throw new Oauth2Error(`Error response error contains error 'use_dpop_nonce' but the response headers do not include a valid 'DPoP-Nonce' header value.`);
2901
- return {
2902
- retry: true,
2903
- dpopNonce
2904
- };
2905
- }
2906
- function shouldRetryResourceRequestWithDPoPNonce(options) {
2907
- if (!options.resourceUnauthorizedError.wwwAuthenticateHeaders.find((challenge) => challenge.scheme === SupportedAuthenticationScheme.DPoP && challenge.error === Oauth2ErrorCodes.UseDpopNonce)) return { retry: false };
2908
- const dpopNonce = extractDpopNonceFromHeaders(options.responseHeaders);
2909
- if (!dpopNonce || typeof dpopNonce !== "string") throw new Oauth2Error(`Resource request error in 'WWW-Authenticate' response header contains error 'use_dpop_nonce' but the response headers do not include a valid 'DPoP-Nonce' value.`);
2910
- return {
2911
- retry: true,
2912
- dpopNonce
2913
- };
2914
- }
2915
-
2916
2917
  //#endregion
2917
2918
  //#region src/access-token/retrieve-access-token.ts
2918
2919
  async function retrievePreAuthorizedCodeAccessToken(options) {
@@ -3325,7 +3326,7 @@ var Oauth2Client = class {
3325
3326
  return {
3326
3327
  dpop: options.dpop ? {
3327
3328
  ...options.dpop,
3328
- nonce: dpopNonce
3329
+ nonce: dpopNonce ?? void 0
3329
3330
  } : void 0,
3330
3331
  authorizationRequestUrl,
3331
3332
  pkce
@@ -3581,5 +3582,5 @@ async function verifyResourceRequest(options) {
3581
3582
  }
3582
3583
 
3583
3584
  //#endregion
3584
- export { HashAlgorithm, InvalidFetchResponseError, Oauth2AuthorizationServer, Oauth2Client, Oauth2ClientAuthorizationChallengeError, Oauth2ClientErrorResponseError, Oauth2Error, Oauth2ErrorCodes, Oauth2JwtParseError, Oauth2JwtVerificationError, Oauth2ResourceServer, Oauth2ResourceUnauthorizedError, Oauth2ServerErrorResponseError, PkceCodeChallengeMethod, SupportedAuthenticationScheme, SupportedClientAuthenticationMethod, authorizationCodeGrantIdentifier, calculateJwkThumbprint, clientAuthenticationAnonymous, clientAuthenticationClientAttestationJwt, clientAuthenticationClientSecretBasic, clientAuthenticationClientSecretPost, clientAuthenticationDynamic, clientAuthenticationNone, clientCredentialsGrantIdentifier, createClientAttestationJwt, createJarAuthorizationRequest, decodeJwt, decodeJwtHeader, fetchAuthorizationServerMetadata, fetchJwks, fetchWellKnownMetadata, fullySpecifiedCoseAlgorithmArrayToJwaSignatureAlgorithmArray, fullySpecifiedCoseAlgorithmToJwaSignatureAlgorithm, getAuthorizationServerMetadataFromList, getGlobalConfig, isJwkInSet, jwaSignatureAlgorithmArrayToFullySpecifiedCoseAlgorithmArray, jwaSignatureAlgorithmToFullySpecifiedCoseAlgorithm, jwtAuthorizationRequestJwtHeaderTyp, jwtHeaderFromJwtSigner, jwtSignerFromJwt, parseAuthorizationResponseRedirectUrl, parsePushedAuthorizationRequestUriReferenceValue, preAuthorizedCodeGrantIdentifier, pushedAuthorizationRequestUriPrefix, refreshTokenGrantIdentifier, resourceRequest, setGlobalConfig, signedAuthorizationRequestJwtHeaderTyp, validateJarRequestParams, verifyAuthorizationResponse, verifyClientAttestationJwt, verifyIdTokenJwt, verifyJwt, verifyResourceRequest, zAlgValueNotNone, zAuthorizationCodeGrantIdentifier, zAuthorizationErrorResponse, zAuthorizationResponse, zAuthorizationResponseFromUriParams, zAuthorizationServerMetadata, zClientCredentialsGrantIdentifier, zCompactJwe, zCompactJwt, zIdTokenJwtHeader, zIdTokenJwtPayload, zJarAuthorizationRequest, zJarRequestObjectPayload, zJwk, zJwkSet, zJwtHeader, zJwtPayload, zOauth2ErrorResponse, zPreAuthorizedCodeGrantIdentifier, zPushedAuthorizationRequestUriPrefix, zRefreshTokenGrantIdentifier };
3585
+ export { HashAlgorithm, InvalidFetchResponseError, Oauth2AuthorizationServer, Oauth2Client, Oauth2ClientAuthorizationChallengeError, Oauth2ClientErrorResponseError, Oauth2Error, Oauth2ErrorCodes, Oauth2JwtParseError, Oauth2JwtVerificationError, Oauth2ResourceServer, Oauth2ResourceUnauthorizedError, Oauth2ServerErrorResponseError, PkceCodeChallengeMethod, SupportedAuthenticationScheme, SupportedClientAuthenticationMethod, authorizationCodeGrantIdentifier, authorizationServerRequestWithDpopRetry, calculateJwkThumbprint, clientAuthenticationAnonymous, clientAuthenticationClientAttestationJwt, clientAuthenticationClientSecretBasic, clientAuthenticationClientSecretPost, clientAuthenticationDynamic, clientAuthenticationNone, clientCredentialsGrantIdentifier, createClientAttestationJwt, createDpopHeadersForRequest, createJarAuthorizationRequest, createPkce, decodeJwt, decodeJwtHeader, extractDpopNonceFromHeaders, fetchAuthorizationServerMetadata, fetchJwks, fetchWellKnownMetadata, fullySpecifiedCoseAlgorithmArrayToJwaSignatureAlgorithmArray, fullySpecifiedCoseAlgorithmToJwaSignatureAlgorithm, getAuthorizationServerMetadataFromList, getGlobalConfig, isJarAuthorizationRequest, isJwkInSet, jwaSignatureAlgorithmArrayToFullySpecifiedCoseAlgorithmArray, jwaSignatureAlgorithmToFullySpecifiedCoseAlgorithm, jwtAuthorizationRequestJwtHeaderTyp, jwtHeaderFromJwtSigner, jwtSignerFromJwt, parseAuthorizationRequest, parseAuthorizationResponseRedirectUrl, parseJarRequest, parsePushedAuthorizationRequestUriReferenceValue, preAuthorizedCodeGrantIdentifier, pushedAuthorizationRequestUriPrefix, refreshTokenGrantIdentifier, resourceRequest, setGlobalConfig, signedAuthorizationRequestJwtHeaderTyp, validateJarRequestParams, verifyAuthorizationRequest, verifyAuthorizationResponse, verifyClientAttestationJwt, verifyIdTokenJwt, verifyJarRequest, verifyJwt, verifyResourceRequest, zAlgValueNotNone, zAuthorizationCodeGrantIdentifier, zAuthorizationErrorResponse, zAuthorizationRequest, zAuthorizationResponse, zAuthorizationResponseFromUriParams, zAuthorizationServerMetadata, zClientCredentialsGrantIdentifier, zCompactJwe, zCompactJwt, zIdTokenJwtHeader, zIdTokenJwtPayload, zJarAuthorizationRequest, zJarRequestObjectPayload, zJwk, zJwkSet, zJwtHeader, zJwtPayload, zOauth2ErrorResponse, zPreAuthorizedCodeGrantIdentifier, zPushedAuthorizationRequestUriPrefix, zRefreshTokenGrantIdentifier };
3585
3586
  //# sourceMappingURL=index.mjs.map