@pagopa/io-react-native-wallet 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. package/lib/commonjs/client/generated/wallet-provider.js +22 -22
  2. package/lib/commonjs/client/generated/wallet-provider.js.map +1 -1
  3. package/lib/commonjs/client/index.js +1 -2
  4. package/lib/commonjs/client/index.js.map +1 -1
  5. package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js +2 -1
  6. package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
  7. package/lib/commonjs/credential/issuance/03-start-credential-issuance.js +287 -0
  8. package/lib/commonjs/credential/issuance/03-start-credential-issuance.js.map +1 -0
  9. package/lib/commonjs/credential/issuance/03-start-user-authorization.js +56 -83
  10. package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
  11. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +88 -0
  12. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
  13. package/lib/commonjs/credential/issuance/05-authorize-access.js +56 -33
  14. package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -1
  15. package/lib/commonjs/credential/issuance/06-obtain-credential.js +51 -78
  16. package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
  17. package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js +21 -44
  18. package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
  19. package/lib/commonjs/credential/issuance/index.js +7 -0
  20. package/lib/commonjs/credential/issuance/index.js.map +1 -1
  21. package/lib/commonjs/credential/issuance/types.js +28 -0
  22. package/lib/commonjs/credential/issuance/types.js.map +1 -0
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/pid/sd-jwt/converters.js +5 -9
  25. package/lib/commonjs/pid/sd-jwt/converters.js.map +1 -1
  26. package/lib/commonjs/pid/sd-jwt/types.js +3 -3
  27. package/lib/commonjs/pid/sd-jwt/types.js.map +1 -1
  28. package/lib/commonjs/sd-jwt/__test__/converters.test.js +1 -1
  29. package/lib/commonjs/sd-jwt/__test__/converters.test.js.map +1 -1
  30. package/lib/commonjs/sd-jwt/__test__/index.test.js +30 -43
  31. package/lib/commonjs/sd-jwt/__test__/index.test.js.map +1 -1
  32. package/lib/commonjs/sd-jwt/__test__/types.test.js +16 -24
  33. package/lib/commonjs/sd-jwt/__test__/types.test.js.map +1 -1
  34. package/lib/commonjs/sd-jwt/index.js +3 -9
  35. package/lib/commonjs/sd-jwt/index.js.map +1 -1
  36. package/lib/commonjs/sd-jwt/types.js +11 -16
  37. package/lib/commonjs/sd-jwt/types.js.map +1 -1
  38. package/lib/commonjs/trust/types.js +70 -29
  39. package/lib/commonjs/trust/types.js.map +1 -1
  40. package/lib/commonjs/utils/auth.js +44 -0
  41. package/lib/commonjs/utils/auth.js.map +1 -0
  42. package/lib/commonjs/utils/errors.js +77 -2
  43. package/lib/commonjs/utils/errors.js.map +1 -1
  44. package/lib/commonjs/utils/misc.js +34 -1
  45. package/lib/commonjs/utils/misc.js.map +1 -1
  46. package/lib/commonjs/utils/par.js +23 -15
  47. package/lib/commonjs/utils/par.js.map +1 -1
  48. package/lib/commonjs/utils/pop.js +33 -0
  49. package/lib/commonjs/utils/pop.js.map +1 -0
  50. package/lib/commonjs/wallet-instance-attestation/issuing.js +17 -2
  51. package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
  52. package/lib/commonjs/wallet-instance-attestation/types.js +7 -7
  53. package/lib/commonjs/wallet-instance-attestation/types.js.map +1 -1
  54. package/lib/module/client/generated/wallet-provider.js +16 -19
  55. package/lib/module/client/generated/wallet-provider.js.map +1 -1
  56. package/lib/module/client/index.js +1 -2
  57. package/lib/module/client/index.js.map +1 -1
  58. package/lib/module/credential/issuance/02-evaluate-issuer-trust.js +2 -1
  59. package/lib/module/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
  60. package/lib/module/credential/issuance/03-start-credential-issuance.js +276 -0
  61. package/lib/module/credential/issuance/03-start-credential-issuance.js.map +1 -0
  62. package/lib/module/credential/issuance/03-start-user-authorization.js +56 -80
  63. package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
  64. package/lib/module/credential/issuance/04-complete-user-authorization.js +85 -1
  65. package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
  66. package/lib/module/credential/issuance/05-authorize-access.js +54 -33
  67. package/lib/module/credential/issuance/05-authorize-access.js.map +1 -1
  68. package/lib/module/credential/issuance/06-obtain-credential.js +50 -75
  69. package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
  70. package/lib/module/credential/issuance/07-verify-and-parse-credential.js +21 -44
  71. package/lib/module/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
  72. package/lib/module/credential/issuance/index.js +2 -1
  73. package/lib/module/credential/issuance/index.js.map +1 -1
  74. package/lib/module/credential/issuance/types.js +18 -0
  75. package/lib/module/credential/issuance/types.js.map +1 -0
  76. package/lib/module/index.js.map +1 -1
  77. package/lib/module/pid/sd-jwt/converters.js +5 -9
  78. package/lib/module/pid/sd-jwt/converters.js.map +1 -1
  79. package/lib/module/pid/sd-jwt/types.js +3 -3
  80. package/lib/module/pid/sd-jwt/types.js.map +1 -1
  81. package/lib/module/sd-jwt/__test__/converters.test.js +1 -1
  82. package/lib/module/sd-jwt/__test__/converters.test.js.map +1 -1
  83. package/lib/module/sd-jwt/__test__/index.test.js +30 -43
  84. package/lib/module/sd-jwt/__test__/index.test.js.map +1 -1
  85. package/lib/module/sd-jwt/__test__/types.test.js +16 -24
  86. package/lib/module/sd-jwt/__test__/types.test.js.map +1 -1
  87. package/lib/module/sd-jwt/index.js +3 -9
  88. package/lib/module/sd-jwt/index.js.map +1 -1
  89. package/lib/module/sd-jwt/types.js +11 -16
  90. package/lib/module/sd-jwt/types.js.map +1 -1
  91. package/lib/module/sd-jwt/verifier.js.map +1 -1
  92. package/lib/module/trust/types.js +70 -29
  93. package/lib/module/trust/types.js.map +1 -1
  94. package/lib/module/utils/auth.js +35 -0
  95. package/lib/module/utils/auth.js.map +1 -0
  96. package/lib/module/utils/errors.js +71 -0
  97. package/lib/module/utils/errors.js.map +1 -1
  98. package/lib/module/utils/misc.js +31 -0
  99. package/lib/module/utils/misc.js.map +1 -1
  100. package/lib/module/utils/par.js +24 -16
  101. package/lib/module/utils/par.js.map +1 -1
  102. package/lib/module/utils/pop.js +24 -0
  103. package/lib/module/utils/pop.js.map +1 -0
  104. package/lib/module/wallet-instance-attestation/issuing.js +17 -2
  105. package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
  106. package/lib/module/wallet-instance-attestation/types.js +7 -7
  107. package/lib/module/wallet-instance-attestation/types.js.map +1 -1
  108. package/lib/typescript/client/generated/wallet-provider.d.ts +35 -13
  109. package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -1
  110. package/lib/typescript/client/index.d.ts.map +1 -1
  111. package/lib/typescript/credential/issuance/01-start-flow.d.ts +1 -0
  112. package/lib/typescript/credential/issuance/01-start-flow.d.ts.map +1 -1
  113. package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts +2 -1
  114. package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts.map +1 -1
  115. package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts +41 -0
  116. package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts.map +1 -0
  117. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +23 -18
  118. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
  119. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +24 -12
  120. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
  121. package/lib/typescript/credential/issuance/05-authorize-access.d.ts +22 -16
  122. package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -1
  123. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts +19 -26
  124. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
  125. package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts +10 -15
  126. package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts.map +1 -1
  127. package/lib/typescript/credential/issuance/index.d.ts +3 -4
  128. package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
  129. package/lib/typescript/credential/issuance/types.d.ts +63 -0
  130. package/lib/typescript/credential/issuance/types.d.ts.map +1 -0
  131. package/lib/typescript/credential/presentation/types.d.ts +6 -6
  132. package/lib/typescript/index.d.ts +2 -1
  133. package/lib/typescript/index.d.ts.map +1 -1
  134. package/lib/typescript/pid/sd-jwt/converters.d.ts.map +1 -1
  135. package/lib/typescript/pid/sd-jwt/types.d.ts +36 -36
  136. package/lib/typescript/pid/sd-jwt/types.d.ts.map +1 -1
  137. package/lib/typescript/sd-jwt/index.d.ts +40 -68
  138. package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
  139. package/lib/typescript/sd-jwt/types.d.ts +64 -121
  140. package/lib/typescript/sd-jwt/types.d.ts.map +1 -1
  141. package/lib/typescript/trust/index.d.ts +150 -48
  142. package/lib/typescript/trust/index.d.ts.map +1 -1
  143. package/lib/typescript/trust/types.d.ts +2838 -1740
  144. package/lib/typescript/trust/types.d.ts.map +1 -1
  145. package/lib/typescript/utils/auth.d.ts +52 -0
  146. package/lib/typescript/utils/auth.d.ts.map +1 -0
  147. package/lib/typescript/utils/errors.d.ts +36 -1
  148. package/lib/typescript/utils/errors.d.ts.map +1 -1
  149. package/lib/typescript/utils/integrity.d.ts +1 -1
  150. package/lib/typescript/utils/misc.d.ts +18 -0
  151. package/lib/typescript/utils/misc.d.ts.map +1 -1
  152. package/lib/typescript/utils/par.d.ts +8 -31
  153. package/lib/typescript/utils/par.d.ts.map +1 -1
  154. package/lib/typescript/utils/pop.d.ts +26 -0
  155. package/lib/typescript/utils/pop.d.ts.map +1 -0
  156. package/lib/typescript/wallet-instance-attestation/issuing.d.ts +2 -1
  157. package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
  158. package/lib/typescript/wallet-instance-attestation/types.d.ts +59 -59
  159. package/lib/typescript/wallet-instance-attestation/types.d.ts.map +1 -1
  160. package/package.json +2 -1
  161. package/src/client/generated/wallet-provider.ts +24 -21
  162. package/src/client/index.ts +3 -8
  163. package/src/credential/issuance/01-start-flow.ts +1 -0
  164. package/src/credential/issuance/02-evaluate-issuer-trust.ts +2 -1
  165. package/src/credential/issuance/03-start-credential-issuance.ts +407 -0
  166. package/src/credential/issuance/03-start-user-authorization.ts +91 -92
  167. package/src/credential/issuance/04-complete-user-authorization.ts +114 -13
  168. package/src/credential/issuance/05-authorize-access.ts +74 -49
  169. package/src/credential/issuance/06-obtain-credential.ts +77 -111
  170. package/src/credential/issuance/07-verify-and-parse-credential.ts +30 -67
  171. package/src/credential/issuance/index.ts +6 -4
  172. package/src/credential/issuance/types.ts +25 -0
  173. package/src/index.ts +2 -1
  174. package/src/pid/sd-jwt/converters.ts +5 -11
  175. package/src/pid/sd-jwt/types.ts +8 -6
  176. package/src/sd-jwt/__test__/converters.test.ts +1 -1
  177. package/src/sd-jwt/__test__/index.test.ts +45 -74
  178. package/src/sd-jwt/__test__/types.test.ts +21 -33
  179. package/src/sd-jwt/index.ts +3 -12
  180. package/src/sd-jwt/types.ts +17 -22
  181. package/src/trust/types.ts +64 -32
  182. package/src/utils/auth.ts +37 -0
  183. package/src/utils/errors.ts +85 -1
  184. package/src/utils/integrity.ts +1 -1
  185. package/src/utils/misc.ts +43 -0
  186. package/src/utils/par.ts +29 -17
  187. package/src/utils/pop.ts +34 -0
  188. package/src/wallet-instance-attestation/issuing.ts +39 -2
  189. package/src/wallet-instance-attestation/types.ts +11 -7
  190. package/lib/commonjs/credential/issuance/07-confirm-credential.js +0 -6
  191. package/lib/commonjs/credential/issuance/07-confirm-credential.js.map +0 -1
  192. package/lib/commonjs/credential/issuance/08-confirm-credential.js +0 -6
  193. package/lib/commonjs/credential/issuance/08-confirm-credential.js.map +0 -1
  194. package/lib/module/credential/issuance/07-confirm-credential.js +0 -2
  195. package/lib/module/credential/issuance/07-confirm-credential.js.map +0 -1
  196. package/lib/module/credential/issuance/08-confirm-credential.js +0 -2
  197. package/lib/module/credential/issuance/08-confirm-credential.js.map +0 -1
  198. package/lib/typescript/credential/issuance/07-confirm-credential.d.ts +0 -11
  199. package/lib/typescript/credential/issuance/07-confirm-credential.d.ts.map +0 -1
  200. package/lib/typescript/credential/issuance/08-confirm-credential.d.ts +0 -11
  201. package/lib/typescript/credential/issuance/08-confirm-credential.d.ts.map +0 -1
  202. package/src/credential/issuance/07-confirm-credential.ts +0 -14
  203. package/src/credential/issuance/08-confirm-credential.ts +0 -14
  204. package/src/sd-jwt/__test__/converters.test.js +0 -24
  205. package/src/sd-jwt/verifier.js +0 -12
