@pagopa/io-wallet-oauth2 2.0.0-launchpad → 2.0.2-apt

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
@@ -1,17 +1,66 @@
1
1
  // src/access-token/create-token-request.ts
2
- var createTokenRequest = async (options) => ({
3
- ...options.additionalRequestPayload,
4
- code: options.authorizationCode,
5
- code_verifier: options.pkceCodeVerifier,
6
- grant_type: "authorization_code",
7
- redirect_uri: options.redirectUri
2
+ import {
3
+ ItWalletSpecsVersion,
4
+ createVersionDispatcher
5
+ } from "@pagopa/io-wallet-utils";
6
+
7
+ // src/access-token/z-grant-type.ts
8
+ import { z } from "zod";
9
+ var zAuthorizationCodeGrantIdentifier = z.literal("authorization_code");
10
+ var authorizationCodeGrantIdentifier = zAuthorizationCodeGrantIdentifier.value;
11
+ var zPreAuthorizedCodeGrantIdentifier = z.literal(
12
+ "urn:ietf:params:oauth:grant-type:pre-authorized_code"
13
+ );
14
+ var preAuthorizedCodeGrantIdentifier = zPreAuthorizedCodeGrantIdentifier.value;
15
+ var zRefreshTokenGrantIdentifier = z.literal("refresh_token");
16
+ var refreshTokenGrantIdentifier = zRefreshTokenGrantIdentifier.value;
17
+
18
+ // src/access-token/create-token-request.ts
19
+ var createTokenRequestV1_4 = (options) => {
20
+ if (options.grantType === refreshTokenGrantIdentifier) {
21
+ return {
22
+ ...options.additionalRequestPayload,
23
+ grant_type: refreshTokenGrantIdentifier,
24
+ refresh_token: options.refreshToken,
25
+ scope: options.scope
26
+ };
27
+ }
28
+ return {
29
+ ...options.additionalRequestPayload,
30
+ code: options.authorizationCode,
31
+ code_verifier: options.pkceCodeVerifier,
32
+ grant_type: authorizationCodeGrantIdentifier,
33
+ redirect_uri: options.redirectUri
34
+ };
35
+ };
36
+ function createTokenRequestAPTITUDE(options) {
37
+ if (options.grantType === preAuthorizedCodeGrantIdentifier) {
38
+ return {
39
+ ...options.additionalRequestPayload,
40
+ grant_type: preAuthorizedCodeGrantIdentifier,
41
+ "pre-authorized_code": options.preAuthorizedCode,
42
+ tx_code: options.txCode
43
+ };
44
+ }
45
+ return createTokenRequestV1_4(options);
46
+ }
47
+ var dispatchCreateTokenRequest = createVersionDispatcher({
48
+ [ItWalletSpecsVersion.APTITUDE]: (o) => createTokenRequestAPTITUDE(o),
49
+ [ItWalletSpecsVersion.V1_0]: (o) => createTokenRequestV1_4(o),
50
+ [ItWalletSpecsVersion.V1_3]: (o) => createTokenRequestV1_4(o),
51
+ [ItWalletSpecsVersion.V1_4]: (o) => createTokenRequestV1_4(o)
8
52
  });
53
+ function createTokenRequest(options) {
54
+ return dispatchCreateTokenRequest(options);
55
+ }
9
56
 
10
57
  // src/access-token/create-token-response.ts
11
58
  import {
12
59
  HashAlgorithm,
60
+ ItWalletSpecsVersion as ItWalletSpecsVersion2,
13
61
  addSecondsToDate,
14
62
  calculateJwkThumbprint,
63
+ createVersionDispatcher as createVersionDispatcher2,
15
64
  dateToSeconds,
16
65
  jwtHeaderFromJwtSigner,
17
66
  parseWithErrorHandling
@@ -79,70 +128,82 @@ import {
79
128
  zJwtHeader,
80
129
  zJwtPayload
81
130
  } from "@pagopa/io-wallet-utils";
82
- import { z } from "zod";
83
- var zAccessTokenRequest = z.discriminatedUnion("grant_type", [
84
- z.object({
85
- code: z.string().nonempty(),
86
- code_verifier: z.string().nonempty(),
87
- grant_type: z.literal("authorization_code"),
88
- redirect_uri: z.string().nonempty()
89
- }),
90
- z.object({
91
- grant_type: z.literal("refresh_token"),
92
- refresh_token: z.string().nonempty(),
93
- scope: z.string().optional()
94
- })
131
+ import { z as z2 } from "zod";
132
+ var zPreAuthorizedCodeTokenRequest = z2.object({
133
+ grant_type: zPreAuthorizedCodeGrantIdentifier,
134
+ "pre-authorized_code": z2.string().nonempty(),
135
+ tx_code: z2.string().optional()
136
+ });
137
+ var zAuthorizationCodeTokenRequest = z2.object({
138
+ code: z2.string().nonempty(),
139
+ code_verifier: z2.string().nonempty(),
140
+ grant_type: zAuthorizationCodeGrantIdentifier,
141
+ redirect_uri: z2.string().nonempty()
142
+ });
143
+ var zRefreshTokenTokenRequest = z2.object({
144
+ grant_type: zRefreshTokenGrantIdentifier,
145
+ refresh_token: z2.string().nonempty(),
146
+ scope: z2.string().optional()
147
+ });
148
+ var zAccessTokenRequest = z2.discriminatedUnion("grant_type", [
149
+ zAuthorizationCodeTokenRequest,
150
+ zRefreshTokenTokenRequest
151
+ ]);
152
+ var zAccessTokenRequestAPTITUDE = z2.discriminatedUnion("grant_type", [
153
+ zAuthorizationCodeTokenRequest,
154
+ zRefreshTokenTokenRequest,
155
+ zPreAuthorizedCodeTokenRequest
95
156
  ]);
96
- var zAccessTokenResponse = z.looseObject({
97
- access_token: z.string(),
98
- authorization_details: z.array(
99
- z.looseObject({
100
- credential_configuration_id: z.optional(z.string()),
101
- credential_identifiers: z.optional(z.array(z.string())),
102
- type: z.literal("openid_credential")
157
+ var zAccessTokenResponse = z2.looseObject({
158
+ access_token: z2.string(),
159
+ authorization_details: z2.array(
160
+ z2.looseObject({
161
+ credential_configuration_id: z2.optional(z2.string()),
162
+ credential_identifiers: z2.optional(z2.array(z2.string())),
163
+ type: z2.literal("openid_credential")
103
164
  })
104
165
  ).optional(),
105
- expires_in: z.optional(z.number().int()),
106
- refresh_token: z.optional(z.string()),
107
- token_type: z.union([z.literal("Bearer"), z.literal("DPoP")])
166
+ expires_in: z2.optional(z2.number().int()),
167
+ refresh_token: z2.optional(z2.string()),
168
+ token_type: z2.union([z2.literal("Bearer"), z2.literal("DPoP")])
108
169
  });
109
- var zAccessTokenProfileJwtHeader = z.looseObject({
170
+ var zAccessTokenProfileJwtHeader = z2.looseObject({
110
171
  ...zJwtHeader.shape,
111
- typ: z.enum(["application/at+jwt", "at+jwt"])
172
+ typ: z2.enum(["application/at+jwt", "at+jwt"])
112
173
  });
113
- var zAccessTokenProfileJwtPayload = z.looseObject({
174
+ var zAccessTokenProfileJwtPayload = z2.looseObject({
114
175
  ...zJwtPayload.shape,
115
- aud: z.string(),
116
- client_id: z.string(),
117
- cnf: z.object({
118
- jkt: z.string()
176
+ aud: z2.string(),
177
+ client_id: z2.string(),
178
+ cnf: z2.object({
179
+ jkt: z2.string()
119
180
  }).optional(),
120
- exp: z.number(),
121
- iat: z.number(),
122
- iss: z.string(),
123
- jti: z.string().max(MAX_JTI_LENGTH),
124
- nbf: z.number().optional(),
125
- scope: z.string().optional(),
126
- sub: z.string()
181
+ exp: z2.number(),
182
+ iat: z2.number(),
183
+ iss: z2.string(),
184
+ jti: z2.string().max(MAX_JTI_LENGTH),
185
+ nbf: z2.number().optional(),
186
+ scope: z2.string().optional(),
187
+ sub: z2.string()
127
188
  });
128
- var zRefreshTokenProfileJwtHeader = z.looseObject({
189
+ var zRefreshTokenProfileJwtHeader = z2.looseObject({
129
190
  ...zJwtHeader.shape,
130
- kid: z.string(),
131
- typ: z.literal("rt+jwt")
191
+ kid: z2.string(),
192
+ typ: z2.literal("rt+jwt")
132
193
  });
133
- var zRefreshTokenProfileJwtPayload = z.looseObject({
194
+ var zRefreshTokenProfileJwtPayload = z2.looseObject({
134
195
  ...zJwtPayload.shape,
135
- aud: z.string(),
136
- client_id: z.string(),
137
- cnf: z.object({
138
- jkt: z.string()
196
+ aud: z2.string(),
197
+ client_id: z2.string(),
198
+ cnf: z2.object({
199
+ jkt: z2.string()
139
200
  }),
140
- exp: z.number().int(),
141
- iat: z.number().int(),
142
- iss: z.string(),
143
- jti: z.string().max(MAX_JTI_LENGTH),
144
- nbf: z.number().int(),
145
- sub: z.string()
201
+ exp: z2.number().int(),
202
+ iat: z2.number().int(),
203
+ iss: z2.string(),
204
+ jti: z2.string().max(MAX_JTI_LENGTH),
205
+ nbf: z2.number().int(),
206
+ sub: z2.string()
146
207
  });
147
208
 
148
209
  // src/access-token/create-token-response.ts
@@ -171,7 +232,7 @@ function resolveRefreshTokenKid(signer) {
171
232
  }
172
233
  return void 0;
173
234
  }
174
- async function createAccessTokenResponse(options) {
235
+ async function createAccessTokenResponseV1_4(options) {
175
236
  try {
176
237
  const now = options.now ?? /* @__PURE__ */ new Date();
177
238
  if (options.tokenType === "DPoP" && !options.dpop) {
@@ -277,18 +338,29 @@ async function createAccessTokenResponse(options) {
277
338
  );
278
339
  }
279
340
  }
341
+ var dispatchCreateAccessTokenResponse = createVersionDispatcher2({
342
+ [ItWalletSpecsVersion2.APTITUDE]: (o) => createAccessTokenResponseV1_4(o),
343
+ [ItWalletSpecsVersion2.V1_0]: (o) => createAccessTokenResponseV1_4(o),
344
+ [ItWalletSpecsVersion2.V1_3]: (o) => createAccessTokenResponseV1_4(o),
345
+ [ItWalletSpecsVersion2.V1_4]: (o) => createAccessTokenResponseV1_4(o)
346
+ });
347
+ function createAccessTokenResponse(options) {
348
+ return dispatchCreateAccessTokenResponse(options);
349
+ }
280
350
 
281
351
  // src/access-token/fetch-token-response.ts
282
352
  import {
283
353
  CONTENT_TYPES,
284
354
  HEADERS,
355
+ ItWalletSpecsVersion as ItWalletSpecsVersion3,
285
356
  UnexpectedStatusCodeError,
286
357
  ValidationError,
287
358
  createFetcher,
359
+ createVersionDispatcher as createVersionDispatcher3,
288
360
  hasStatusOrThrow,
289
361
  parseWithErrorHandling as parseWithErrorHandling2
290
362
  } from "@pagopa/io-wallet-utils";
291
- async function fetchTokenResponse(options) {
363
+ async function fetchTokenResponseV1_4(options) {
292
364
  try {
293
365
  const fetch = createFetcher(options.callbacks.fetch);
294
366
  const tokenResponse = await fetch(options.accessTokenEndpoint, {
@@ -327,26 +399,43 @@ function toURLSearchParams(data) {
327
399
  });
328
400
  return params;
329
401
  }
402
+ var dispatchFetchTokenResponse = createVersionDispatcher3({
403
+ [ItWalletSpecsVersion3.APTITUDE]: (o) => fetchTokenResponseV1_4(o),
404
+ [ItWalletSpecsVersion3.V1_0]: (o) => fetchTokenResponseV1_4(
405
+ o
406
+ ),
407
+ [ItWalletSpecsVersion3.V1_3]: (o) => fetchTokenResponseV1_4(
408
+ o
409
+ ),
410
+ [ItWalletSpecsVersion3.V1_4]: (o) => fetchTokenResponseV1_4(
411
+ o
412
+ )
413
+ });
414
+ function fetchTokenResponse(options) {
415
+ return dispatchFetchTokenResponse(options);
416
+ }
330
417
 
331
418
  // src/access-token/parse-token-request.ts
332
419
  import {
420
+ ItWalletSpecsVersion as ItWalletSpecsVersion5,
421
+ createVersionDispatcher as createVersionDispatcher5,
333
422
  formatZodError
334
423
  } from "@pagopa/io-wallet-utils";
335
424
 
336
425
  // src/client-attestation/wallet-attestation.ts
337
426
  import {
338
- ItWalletSpecsVersion,
339
- createVersionDispatcher,
427
+ ItWalletSpecsVersion as ItWalletSpecsVersion4,
428
+ createVersionDispatcher as createVersionDispatcher4,
340
429
  zCompactJwt
341
430
  } from "@pagopa/io-wallet-utils";
342
431
 
343
432
  // src/client-attestation/types.ts
344
- import z2 from "zod";
345
- var zOauthClientAttestationHeader = z2.literal(
433
+ import z3 from "zod";
434
+ var zOauthClientAttestationHeader = z3.literal(
346
435
  "OAuth-Client-Attestation"
347
436
  );
348
437
  var oauthClientAttestationHeader = zOauthClientAttestationHeader.value;
349
- var zOauthClientAttestationPopHeader = z2.literal(
438
+ var zOauthClientAttestationPopHeader = z3.literal(
350
439
  "OAuth-Client-Attestation-PoP"
351
440
  );
352
441
  var oauthClientAttestationPopHeader = zOauthClientAttestationPopHeader.value;
@@ -383,27 +472,27 @@ import {
383
472
  zJwtPayload as zJwtPayload2,
384
473
  zTrustChain
385
474
  } from "@pagopa/io-wallet-utils";
386
- import { z as z3 } from "zod";
387
- var zWalletAttestationJwtHeaderV1_0 = z3.looseObject({
475
+ import { z as z4 } from "zod";
476
+ var zWalletAttestationJwtHeaderV1_0 = z4.looseObject({
388
477
  ...zJwtHeader2.shape,
389
478
  trust_chain: zTrustChain,
390
479
  // REQUIRED in v1.0
391
- typ: z3.literal("oauth-client-attestation+jwt")
480
+ typ: z4.literal("oauth-client-attestation+jwt")
392
481
  });
393
- var zWalletAttestationJwtPayloadV1_0 = z3.looseObject({
482
+ var zWalletAttestationJwtPayloadV1_0 = z4.looseObject({
394
483
  ...zJwtPayload2.shape,
395
- aal: z3.string(),
396
- cnf: z3.object({
484
+ aal: z4.string(),
485
+ cnf: z4.object({
397
486
  jwk: zJwk
398
487
  }),
399
- exp: z3.number(),
400
- iat: z3.number(),
401
- iss: z3.string(),
402
- sub: z3.string(),
403
- wallet_link: z3.url().optional(),
404
- wallet_name: z3.string().optional()
488
+ exp: z4.number(),
489
+ iat: z4.number(),
490
+ iss: z4.string(),
491
+ sub: z4.string(),
492
+ wallet_link: z4.url().optional(),
493
+ wallet_name: z4.string().optional()
405
494
  });
406
- var zWalletAttestationJwtV1_0 = z3.string().min(1);
495
+ var zWalletAttestationJwtV1_0 = z4.string().min(1);
407
496
 
408
497
  // src/client-attestation/v1.0/verify-wallet-attestation-jwt.ts
409
498
  async function verifyWalletAttestationJwt(options) {
@@ -422,37 +511,37 @@ import {
422
511
  zJwtPayload as zJwtPayload3,
423
512
  zTrustChain as zTrustChain2
424
513
  } from "@pagopa/io-wallet-utils";
425
- import { z as z4 } from "zod";
426
- var zWalletAttestationJwtHeaderV1_3 = z4.looseObject({
514
+ import { z as z5 } from "zod";
515
+ var zWalletAttestationJwtHeaderV1_3 = z5.looseObject({
427
516
  ...zJwtHeader3.shape,
428
517
  trust_chain: zTrustChain2.optional(),
429
518
  // OPTIONAL in v1.3
430
- typ: z4.literal("oauth-client-attestation+jwt"),
519
+ typ: z5.literal("oauth-client-attestation+jwt"),
431
520
  x5c: zCertificateChain
432
521
  // REQUIRED in v1.3
433
522
  });
434
- var zWalletAttestationJwtPayloadV1_3 = z4.looseObject({
523
+ var zWalletAttestationJwtPayloadV1_3 = z5.looseObject({
435
524
  ...zJwtPayload3.shape,
436
- cnf: z4.object({
525
+ cnf: z5.object({
437
526
  jwk: zJwk2
438
527
  }),
439
- exp: z4.number(),
440
- iat: z4.number(),
441
- iss: z4.string(),
442
- nbf: z4.number().optional(),
528
+ exp: z5.number(),
529
+ iat: z5.number(),
530
+ iss: z5.string(),
531
+ nbf: z5.number().optional(),
443
532
  // NEW in v1.3
444
- status: z4.object({
445
- status_list: z4.object({
446
- idx: z4.number().int(),
447
- uri: z4.string()
533
+ status: z5.object({
534
+ status_list: z5.object({
535
+ idx: z5.number().int(),
536
+ uri: z5.string()
448
537
  })
449
538
  }).optional(),
450
539
  // NEW in v1.3 - status object for revocation
451
- sub: z4.string(),
452
- wallet_link: z4.url().optional(),
453
- wallet_name: z4.string().optional()
540
+ sub: z5.string(),
541
+ wallet_link: z5.url().optional(),
542
+ wallet_name: z5.string().optional()
454
543
  });
455
- var zWalletAttestationJwtV1_3 = z4.string().min(1);
544
+ var zWalletAttestationJwtV1_3 = z5.string().min(1);
456
545
 
457
546
  // src/client-attestation/v1.3/verify-wallet-attestation-jwt.ts
458
547
  async function verifyWalletAttestationJwt2(options) {
@@ -471,28 +560,28 @@ import {
471
560
  zJwtPayload as zJwtPayload4,
472
561
  zTrustChain as zTrustChain3
473
562
  } from "@pagopa/io-wallet-utils";
474
- import { z as z5 } from "zod";
475
- var zWalletAttestationJwtHeaderV1_4 = z5.looseObject({
563
+ import { z as z6 } from "zod";
564
+ var zWalletAttestationJwtHeaderV1_4 = z6.looseObject({
476
565
  ...zJwtHeader4.shape,
477
- kid: z5.string(),
566
+ kid: z6.string(),
478
567
  trust_chain: zTrustChain3.optional(),
479
- typ: z5.literal("oauth-client-attestation+jwt"),
568
+ typ: z6.literal("oauth-client-attestation+jwt"),
480
569
  x5c: zCertificateChain2
481
570
  });
482
- var zWalletAttestationJwtPayloadV1_4 = z5.looseObject({
571
+ var zWalletAttestationJwtPayloadV1_4 = z6.looseObject({
483
572
  ...zJwtPayload4.shape,
484
- cnf: z5.object({
573
+ cnf: z6.object({
485
574
  jwk: zJwk3
486
575
  }),
487
- exp: z5.number().int(),
488
- iat: z5.number().int(),
489
- iss: z5.string(),
490
- nbf: z5.number().optional(),
491
- sub: z5.string(),
492
- wallet_link: z5.url(),
493
- wallet_name: z5.string()
576
+ exp: z6.number().int(),
577
+ iat: z6.number().int(),
578
+ iss: z6.string(),
579
+ nbf: z6.number().optional(),
580
+ sub: z6.string(),
581
+ wallet_link: z6.url(),
582
+ wallet_name: z6.string()
494
583
  });
495
- var zWalletAttestationJwtV1_4 = z5.string().min(1);
584
+ var zWalletAttestationJwtV1_4 = z6.string().min(1);
496
585
 
497
586
  // src/client-attestation/v1.4/verify-wallet-attestation-jwt.ts
498
587
  async function verifyWalletAttestationJwt3(options) {
@@ -504,10 +593,11 @@ async function verifyWalletAttestationJwt3(options) {
504
593
  }
505
594
 
506
595
  // src/client-attestation/wallet-attestation.ts
507
- var dispatchVerifyWalletAttestationJwt = createVersionDispatcher({
508
- [ItWalletSpecsVersion.V1_0]: (o) => verifyWalletAttestationJwt(o),
509
- [ItWalletSpecsVersion.V1_3]: (o) => verifyWalletAttestationJwt2(o),
510
- [ItWalletSpecsVersion.V1_4]: (o) => verifyWalletAttestationJwt3(o)
596
+ var dispatchVerifyWalletAttestationJwt = createVersionDispatcher4({
597
+ [ItWalletSpecsVersion4.APTITUDE]: (o) => verifyWalletAttestationJwt3(o),
598
+ [ItWalletSpecsVersion4.V1_0]: (o) => verifyWalletAttestationJwt(o),
599
+ [ItWalletSpecsVersion4.V1_3]: (o) => verifyWalletAttestationJwt2(o),
600
+ [ItWalletSpecsVersion4.V1_4]: (o) => verifyWalletAttestationJwt3(o)
511
601
  });
512
602
  async function verifyWalletAttestationJwt4(options) {
513
603
  return dispatchVerifyWalletAttestationJwt(options);
@@ -561,19 +651,19 @@ import {
561
651
  zJwtHeader as zJwtHeader5,
562
652
  zJwtPayload as zJwtPayload5
563
653
  } from "@pagopa/io-wallet-utils";
564
- import z6 from "zod";
565
- var zDpopJwtPayload = z6.looseObject({
654
+ import z7 from "zod";
655
+ var zDpopJwtPayload = z7.looseObject({
566
656
  ...zJwtPayload5.shape,
567
- ath: z6.optional(z6.string()),
657
+ ath: z7.optional(z7.string()),
568
658
  htm: zHttpMethod,
569
- htu: z6.url(),
570
- iat: z6.number().int().nonnegative(),
571
- jti: z6.string().max(MAX_JTI_LENGTH2)
659
+ htu: z7.url(),
660
+ iat: z7.number().int().nonnegative(),
661
+ jti: z7.string().max(MAX_JTI_LENGTH2)
572
662
  });
573
- var zDpopJwtHeader = z6.looseObject({
663
+ var zDpopJwtHeader = z7.looseObject({
574
664
  ...zJwtHeader5.shape,
575
665
  jwk: zJwk4,
576
- typ: z6.literal("dpop+jwt")
666
+ typ: z7.literal("dpop+jwt")
577
667
  });
578
668
 
579
669
  // src/token-dpop/create-token-dpop.ts
@@ -630,15 +720,8 @@ function extractDpopJwtFromHeaders(headers) {
630
720
  return { dpopJwt, valid: true };
631
721
  }
632
722
 
633
- // src/access-token/z-grant-type.ts
634
- import { z as z7 } from "zod";
635
- var zAuthorizationCodeGrantIdentifier = z7.literal("authorization_code");
636
- var authorizationCodeGrantIdentifier = zAuthorizationCodeGrantIdentifier.value;
637
- var zRefreshTokenGrantIdentifier = z7.literal("refresh_token");
638
- var refreshTokenGrantIdentifier = zRefreshTokenGrantIdentifier.value;
639
-
640
723
  // src/access-token/parse-token-request.ts
641
- function parseAccessTokenRequest(options) {
724
+ function parseAccessTokenRequestV1_4(options) {
642
725
  const validationResult = zAccessTokenRequest.safeParse(
643
726
  options.accessTokenRequest
644
727
  );
@@ -659,6 +742,25 @@ ${formatZodError(validationResult.error)}`
659
742
  ...securityHeaders
660
743
  };
661
744
  }
745
+ function parseAccessTokenRequestAPTITUDE(options) {
746
+ const validationResult = zAccessTokenRequestAPTITUDE.safeParse(
747
+ options.accessTokenRequest
748
+ );
749
+ if (!validationResult.success) {
750
+ throw new Oauth2Error(
751
+ `Access token request validation failed:
752
+ ${formatZodError(validationResult.error)}`
753
+ );
754
+ }
755
+ const accessTokenRequest = validationResult.data;
756
+ const grant = parseGrantParametersAPTITUDE(accessTokenRequest);
757
+ const securityHeaders = parseSecurityHeaders(options.request.headers);
758
+ return {
759
+ accessTokenRequest,
760
+ grant,
761
+ ...securityHeaders
762
+ };
763
+ }
662
764
  function parseGrantParameters(accessTokenRequest) {
663
765
  if (accessTokenRequest.grant_type === authorizationCodeGrantIdentifier) {
664
766
  return {
@@ -676,6 +778,30 @@ function parseGrantParameters(accessTokenRequest) {
676
778
  `Unsupported grant type. Supported types are: '${authorizationCodeGrantIdentifier}', '${refreshTokenGrantIdentifier}'`
677
779
  );
678
780
  }
781
+ function parseGrantParametersAPTITUDE(accessTokenRequest) {
782
+ if (accessTokenRequest.grant_type === authorizationCodeGrantIdentifier) {
783
+ return {
784
+ code: accessTokenRequest.code,
785
+ grantType: authorizationCodeGrantIdentifier
786
+ };
787
+ }
788
+ if (accessTokenRequest.grant_type === refreshTokenGrantIdentifier) {
789
+ return {
790
+ grantType: refreshTokenGrantIdentifier,
791
+ refreshToken: accessTokenRequest.refresh_token
792
+ };
793
+ }
794
+ if (accessTokenRequest.grant_type === preAuthorizedCodeGrantIdentifier) {
795
+ return {
796
+ grantType: preAuthorizedCodeGrantIdentifier,
797
+ preAuthorizedCode: accessTokenRequest["pre-authorized_code"],
798
+ txCode: accessTokenRequest.tx_code
799
+ };
800
+ }
801
+ throw new Oauth2Error(
802
+ `Unsupported grant type. Supported types are: '${authorizationCodeGrantIdentifier}', '${refreshTokenGrantIdentifier}', '${preAuthorizedCodeGrantIdentifier}'`
803
+ );
804
+ }
679
805
  function parseSecurityHeaders(headers) {
680
806
  const extractedDpopJwt = extractDpopJwtFromHeaders(headers);
681
807
  if (!extractedDpopJwt.valid) {
@@ -710,6 +836,29 @@ function parseSecurityHeaders(headers) {
710
836
  dpop: { jwt: extractedDpopJwt.dpopJwt }
711
837
  };
712
838
  }
839
+ var dispatchParseTokenRequest = createVersionDispatcher5({
840
+ [ItWalletSpecsVersion5.APTITUDE]: (o) => parseAccessTokenRequestAPTITUDE(
841
+ o
842
+ ),
843
+ [ItWalletSpecsVersion5.V1_0]: (o) => parseAccessTokenRequestV1_4(
844
+ o
845
+ ),
846
+ [ItWalletSpecsVersion5.V1_3]: (o) => parseAccessTokenRequestV1_4(
847
+ o
848
+ ),
849
+ [ItWalletSpecsVersion5.V1_4]: (o) => parseAccessTokenRequestV1_4(
850
+ o
851
+ )
852
+ });
853
+ function parseAccessTokenRequest(options) {
854
+ return dispatchParseTokenRequest(options);
855
+ }
856
+
857
+ // src/access-token/verify-access-token-request.ts
858
+ import {
859
+ ItWalletSpecsVersion as ItWalletSpecsVersion7,
860
+ createVersionDispatcher as createVersionDispatcher6
861
+ } from "@pagopa/io-wallet-utils";
713
862
 
714
863
  // src/client-attestation/verify-client-attestation.ts
715
864
  import {
@@ -719,7 +868,7 @@ import {
719
868
 
720
869
  // src/client-attestation/client-attestation-pop.ts
721
870
  import {
722
- ItWalletSpecsVersion as ItWalletSpecsVersion2,
871
+ ItWalletSpecsVersion as ItWalletSpecsVersion6,
723
872
  addSecondsToDate as addSecondsToDate2,
724
873
  dateToSeconds as dateToSeconds3,
725
874
  decodeJwt as decodeJwt2,
@@ -846,7 +995,7 @@ async function createClientAttestationPopJwt(options) {
846
995
  iat: dateToSeconds3(issuedAt),
847
996
  iss: sub,
848
997
  jti,
849
- ...options.config.itWalletSpecsVersion === ItWalletSpecsVersion2.V1_0 ? {
998
+ ...options.config.itWalletSpecsVersion === ItWalletSpecsVersion6.V1_0 ? {
850
999
  exp: dateToSeconds3(
851
1000
  "expiresAt" in options && options.expiresAt ? options.expiresAt : addSecondsToDate2(issuedAt, 1 * 60)
852
1001
  )
@@ -1080,7 +1229,7 @@ async function verifyTokenDPoP(options) {
1080
1229
  }
1081
1230
 
1082
1231
  // src/access-token/verify-access-token-request.ts
1083
- async function verifyAccessTokenRequest(options) {
1232
+ async function verifyAccessTokenRequestV1_4(options) {
1084
1233
  if (options.dpop.expectedNonce === "") {
1085
1234
  throw new Oauth2Error(`Invalid 'dpop.expectedNonce' provided`);
1086
1235
  }
@@ -1109,12 +1258,44 @@ async function verifyAccessTokenRequest(options) {
1109
1258
  if (options.grant.code !== options.expectedCode) {
1110
1259
  throw new Oauth2Error(`Invalid 'code' provided`);
1111
1260
  }
1112
- if (options.codeExpiresAt) {
1113
- const now = options.now ?? /* @__PURE__ */ new Date();
1114
- if (now.getTime() > options.codeExpiresAt.getTime()) {
1115
- throw new Oauth2Error(`Expired 'code' provided`);
1116
- }
1261
+ verifyCodeExpiration(options.codeExpiresAt, options.now, "code");
1262
+ if (!header.jwk) {
1263
+ throw new Oauth2Error("DPoP header does not contain a JWK");
1264
+ }
1265
+ return {
1266
+ clientAttestation: clientAttestationResult,
1267
+ dpop: { jwk: header.jwk, jwkThumbprint }
1268
+ };
1269
+ }
1270
+ async function verifyAccessTokenRequestAPTITUDE(options) {
1271
+ if (options.dpop.expectedNonce === "") {
1272
+ throw new Oauth2Error(`Invalid 'dpop.expectedNonce' provided`);
1117
1273
  }
1274
+ if (!isPreAuthorizedCodeVerification(options)) {
1275
+ await verifyPkce({
1276
+ callbacks: options.callbacks,
1277
+ codeChallenge: options.pkce.codeChallenge,
1278
+ codeChallengeMethod: options.pkce.codeChallengeMethod,
1279
+ codeVerifier: options.pkce.codeVerifier
1280
+ });
1281
+ }
1282
+ const { header, jwkThumbprint } = await verifyTokenDPoP({
1283
+ allowedSigningAlgs: options.dpop.allowedSigningAlgs,
1284
+ callbacks: options.callbacks,
1285
+ dpopJwt: options.dpop.jwt,
1286
+ expectedNonce: options.dpop.expectedNonce,
1287
+ now: options.now,
1288
+ request: options.request
1289
+ });
1290
+ const clientAttestationResult = await verifyClientAttestation({
1291
+ authorizationServerMetadata: options.authorizationServerMetadata,
1292
+ callbacks: options.callbacks,
1293
+ clientAttestation: options.clientAttestation,
1294
+ config: options.config,
1295
+ dpopJwkThumbprint: jwkThumbprint,
1296
+ now: options.now
1297
+ });
1298
+ verifyGrantParameters(options);
1118
1299
  if (!header.jwk) {
1119
1300
  throw new Oauth2Error("DPoP header does not contain a JWK");
1120
1301
  }
@@ -1123,10 +1304,73 @@ async function verifyAccessTokenRequest(options) {
1123
1304
  dpop: { jwk: header.jwk, jwkThumbprint }
1124
1305
  };
1125
1306
  }
1307
+ function isPreAuthorizedCodeVerification(options) {
1308
+ return options.grant.grantType === preAuthorizedCodeGrantIdentifier;
1309
+ }
1310
+ function verifyGrantParameters(options) {
1311
+ if (isPreAuthorizedCodeVerification(options)) {
1312
+ if (options.grant.preAuthorizedCode !== options.expectedPreAuthorizedCode) {
1313
+ throw new Oauth2Error(`Invalid 'pre-authorized_code' provided`);
1314
+ }
1315
+ verifyTransactionCode(options.grant.txCode, options.expectedTxCode);
1316
+ verifyCodeExpiration(
1317
+ options.preAuthorizedCodeExpiresAt,
1318
+ options.now,
1319
+ "pre-authorized_code"
1320
+ );
1321
+ return;
1322
+ }
1323
+ if (options.grant.grantType !== authorizationCodeGrantIdentifier) {
1324
+ throw new Oauth2Error(
1325
+ "Only authorization_code and pre-authorized_code grants can be verified"
1326
+ );
1327
+ }
1328
+ if (options.grant.code !== options.expectedCode) {
1329
+ throw new Oauth2Error(`Invalid 'code' provided`);
1330
+ }
1331
+ verifyCodeExpiration(options.codeExpiresAt, options.now, "code");
1332
+ }
1333
+ function verifyTransactionCode(txCode, expectedTxCode) {
1334
+ if (txCode === expectedTxCode) return;
1335
+ if (expectedTxCode === void 0) {
1336
+ throw new Oauth2Error("Request contains 'tx_code' that was not expected");
1337
+ }
1338
+ if (txCode === void 0) {
1339
+ throw new Oauth2Error("Missing required 'tx_code' in request");
1340
+ }
1341
+ throw new Oauth2Error("Invalid 'tx_code' provided");
1342
+ }
1343
+ function verifyCodeExpiration(expiresAt, date, codeParameter) {
1344
+ if (!expiresAt) return;
1345
+ if (Number.isNaN(expiresAt.getTime())) {
1346
+ throw new Oauth2Error(`Invalid expiration date for '${codeParameter}'`);
1347
+ }
1348
+ const now = date ?? /* @__PURE__ */ new Date();
1349
+ if (now.getTime() > expiresAt.getTime()) {
1350
+ throw new Oauth2Error(`Expired '${codeParameter}' provided`);
1351
+ }
1352
+ }
1353
+ var dispatchVerifyAccessTokenRequest = createVersionDispatcher6({
1354
+ [ItWalletSpecsVersion7.APTITUDE]: (o) => verifyAccessTokenRequestAPTITUDE(
1355
+ o
1356
+ ),
1357
+ [ItWalletSpecsVersion7.V1_0]: (o) => verifyAccessTokenRequestV1_4(
1358
+ o
1359
+ ),
1360
+ [ItWalletSpecsVersion7.V1_3]: (o) => verifyAccessTokenRequestV1_4(
1361
+ o
1362
+ ),
1363
+ [ItWalletSpecsVersion7.V1_4]: (o) => verifyAccessTokenRequestV1_4(
1364
+ o
1365
+ )
1366
+ });
1367
+ function verifyAccessTokenRequest(options) {
1368
+ return dispatchVerifyAccessTokenRequest(options);
1369
+ }
1126
1370
 
1127
1371
  // src/authorization-request/create-authorization-request.ts
1128
1372
  import {
1129
- ItWalletSpecsVersion as ItWalletSpecsVersion3,
1373
+ ItWalletSpecsVersion as ItWalletSpecsVersion8,
1130
1374
  addSecondsToDate as addSecondsToDate3,
1131
1375
  dateToSeconds as dateToSeconds4,
1132
1376
  dispatchByVersion,
@@ -1282,16 +1526,19 @@ async function createPushedAuthorizationRequest(options) {
1282
1526
  }
1283
1527
  function parseAuthorizationRequestByVersion(options, baseAuthorizationRequest) {
1284
1528
  return dispatchByVersion(options.config.itWalletSpecsVersion, {
1285
- [ItWalletSpecsVersion3.V1_0]: () => zAuthorizationRequestV1_0.parse({
1529
+ [ItWalletSpecsVersion8.APTITUDE]: () => zAuthorizationRequestV1_3.parse(
1530
+ baseAuthorizationRequest
1531
+ ),
1532
+ [ItWalletSpecsVersion8.V1_0]: () => zAuthorizationRequestV1_0.parse({
1286
1533
  ...baseAuthorizationRequest,
1287
1534
  response_mode: options.responseMode
1288
1535
  }),
1289
- [ItWalletSpecsVersion3.V1_3]: () => zAuthorizationRequestV1_3.parse(
1536
+ // V1_4 reuses V1_3 authorization request schema — no breaking changes between versions.
1537
+ [ItWalletSpecsVersion8.V1_3]: () => zAuthorizationRequestV1_3.parse(
1290
1538
  baseAuthorizationRequest
1291
1539
  ),
1292
- // V1_4 reuses V1_3 authorization request schema — no breaking changes between versions.
1293
1540
  // Verified against compare/1.3.3...1.4.1: authorization request parameters identical.
1294
- [ItWalletSpecsVersion3.V1_4]: () => zAuthorizationRequestV1_3.parse(
1541
+ [ItWalletSpecsVersion8.V1_4]: () => zAuthorizationRequestV1_3.parse(
1295
1542
  baseAuthorizationRequest
1296
1543
  )
1297
1544
  });
@@ -1387,7 +1634,7 @@ function parseAuthorizationRequest(options) {
1387
1634
 
1388
1635
  // src/authorization-request/parse-pushed-authorization-request.ts
1389
1636
  import {
1390
- ItWalletSpecsVersion as ItWalletSpecsVersion4,
1637
+ ItWalletSpecsVersion as ItWalletSpecsVersion9,
1391
1638
  decodeJwt as decodeJwt4,
1392
1639
  dispatchByVersion as dispatchByVersion2,
1393
1640
  formatZodError as formatZodError2,
@@ -1536,11 +1783,12 @@ ${formatZodError2(parsedAuthorizationRequest.error)}`
1536
1783
  }
1537
1784
  function getAuthorizationRequestSchema(config) {
1538
1785
  return dispatchByVersion2(config.itWalletSpecsVersion, {
1539
- [ItWalletSpecsVersion4.V1_0]: () => zAuthorizationRequestV1_0,
1540
- [ItWalletSpecsVersion4.V1_3]: () => zAuthorizationRequestV1_3,
1786
+ [ItWalletSpecsVersion9.APTITUDE]: () => zAuthorizationRequestV1_3,
1787
+ [ItWalletSpecsVersion9.V1_0]: () => zAuthorizationRequestV1_0,
1541
1788
  // V1_4 reuses V1_3 PAR schema — no breaking changes between versions.
1789
+ [ItWalletSpecsVersion9.V1_3]: () => zAuthorizationRequestV1_3,
1542
1790
  // Verified against compare/1.3.3...1.4.1: authorization request parameters identical.
1543
- [ItWalletSpecsVersion4.V1_4]: () => zAuthorizationRequestV1_3
1791
+ [ItWalletSpecsVersion9.V1_4]: () => zAuthorizationRequestV1_3
1544
1792
  });
1545
1793
  }
1546
1794
 
@@ -2372,6 +2620,8 @@ export {
2372
2620
  createPushedAuthorizationRequest,
2373
2621
  createTokenDPoP,
2374
2622
  createTokenRequest,
2623
+ createTokenRequestAPTITUDE,
2624
+ createTokenRequestV1_4,
2375
2625
  createWalletAttestationJwt as createWalletAttestationJwtV1_0,
2376
2626
  createWalletAttestationJwt2 as createWalletAttestationJwtV1_3,
2377
2627
  createWalletAttestationJwt3 as createWalletAttestationJwtV1_4,
@@ -2394,6 +2644,7 @@ export {
2394
2644
  parseJarRequest,
2395
2645
  parseMrtdChallenge,
2396
2646
  parsePushedAuthorizationRequest,
2647
+ preAuthorizedCodeGrantIdentifier,
2397
2648
  refreshTokenGrantIdentifier,
2398
2649
  signedAuthorizationRequestJwtHeaderTyp,
2399
2650
  toURLSearchParams,
@@ -2414,8 +2665,10 @@ export {
2414
2665
  zAccessTokenProfileJwtHeader,
2415
2666
  zAccessTokenProfileJwtPayload,
2416
2667
  zAccessTokenRequest,
2668
+ zAccessTokenRequestAPTITUDE,
2417
2669
  zAccessTokenResponse,
2418
2670
  zAuthorizationCodeGrantIdentifier,
2671
+ zAuthorizationCodeTokenRequest,
2419
2672
  zAuthorizationRequestV1_0,
2420
2673
  zAuthorizationRequestV1_3,
2421
2674
  zDpopJwtHeader,
@@ -2434,6 +2687,8 @@ export {
2434
2687
  zMrtdPopVerifyResponse,
2435
2688
  zMrtdValidationJwtHeader,
2436
2689
  zMrtdValidationJwtPayload,
2690
+ zPreAuthorizedCodeGrantIdentifier,
2691
+ zPreAuthorizedCodeTokenRequest,
2437
2692
  zPushedAuthorizationRequestSigned,
2438
2693
  zPushedAuthorizationRequestUnsignedV1_0,
2439
2694
  zPushedAuthorizationRequestUnsignedV1_3,
@@ -2441,6 +2696,7 @@ export {
2441
2696
  zRefreshTokenGrantIdentifier,
2442
2697
  zRefreshTokenProfileJwtHeader,
2443
2698
  zRefreshTokenProfileJwtPayload,
2699
+ zRefreshTokenTokenRequest,
2444
2700
  zSignedAuthorizationRequestJwtHeaderTyp,
2445
2701
  zWalletAttestationJwtHeaderV1_0,
2446
2702
  zWalletAttestationJwtHeaderV1_3,