@@ -4,24 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.startUserAuthorization = void 0;
7
- var z = _interopRequireWildcard(require("zod"));
8
- var _reactNativeUuid = _interopRequireDefault(require("react-native-uuid"));
9
- var _par = require("../../utils/par");
10
- var _decoder = require("../../utils/decoder");
11
- var _misc = require("../../utils/misc");
7
+ var _misc = require("../../../src/utils/misc");
8
+ var _par = require("../../../src/utils/par");
12
9
  var _const = require("./const");
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
10
+ /**
11
+ * Ensures that the credential type requested is supported by the issuer and contained in the
12
+ * issuer configuration.
13
+ * @param issuerConf The issuer configuration returned by {@link evaluateIssuerTrust}
14
+ * @param credentialType The type of the credential to be requested returned by {@link startFlow}
15
+ * @param context.wiaCryptoContext The Wallet Instance's crypto context
16
+ * @param context.walletInstanceAttestation The Wallet Instance's attestation
17
+ * @param context.redirectUri The redirect URI which is the custom URL scheme that the Wallet Instance is registered to handle
18
+ * @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
19
+ * @returns The credential definition to be used in the request which includes the format and the type and its type
20
+ */
16
21
  const selectCredentialDefinition = (issuerConf, credentialType) => {
17
- const {
18
- credentials_supported
19
- } = issuerConf.openid_credential_issuer;
20
- const [result] = credentials_supported.filter(e => e.credential_definition.type.includes(credentialType)).map(e => ({
21
- credential_definition: {
22
- type: credentialType
23
- },
24
- format: e.format,
22
+ const credential_configurations_supported = issuerConf.openid_credential_issuer.credential_configurations_supported;
23
+ const [result] = Object.keys(credential_configurations_supported).filter(e => e.includes(credentialType)).map(e => ({
24
+ credential_configuration_id: credentialType,
25
+ format: credential_configurations_supported[e].format,
25
26
  type: "openid_credential"
26
27
  }));
27
28
  if (!result) {
@@ -29,90 +30,62 @@ const selectCredentialDefinition = (issuerConf, credentialType) => {
29
30
  }
30
31
  return result;
31
32
  };
32
- const decodeAuthorizationResponse = async raw => {
33
- const {
34
- decodedJwt: {
35
- payload
36
- }
37
- } = await (0, _decoder.getJwtFromFormPost)(raw);
38
33
 
39
- /**
40
- * FIXME: [SIW-628] This step must not make any difference on the credential
41
- * we are authorizing for, being a PID or any other (Q)EAA.
42
- *
43
- * Currently, PID issuer is implemented to skip the CompleteUserAuthorization step
44
- * thus returning a stubbed (code, state) pair.
45
- *
46
- * This is a workaround to proceeed the flow anyway.
47
- * If the response does not map what expected (CorrectShape),
48
- * we try parse into (code, state) to check if we are in the PID scenario.
49
- * In that case, a stub value is returned (will not be evaluated anyway).
50
- *
51
- * This workaround will be obsolete once the PID issuer fixes its implementation
52
- */
53
- const CorrectShape = z.object({
54
- request_uri: z.string()
55
- });
56
- const WrongShapeForPID = z.object({
57
- code: z.string(),
58
- state: z.string()
59
- });
60
- const [correct, wrong] = [CorrectShape.safeParse(payload), WrongShapeForPID.safeParse(payload)];
61
- if (correct.success) {
62
- return correct.data;
63
- } else if (wrong.success) {
64
- return {
65
- request_uri: "https://fake-request-uri"
66
- };
34
+ /**
35
+ * Ensures that the response mode requested is supported by the issuer and contained in the issuer configuration.
36
+ * @param issuerConf The issuer configuration
37
+ * @param credentialType The type of the credential to be requested
38
+ * @returns The response mode to be used in the request, "query" for PersonIdentificationData and "form_post.jwt" for all other types.
39
+ */
40
+ const selectResponseMode = (issuerConf, credentialType) => {
41
+ const responseModeSupported = issuerConf.oauth_authorization_server.response_modes_supported;
42
+ const responseMode = credentialType === "PersonIdentificationData" ? "query" : "form_post.jwt";
43
+ if (!responseModeSupported.includes(responseMode)) {
44
+ throw new Error(`No response mode support the type '${credentialType}'`);
67
45
  }
68
- throw correct.error;
46
+ return responseMode;
69
47
  };
48
+
70
49
  /**
71
- * Start the User authorization phase.
72
- * Perform the Pushed Authorization Request as defined in OAuth 2.0 protocol.
73
- *
74
- * @param issuerConf The Issuer configuration
75
- * @param credentialType The type of the credential to be requested
76
- * @param context.wiaCryptoContext The context to access the key associated with the Wallet Instance Attestation
77
- * @param context.walletInstanceAttestation The Wallet Instance Attestation token
78
- * @param context.walletProviderBaseUrl The base url of the Wallet Provider
79
- * @param context.additionalParams Hash set of parameters to be passed to the authorization endpoint
80
- * (used as a temporary fix until we have a proper User identity in the PID token provider)
81
- * TODO: [SIW-630]
82
- * @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
83
- * @returns The request uri to continue the authorization to
50
+ * WARNING: This function must be called after {@link evaluateIssuerTrust} and {@link startFlow}. The next steam is {@link compeUserAuthorizationWithQueryMode} or {@link compeUserAuthorizationWithFormPostJwtMode}
51
+ * Creates and sends a PAR request to the /as/par endpoint of the authroization server.
52
+ * This starts the authentication flow to obtain an access token.
53
+ * This token enables the Wallet Instance to request a digital credential from the Credential Endpoint of the Credential Issuer.
54
+ * This is an HTTP POST request containing the Wallet Instance identifier (client id), the code challenge and challenge method as specified by PKCE according to RFC 9126
55
+ * along with the WTE and its proof of possession (WTE-PoP).
56
+ * Additionally, it includes a request object, which is a signed JWT encapsulating the type of digital credential requested (authorization_details),
57
+ * the application session identifier on the Wallet Instance side (state),
58
+ * the method (query or form_post.jwt) by which the Authorization Server
59
+ * should transmit the Authorization Response containing the authorization code issued upon the end user's authentication (response_mode)
60
+ * to the Wallet Instance's Token Endpoint to obtain the Access Token, and the redirect_uri of the Wallet Instance where the Authorization Response
61
+ * should be delivered. The redirect is achived by using a custom URL scheme that the Wallet Instance is registered to handle.
62
+ * @param issuerConf The issuer configuration
63
+ * @param credentialType The type of the credential to be requested returned by {@link selectCredentialDefinition}
64
+ * @param ctx The context object containing the Wallet Instance's cryptographic context, the Wallet Instance's attestation, the redirect URI and the fetch implementation
65
+ * @returns The URI to which the end user should be redirected to start the authentication flow, along with the client id, the code verifier and the credential definition
84
66
  */
85
67
  const startUserAuthorization = async (issuerConf, credentialType, ctx) => {
86
68
  const {
87
69
  wiaCryptoContext,
88
70
  walletInstanceAttestation,
89
- walletProviderBaseUrl,
90
- additionalParams = {},
71
+ redirectUri,
91
72
  appFetch = fetch
92
73
  } = ctx;
93
74
  const clientId = await wiaCryptoContext.getPublicKey().then(_ => _.kid);
94
- const codeVerifier = `${_reactNativeUuid.default.v4()}`;
95
- // Make a PAR request to the credential issuer and return the response url
96
- const parUrl = issuerConf.openid_credential_issuer.pushed_authorization_request_endpoint;
75
+ const codeVerifier = (0, _misc.generateRandomAlphaNumericString)(64);
76
+ const parEndpoint = issuerConf.oauth_authorization_server.pushed_authorization_request_endpoint;
77
+ const credentialDefinition = selectCredentialDefinition(issuerConf, credentialType);
78
+ const responseMode = selectResponseMode(issuerConf, credentialType);
97
79
  const getPar = (0, _par.makeParRequest)({
98
80
  wiaCryptoContext,
99
81
  appFetch
100
82
  });
101
- const issuerRequestUri = await getPar(clientId, codeVerifier, walletProviderBaseUrl, parUrl, walletInstanceAttestation, [selectCredentialDefinition(issuerConf, credentialType)], _const.ASSERTION_TYPE);
102
-
103
- // Initialize authorization by requesting the authz request uri
104
- const authzRequestEndpoint = issuerConf.openid_credential_issuer.authorization_endpoint;
105
- const params = new URLSearchParams({
106
- client_id: clientId,
107
- request_uri: issuerRequestUri,
108
- ...additionalParams
109
- });
110
- const {
111
- request_uri
112
- } = await appFetch(`${authzRequestEndpoint}?${params}`).then((0, _misc.hasStatus)(200)).then(res => res.text()).then(decodeAuthorizationResponse);
83
+ const issuerRequestUri = await getPar(clientId, codeVerifier, redirectUri, responseMode, parEndpoint, walletInstanceAttestation, [credentialDefinition], _const.ASSERTION_TYPE);
113
84
  return {
114
- requestUri: request_uri,
115
- clientId
85
+ issuerRequestUri,
86
+ clientId,
87
+ codeVerifier,
88
+ credentialDefinition
116
89
  };
117
90
  };
118
91
  exports.startUserAuthorization = startUserAuthorization;
@@ -1 +1 @@
1
- {"version":3,"names":["z","_interopRequireWildcard","require","_reactNativeUuid","_interopRequireDefault","_par","_decoder","_misc","_const","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","selectCredentialDefinition","issuerConf","credentialType","credentials_supported","openid_credential_issuer","result","filter","e","credential_definition","type","includes","map","format","Error","decodeAuthorizationResponse","raw","decodedJwt","payload","getJwtFromFormPost","CorrectShape","object","request_uri","string","WrongShapeForPID","code","state","correct","wrong","safeParse","success","data","error","startUserAuthorization","ctx","wiaCryptoContext","walletInstanceAttestation","walletProviderBaseUrl","additionalParams","appFetch","fetch","clientId","getPublicKey","then","_","kid","codeVerifier","uuid","v4","parUrl","pushed_authorization_request_endpoint","getPar","makeParRequest","issuerRequestUri","ASSERTION_TYPE","authzRequestEndpoint","authorization_endpoint","params","URLSearchParams","client_id","hasStatus","res","text","requestUri","exports"],"sourceRoot":"../../../../src","sources":["credential/issuance/03-start-user-authorization.ts"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AAEA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AAGA,IAAAM,MAAA,GAAAN,OAAA;AAAyC,SAAAE,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAZ,wBAAAQ,GAAA,EAAAI,WAAA,SAAAA,WAAA,IAAAJ,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAQ,KAAA,GAAAL,wBAAA,CAAAC,WAAA,OAAAI,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAT,GAAA,YAAAQ,KAAA,CAAAE,GAAA,CAAAV,GAAA,SAAAW,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBA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AAU,CAACG,wBAAwB,CAAC6C,qCAAqC;EAC3E,MAAMC,MAAM,GAAG,IAAAC,mBAAc,EAAC;IAAEjB,gBAAgB;IAAEI;EAAS,CAAC,CAAC;EAC7D,MAAMc,gBAAgB,GAAG,MAAMF,MAAM,CACnCV,QAAQ,EACRK,YAAY,EACZT,qBAAqB,EACrBY,MAAM,EACNb,yBAAyB,EACzB,CAACnC,0BAA0B,CAACC,UAAU,EAAEC,cAAc,CAAC,CAAC,EACxDmD,qBACF,CAAC;;EAED;EACA,MAAMC,oBAAoB,GACxBrD,UAAU,CAACG,wBAAwB,CAACmD,sBAAsB;EAC5D,MAAMC,MAAM,GAAG,IAAIC,eAAe,CAAC;IACjCC,SAAS,EAAElB,QAAQ;IACnBnB,WAAW,EAAE+B,gBAAgB;IAC7B,GAAGf;EACL,CAAC,CAAC;EAEF,MAAM;IAAEhB;EAAY,CAAC,GAAG,MAAMiB,QAAQ,CAAE,GAAEgB,oBAAqB,IAAGE,MAAO,EAAC,CAAC,CACxEd,IAAI,CAAC,IAAAiB,eAAS,EAAC,GAAG,CAAC,CAAC,CACpBjB,IAAI,CAAEkB,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBnB,IAAI,CAAC5B,2BAA2B,CAAC;EAEpC,OAAO;IAAEgD,UAAU,EAAEzC,WAAW;IAAEmB;EAAS,CAAC;AAC9C,CAAC;AAACuB,OAAA,CAAA/B,sBAAA,GAAAA,sBAAA"}
1
+ {"version":3,"names":["_misc","require","_par","_const","selectCredentialDefinition","issuerConf","credentialType","credential_configurations_supported","openid_credential_issuer","result","Object","keys","filter","e","includes","map","credential_configuration_id","format","type","Error","selectResponseMode","responseModeSupported","oauth_authorization_server","response_modes_supported","responseMode","startUserAuthorization","ctx","wiaCryptoContext","walletInstanceAttestation","redirectUri","appFetch","fetch","clientId","getPublicKey","then","_","kid","codeVerifier","generateRandomAlphaNumericString","parEndpoint","pushed_authorization_request_endpoint","credentialDefinition","getPar","makeParRequest","issuerRequestUri","ASSERTION_TYPE","exports"],"sourceRoot":"../../../../src","sources":["credential/issuance/03-start-user-authorization.ts"],"mappings":";;;;;;AAEA,IAAAA,KAAA,GAAAC,OAAA;AAOA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMG,0BAA0B,GAAGA,CACjCC,UAAkD,EAClDC,cAAgD,KACxB;EACxB,MAAMC,mCAAmC,GACvCF,UAAU,CAACG,wBAAwB,CAACD,mCAAmC;EAEzE,MAAM,CAACE,MAAM,CAAC,GAAGC,MAAM,CAACC,IAAI,CAACJ,mCAAmC,CAAC,CAC9DK,MAAM,CAAEC,CAAC,IAAKA,CAAC,CAACC,QAAQ,CAACR,cAAc,CAAC,CAAC,CACzCS,GAAG,CAAEF,CAAC,KAAM;IACXG,2BAA2B,EAAEV,cAAc;IAC3CW,MAAM,EAAEV,mCAAmC,CAACM,CAAC,CAAC,CAAEI,MAAM;IACtDC,IAAI,EAAE;EACR,CAAC,CAAC,CAAC;EAEL,IAAI,CAACT,MAAM,EAAE;IACX,MAAM,IAAIU,KAAK,CAAE,mCAAkCb,cAAe,GAAE,CAAC;EACvE;EACA,OAAOG,MAAM;AACf,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,MAAMW,kBAAkB,GAAGA,CACzBf,UAAkD,EAClDC,cAAgD,KAC/B;EACjB,MAAMe,qBAAqB,GACzBhB,UAAU,CAACiB,0BAA0B,CAACC,wBAAwB;EAEhE,MAAMC,YAAY,GAChBlB,cAAc,KAAK,0BAA0B,GAAG,OAAO,GAAG,eAAe;EAE3E,IAAI,CAACe,qBAAqB,CAACP,QAAQ,CAACU,YAAY,CAAC,EAAE;IACjD,MAAM,IAAIL,KAAK,CAAE,sCAAqCb,cAAe,GAAE,CAAC;EAC1E;EAEA,OAAOkB,YAAY;AACrB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,sBAA8C,GAAG,MAAAA,CAC5DpB,UAAU,EACVC,cAAc,EACdoB,GAAG,KACA;EACH,MAAM;IACJC,gBAAgB;IAChBC,yBAAyB;IACzBC,WAAW;IACXC,QAAQ,GAAGC;EACb,CAAC,GAAGL,GAAG;EAEP,MAAMM,QAAQ,GAAG,MAAML,gBAAgB,CAACM,YAAY,CAAC,CAAC,CAACC,IAAI,CAAEC,CAAC,IAAKA,CAAC,CAACC,GAAG,CAAC;EACzE,MAAMC,YAAY,GAAG,IAAAC,sCAAgC,EAAC,EAAE,CAAC;EACzD,MAAMC,WAAW,GACflC,UAAU,CAACiB,0BAA0B,CAACkB,qCAAqC;EAC7E,MAAMC,oBAAoB,GAAGrC,0BAA0B,CACrDC,UAAU,EACVC,cACF,CAAC;EACD,MAAMkB,YAAY,GAAGJ,kBAAkB,CAACf,UAAU,EAAEC,cAAc,CAAC;EAEnE,MAAMoC,MAAM,GAAG,IAAAC,mBAAc,EAAC;IAAEhB,gBAAgB;IAAEG;EAAS,CAAC,CAAC;EAC7D,MAAMc,gBAAgB,GAAG,MAAMF,MAAM,CACnCV,QAAQ,EACRK,YAAY,EACZR,WAAW,EACXL,YAAY,EACZe,WAAW,EACXX,yBAAyB,EACzB,CAACa,oBAAoB,CAAC,EACtBI,qBACF,CAAC;EAED,OAAO;IAAED,gBAAgB;IAAEZ,QAAQ;IAAEK,YAAY;IAAEI;EAAqB,CAAC;AAC3E,CAAC;AAACK,OAAA,CAAArB,sBAAA,GAAAA,sBAAA"}
@@ -3,4 +3,92 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.completeUserAuthorizationWithQueryMode = exports.completeUserAuthorizationWithFormPostJwtMode = void 0;
7
+ var _auth = require("../../../src/utils/auth");
8
+ var _misc = require("../../utils/misc");
9
+ var _parseUrl = _interopRequireDefault(require("parse-url"));
10
+ var _errors = require("../../utils/errors");
11
+ var _reactNative = require("react-native");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ /**
14
+ * The interface of the phase to complete User authorization via strong identification when the response mode is "query" and the request credential is a PersonIdentificationData.
15
+ */
16
+
17
+ /**
18
+ * WARNING: This function must be called after {@link startUserAuthorization}. The next function to be called is {@link authorizeAccess}.
19
+ * The interface of the phase to complete User authorization via strong identification when the response mode is "query" and the request credential is a PersonIdentificationData.
20
+ * It is used to complete the user authorization by catching the redirectSchema from the authorization server which then contains the authorization response.
21
+ * This function utilizes the authorization context to open an in-app browser capable of catching the redirectSchema to perform a get request to the authorization endpoint.
22
+ * If the 302 redirect happens and the redirectSchema is caught, the function will return the authorization response after parsing it from the query string.
23
+ * @param issuerRequestUri the URI of the issuer where the request is sent
24
+ * @param clientId Identifies the current client across all the requests of the issuing flow returned by {@link startUserAuthorization}
25
+ * @param issuerConf The issuer configuration returned by {@link evaluateIssuerTrust}
26
+ * @param authorizationContext The context to identify the user which will be used to start the authorization. It's needed only when requesting a PersonalIdentificationData credential. The implementantion should open an in-app browser capable of catching the redirectSchema.
27
+ * If not specified, the default browser is used
28
+ * @param idphint Unique identifier of the SPID IDP selected by the user
29
+ * @param redirectUri The url to reach to complete the user authorization which is the custom URL scheme that the Wallet Instance is registered to handle, usually a custom URL or deeplink
30
+ * @throws {AuthorizationError} if an error occurs during the authorization process
31
+ * @throws {AuthorizationIdpError} if an error occurs during the authorization process and the error is related to the IDP
32
+ * @returns the authorization response which contains code, state and iss
33
+ */
34
+ const completeUserAuthorizationWithQueryMode = async (issuerRequestUri, clientId, issuerConf, idpHint, redirectUri, authorizationContext) => {
35
+ /**
36
+ * Starts the authorization flow which dependes on the response mode and the request credential.
37
+ * If the response mode is "query" the authorization flow is handled differently via the authorization context which opens an in-app browser capable of catching the redirectSchema.
38
+ * The form_post.jwt mode is not currently supported.
39
+ */
40
+ const authzRequestEndpoint = issuerConf.oauth_authorization_server.authorization_endpoint;
41
+ const params = new URLSearchParams({
42
+ client_id: clientId,
43
+ request_uri: issuerRequestUri,
44
+ idphint: idpHint
45
+ });
46
+ const authUrl = `${authzRequestEndpoint}?${params}`;
47
+ var authRedirectUrl;
48
+ if (authorizationContext) {
49
+ const redirectSchema = new URL(redirectUri).protocol.replace(":", "");
50
+ authRedirectUrl = await authorizationContext.authorize(authUrl, redirectSchema).catch(e => {
51
+ throw new _errors.AuthorizationError(e.message);
52
+ });
53
+ } else {
54
+ // handler for redirectUri
55
+ _reactNative.Linking.addEventListener("url", _ref => {
56
+ let {
57
+ url
58
+ } = _ref;
59
+ if (url.includes(redirectUri)) {
60
+ authRedirectUrl = url;
61
+ }
62
+ });
63
+ const openAuthUrlInBrowser = _reactNative.Linking.openURL(authUrl);
64
+
65
+ /*
66
+ * Waits for 120 seconds for the identificationRedirectUrl variable to be set
67
+ * by the custom url handler. If the timeout is exceeded, throw an exception
68
+ */
69
+ const unitAuthRedirectIsNotUndefined = (0, _misc.until)(() => authRedirectUrl !== undefined, 120);
70
+ await Promise.all([openAuthUrlInBrowser, unitAuthRedirectIsNotUndefined]);
71
+ if (authRedirectUrl === undefined) {
72
+ throw new _errors.AuthorizationError("Invalid authentication redirect url");
73
+ }
74
+ }
75
+ const urlParse = (0, _parseUrl.default)(authRedirectUrl);
76
+ const authRes = _auth.AuthorizationResultShape.safeParse(urlParse.query);
77
+ if (!authRes.success) {
78
+ const authErr = _auth.AuthorizationErrorShape.safeParse(urlParse.query);
79
+ if (!authErr.success) {
80
+ throw new _errors.AuthorizationError(authRes.error.message); // an error occured while parsing the result and the error
81
+ }
82
+
83
+ throw new _errors.AuthorizationIdpError(authErr.data.error, authErr.data.error_description);
84
+ }
85
+ return authRes.data;
86
+ };
87
+
88
+ // TODO: SIW-1120 implement generic credential issuance flow
89
+ exports.completeUserAuthorizationWithQueryMode = completeUserAuthorizationWithQueryMode;
90
+ const completeUserAuthorizationWithFormPostJwtMode = () => {
91
+ throw new Error("Not implemented");
92
+ };
93
+ exports.completeUserAuthorizationWithFormPostJwtMode = completeUserAuthorizationWithFormPostJwtMode;
6
94
  //# sourceMappingURL=04-complete-user-authorization.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["credential/issuance/04-complete-user-authorization.ts"],"mappings":""}
1
+ {"version":3,"names":["_auth","require","_misc","_parseUrl","_interopRequireDefault","_errors","_reactNative","obj","__esModule","default","completeUserAuthorizationWithQueryMode","issuerRequestUri","clientId","issuerConf","idpHint","redirectUri","authorizationContext","authzRequestEndpoint","oauth_authorization_server","authorization_endpoint","params","URLSearchParams","client_id","request_uri","idphint","authUrl","authRedirectUrl","redirectSchema","URL","protocol","replace","authorize","catch","e","AuthorizationError","message","Linking","addEventListener","_ref","url","includes","openAuthUrlInBrowser","openURL","unitAuthRedirectIsNotUndefined","until","undefined","Promise","all","urlParse","parseUrl","authRes","AuthorizationResultShape","safeParse","query","success","authErr","AuthorizationErrorShape","error","AuthorizationIdpError","data","error_description","exports","completeUserAuthorizationWithFormPostJwtMode","Error"],"sourceRoot":"../../../../src","sources":["credential/issuance/04-complete-user-authorization.ts"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAMA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AAAuC,SAAAG,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEvC;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,sCAA8E,GACzF,MAAAA,CACEC,gBAAgB,EAChBC,QAAQ,EACRC,UAAU,EACVC,OAAO,EACPC,WAAW,EACXC,oBAAoB,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ACrE;EACF;EAEA,MAAMc,QAAQ,GAAG,IAAAC,iBAAQ,EAACvB,eAAe,CAAC;EAC1C,MAAMwB,OAAO,GAAGC,8BAAwB,CAACC,SAAS,CAACJ,QAAQ,CAACK,KAAK,CAAC;EAClE,IAAI,CAACH,OAAO,CAACI,OAAO,EAAE;IACpB,MAAMC,OAAO,GAAGC,6BAAuB,CAACJ,SAAS,CAACJ,QAAQ,CAACK,KAAK,CAAC;IACjE,IAAI,CAACE,OAAO,CAACD,OAAO,EAAE;MACpB,MAAM,IAAIpB,0BAAkB,CAACgB,OAAO,CAACO,KAAK,CAACtB,OAAO,CAAC,CAAC,CAAC;IACvD;;IACA,MAAM,IAAIuB,6BAAqB,CAC7BH,OAAO,CAACI,IAAI,CAACF,KAAK,EAClBF,OAAO,CAACI,IAAI,CAACC,iBACf,CAAC;EACH;EACA,OAAOV,OAAO,CAACS,IAAI;AACrB,CAAC;;AAEH;AAAAE,OAAA,CAAAnD,sCAAA,GAAAA,sCAAA;AACO,MAAMoD,4CAA4C,GAAGA,CAAA,KAAM;EAChE,MAAM,IAAIC,KAAK,CAAC,iBAAiB,CAAC;AACpC,CAAC;AAACF,OAAA,CAAAC,4CAAA,GAAAA,4CAAA"}
@@ -4,60 +4,83 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.authorizeAccess = void 0;
7
+ var _misc = require("../../../src/utils/misc");
8
+ var _crypto = require("../../../src/utils/crypto");
9
+ var _dpop = require("../../../src/utils/dpop");
7
10
  var _reactNativeUuid = _interopRequireDefault(require("react-native-uuid"));
8
- var _crypto = require("../../utils/crypto");
9
- var _dpop = require("../../utils/dpop");
10
- var _misc = require("../../utils/misc");
11
+ var _pop = require("../../../src/utils/pop");
12
+ var WalletInstanceAttestation = _interopRequireWildcard(require("../../wallet-instance-attestation"));
11
13
  var _const = require("./const");
14
+ var _types = require("./types");
15
+ var _errors = require("../../../src/utils/errors");
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
19
  /**
14
- * Obtain the access token to finally request the credential
15
- *
16
- * @param issuerConf The Issuer configuration
17
- * @param code The access code from the User authorization phase
18
- * @param clientId Identifies the current client across all the requests of the issuing flow
19
- * @param context.walletInstanceAttestation The Wallet Instance Attestation token
20
- * @param context.walletProviderBaseUrl The base url of the Wallet Provider
20
+ * Creates and sends the DPoP Proof JWT to be presented with the authorization code to the /token endpoint of the authorization server
21
+ * for requesting the issuance of an access token bound to the public key of the Wallet Instance contained within the DPoP.
22
+ * This enables the Wallet Instance to request a digital credential.
23
+ * The DPoP Proof JWT is generated according to the section 4.3 of the DPoP RFC 9449 specification.
24
+ * @param issuerConf The issuer configuration returned by {@link evaluateIssuerTrust}
25
+ * @param code The authorization code returned by {@link completeUserAuthorizationWithQueryMode} or {@link completeUserAuthorizationWithFormPost}
26
+ * @param redirectUri The redirect URI which is the custom URL scheme that the Wallet Instance is registered to handle
27
+ * @param clientId The client id returned by {@link startUserAuthorization}
28
+ * @param codeVerifier The code verifier returned by {@link startUserAuthorization}
29
+ * @param context.walletInstanceAttestation The Wallet Instance's attestation
30
+ * @param context.wiaCryptoContext The Wallet Instance's crypto context
21
31
  * @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
22
- * @returns
32
+ * @throws {ValidationFailed} if an error occurs while parsing the token response
33
+ * @return The token response containing the access token along with the token request signed with DPoP which has to be used in the {@link obtainCredential} step.
23
34
  */
24
- const authorizeAccess = async (issuerConf, code, clientId, context) => {
35
+ const authorizeAccess = async (issuerConf, code, clientId, redirectUri, codeVerifier, context) => {
25
36
  const {
26
37
  appFetch = fetch,
27
38
  walletInstanceAttestation,
28
- walletProviderBaseUrl
39
+ wiaCryptoContext
29
40
  } = context;
30
- const tokenUrl = issuerConf.openid_credential_issuer.token_endpoint;
31
-
41
+ const parEndpoint = issuerConf.oauth_authorization_server.pushed_authorization_request_endpoint;
42
+ const parUrl = new URL(parEndpoint);
43
+ const aud = `${parUrl.protocol}//${parUrl.hostname}`;
44
+ const iss = WalletInstanceAttestation.decode(walletInstanceAttestation).payload.cnf.jwk.kid;
45
+ const tokenUrl = issuerConf.oauth_authorization_server.token_endpoint;
32
46
  // Use an ephemeral key to be destroyed after use
33
- const signedDPop = await (0, _crypto.withEphemeralKey)(ephemeralContext => (0, _dpop.createDPopToken)({
34
- htm: "POST",
35
- htu: tokenUrl,
36
- jti: `${_reactNativeUuid.default.v4()}`
37
- }, ephemeralContext));
38
- const codeVerifier = `${_reactNativeUuid.default.v4()}`;
47
+ const tokenRequestSignedDPop = await (0, _crypto.withEphemeralKey)(async ephimeralContext => {
48
+ return await (0, _dpop.createDPopToken)({
49
+ htm: "POST",
50
+ htu: tokenUrl,
51
+ jti: `${_reactNativeUuid.default.v4()}`
52
+ }, ephimeralContext);
53
+ });
54
+ const signedWiaPoP = await (0, _pop.createPopToken)({
55
+ jti: `${_reactNativeUuid.default.v4()}`,
56
+ aud,
57
+ iss
58
+ }, wiaCryptoContext);
39
59
  const requestBody = {
40
- grant_type: "authorization code",
60
+ grant_type: "authorization_code",
41
61
  client_id: clientId,
42
62
  code,
63
+ redirect_uri: redirectUri,
43
64
  code_verifier: codeVerifier,
44
65
  client_assertion_type: _const.ASSERTION_TYPE,
45
- client_assertion: walletInstanceAttestation,
46
- redirect_uri: walletProviderBaseUrl
66
+ client_assertion: walletInstanceAttestation + "~" + signedWiaPoP
47
67
  };
48
- var formBody = new URLSearchParams(requestBody);
49
- return appFetch(tokenUrl, {
68
+ const authorizationRequestFormBody = new URLSearchParams(requestBody);
69
+ const tokenRes = await appFetch(tokenUrl, {
50
70
  method: "POST",
51
71
  headers: {
52
72
  "Content-Type": "application/x-www-form-urlencoded",
53
- DPoP: signedDPop
73
+ DPoP: tokenRequestSignedDPop
54
74
  },
55
- body: formBody.toString()
56
- }).then((0, _misc.hasStatus)(200)).then(res => res.json()).then(body => ({
57
- accessToken: body.access_token,
58
- nonce: body.c_nonce,
59
- clientId
60
- }));
75
+ body: authorizationRequestFormBody.toString()
76
+ }).then((0, _misc.hasStatus)(200)).then(res => res.json()).then(body => _types.TokenResponse.safeParse(body));
77
+ if (!tokenRes.success) {
78
+ throw new _errors.ValidationFailed(tokenRes.error.message);
79
+ }
80
+ return {
81
+ accessToken: tokenRes.data,
82
+ tokenRequestSignedDPop
83
+ };
61
84
  };
62
85
  exports.authorizeAccess = authorizeAccess;
63
86
  //# sourceMappingURL=05-authorize-access.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNativeUuid","_interopRequireDefault","require","_crypto","_dpop","_misc","_const","obj","__esModule","default","authorizeAccess","issuerConf","code","clientId","context","appFetch","fetch","walletInstanceAttestation","walletProviderBaseUrl","tokenUrl","openid_credential_issuer","token_endpoint","signedDPop","withEphemeralKey","ephemeralContext","createDPopToken","htm","htu","jti","uuid","v4","codeVerifier","requestBody","grant_type","client_id","code_verifier","client_assertion_type","ASSERTION_TYPE","client_assertion","redirect_uri","formBody","URLSearchParams","method","headers","DPoP","body","toString","then","hasStatus","res","json","accessToken","access_token","nonce","c_nonce","exports"],"sourceRoot":"../../../../src","sources":["credential/issuance/05-authorize-access.ts"],"mappings":";;;;;;AAAA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,KAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAAyC,SAAAD,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAqBzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,eAAgC,GAAG,MAAAA,CAC9CC,UAAU,EACVC,IAAI,EACJC,QAAQ,EACRC,OAAO,KAC+D;EACtE,MAAM;IACJC,QAAQ,GAAGC,KAAK;IAChBC,yBAAyB;IACzBC;EACF,CAAC,GAAGJ,OAAO;EAEX,MAAMK,QAAQ,GAAGR,UAAU,CAACS,wBAAwB,CAACC,cAAc;;EAEnE;EACA,MAAMC,UAAU,GAAG,MAAM,IAAAC,wBAAgB,EAAEC,gBAAgB,IACzD,IAAAC,qBAAe,EACb;IACEC,GAAG,EAAE,MAAM;IACXC,GAAG,EAAER,QAAQ;IACbS,GAAG,EAAG,GAAEC,wBAAI,CAACC,EAAE,CAAC,CAAE;EACpB,CAAC,EACDN,gBACF,CACF,CAAC;EAED,MAAMO,YAAY,GAAI,GAAEF,wBAAI,CAACC,EAAE,CAAC,CAAE,EAAC;EACnC,MAAME,WAAW,GAAG;IAClBC,UAAU,EAAE,oBAAoB;IAChCC,SAAS,EAAErB,QAAQ;IACnBD,IAAI;IACJuB,aAAa,EAAEJ,YAAY;IAC3BK,qBAAqB,EAAEC,qBAAc;IACrCC,gBAAgB,EAAErB,yBAAyB;IAC3CsB,YAAY,EAAErB;EAChB,CAAC;EACD,IAAIsB,QAAQ,GAAG,IAAIC,eAAe,CAACT,WAAW,CAAC;EAE/C,OAAOjB,QAAQ,CAACI,QAAQ,EAAE;IACxBuB,MAAM,EAAE,MAAM;IACdC,OAAO,EAAE;MACP,cAAc,EAAE,mCAAmC;MACnDC,IAAI,EAAEtB;IACR,CAAC;IACDuB,IAAI,EAAEL,QAAQ,CAACM,QAAQ,CAAC;EAC1B,CAAC,CAAC,CACCC,IAAI,CAAC,IAAAC,eAAS,EAAC,GAAG,CAAC,CAAC,CACpBD,IAAI,CAAEE,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBH,IAAI,CAAEF,IAAI,KAAM;IACfM,WAAW,EAAEN,IAAI,CAACO,YAAY;IAC9BC,KAAK,EAAER,IAAI,CAACS,OAAO;IACnBzC;EACF,CAAC,CAAC,CAAC;AACP,CAAC;AAAC0C,OAAA,CAAA7C,eAAA,GAAAA,eAAA"}
1
+ {"version":3,"names":["_misc","require","_crypto","_dpop","_reactNativeUuid","_interopRequireDefault","_pop","WalletInstanceAttestation","_interopRequireWildcard","_const","_types","_errors","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","authorizeAccess","issuerConf","code","clientId","redirectUri","codeVerifier","context","appFetch","fetch","walletInstanceAttestation","wiaCryptoContext","parEndpoint","oauth_authorization_server","pushed_authorization_request_endpoint","parUrl","URL","aud","protocol","hostname","iss","decode","payload","cnf","jwk","kid","tokenUrl","token_endpoint","tokenRequestSignedDPop","withEphemeralKey","ephimeralContext","createDPopToken","htm","htu","jti","uuid","v4","signedWiaPoP","createPopToken","requestBody","grant_type","client_id","redirect_uri","code_verifier","client_assertion_type","ASSERTION_TYPE","client_assertion","authorizationRequestFormBody","URLSearchParams","tokenRes","method","headers","DPoP","body","toString","then","hasStatus","res","json","TokenResponse","safeParse","success","ValidationFailed","error","message","accessToken","data","exports"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