@pagopa/io-react-native-wallet 0.11.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/client/generated/wallet-provider.js +126 -0
- package/lib/commonjs/client/generated/wallet-provider.js.map +1 -0
- package/lib/commonjs/client/index.js +40 -0
- package/lib/commonjs/client/index.js.map +1 -0
- package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js +2 -1
- package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
- package/lib/commonjs/credential/issuance/03-start-credential-issuance.js +287 -0
- package/lib/commonjs/credential/issuance/03-start-credential-issuance.js.map +1 -0
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js +56 -83
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +88 -0
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/issuance/05-authorize-access.js +56 -33
- package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -1
- package/lib/commonjs/credential/issuance/06-obtain-credential.js +51 -78
- package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js +21 -44
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/commonjs/credential/issuance/index.js +7 -0
- package/lib/commonjs/credential/issuance/index.js.map +1 -1
- package/lib/commonjs/credential/issuance/types.js +28 -0
- package/lib/commonjs/credential/issuance/types.js.map +1 -0
- package/lib/commonjs/index.js +10 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/pid/sd-jwt/converters.js +5 -9
- package/lib/commonjs/pid/sd-jwt/converters.js.map +1 -1
- package/lib/commonjs/pid/sd-jwt/types.js +3 -3
- package/lib/commonjs/pid/sd-jwt/types.js.map +1 -1
- package/lib/commonjs/sd-jwt/__test__/converters.test.js +1 -1
- package/lib/commonjs/sd-jwt/__test__/converters.test.js.map +1 -1
- package/lib/commonjs/sd-jwt/__test__/index.test.js +30 -43
- package/lib/commonjs/sd-jwt/__test__/index.test.js.map +1 -1
- package/lib/commonjs/sd-jwt/__test__/types.test.js +16 -24
- package/lib/commonjs/sd-jwt/__test__/types.test.js.map +1 -1
- package/lib/commonjs/sd-jwt/index.js +3 -9
- package/lib/commonjs/sd-jwt/index.js.map +1 -1
- package/lib/commonjs/sd-jwt/types.js +11 -16
- package/lib/commonjs/sd-jwt/types.js.map +1 -1
- package/lib/commonjs/trust/types.js +70 -29
- package/lib/commonjs/trust/types.js.map +1 -1
- package/lib/commonjs/utils/auth.js +44 -0
- package/lib/commonjs/utils/auth.js.map +1 -0
- package/lib/commonjs/utils/errors.js +104 -1
- package/lib/commonjs/utils/errors.js.map +1 -1
- package/lib/commonjs/utils/integrity.js +2 -0
- package/lib/commonjs/utils/integrity.js.map +1 -0
- package/lib/commonjs/utils/misc.js +34 -1
- package/lib/commonjs/utils/misc.js.map +1 -1
- package/lib/commonjs/utils/par.js +23 -15
- package/lib/commonjs/utils/par.js.map +1 -1
- package/lib/commonjs/utils/pop.js +33 -0
- package/lib/commonjs/utils/pop.js.map +1 -0
- package/lib/commonjs/wallet-instance/index.js +29 -0
- package/lib/commonjs/wallet-instance/index.js.map +1 -0
- package/lib/commonjs/wallet-instance-attestation/issuing.js +62 -65
- package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
- package/lib/commonjs/wallet-instance-attestation/types.js +8 -8
- package/lib/commonjs/wallet-instance-attestation/types.js.map +1 -1
- package/lib/module/client/generated/wallet-provider.js +102 -0
- package/lib/module/client/generated/wallet-provider.js.map +1 -0
- package/lib/module/client/index.js +33 -0
- package/lib/module/client/index.js.map +1 -0
- package/lib/module/credential/issuance/02-evaluate-issuer-trust.js +2 -1
- package/lib/module/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
- package/lib/module/credential/issuance/03-start-credential-issuance.js +276 -0
- package/lib/module/credential/issuance/03-start-credential-issuance.js.map +1 -0
- package/lib/module/credential/issuance/03-start-user-authorization.js +56 -80
- package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
- package/lib/module/credential/issuance/04-complete-user-authorization.js +85 -1
- package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/module/credential/issuance/05-authorize-access.js +54 -33
- package/lib/module/credential/issuance/05-authorize-access.js.map +1 -1
- package/lib/module/credential/issuance/06-obtain-credential.js +50 -75
- package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js +21 -44
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/module/credential/issuance/index.js +2 -1
- package/lib/module/credential/issuance/index.js.map +1 -1
- package/lib/module/credential/issuance/types.js +18 -0
- package/lib/module/credential/issuance/types.js.map +1 -0
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/pid/sd-jwt/converters.js +5 -9
- package/lib/module/pid/sd-jwt/converters.js.map +1 -1
- package/lib/module/pid/sd-jwt/types.js +3 -3
- package/lib/module/pid/sd-jwt/types.js.map +1 -1
- package/lib/module/sd-jwt/__test__/converters.test.js +1 -1
- package/lib/module/sd-jwt/__test__/converters.test.js.map +1 -1
- package/lib/module/sd-jwt/__test__/index.test.js +30 -43
- package/lib/module/sd-jwt/__test__/index.test.js.map +1 -1
- package/lib/module/sd-jwt/__test__/types.test.js +16 -24
- package/lib/module/sd-jwt/__test__/types.test.js.map +1 -1
- package/lib/module/sd-jwt/index.js +3 -9
- package/lib/module/sd-jwt/index.js.map +1 -1
- package/lib/module/sd-jwt/types.js +11 -16
- package/lib/module/sd-jwt/types.js.map +1 -1
- package/lib/module/trust/types.js +70 -29
- package/lib/module/trust/types.js.map +1 -1
- package/lib/module/utils/auth.js +35 -0
- package/lib/module/utils/auth.js.map +1 -0
- package/lib/module/utils/errors.js +98 -0
- package/lib/module/utils/errors.js.map +1 -1
- package/lib/module/utils/integrity.js +2 -0
- package/lib/module/utils/integrity.js.map +1 -0
- package/lib/module/utils/misc.js +31 -0
- package/lib/module/utils/misc.js.map +1 -1
- package/lib/module/utils/par.js +24 -16
- package/lib/module/utils/par.js.map +1 -1
- package/lib/module/utils/pop.js +24 -0
- package/lib/module/utils/pop.js.map +1 -0
- package/lib/module/wallet-instance/index.js +23 -0
- package/lib/module/wallet-instance/index.js.map +1 -0
- package/lib/module/wallet-instance-attestation/issuing.js +63 -67
- package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
- package/lib/module/wallet-instance-attestation/types.js +8 -8
- package/lib/module/wallet-instance-attestation/types.js.map +1 -1
- package/lib/typescript/client/generated/wallet-provider.d.ts +264 -0
- package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -0
- package/lib/typescript/client/index.d.ts +7 -0
- package/lib/typescript/client/index.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/01-start-flow.d.ts +1 -0
- package/lib/typescript/credential/issuance/01-start-flow.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts +2 -1
- package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts +41 -0
- package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +23 -18
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +24 -12
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/05-authorize-access.d.ts +22 -16
- package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/06-obtain-credential.d.ts +19 -26
- package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts +10 -15
- package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/index.d.ts +3 -4
- package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/types.d.ts +63 -0
- package/lib/typescript/credential/issuance/types.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/types.d.ts +6 -6
- package/lib/typescript/index.d.ts +6 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/pid/sd-jwt/converters.d.ts.map +1 -1
- package/lib/typescript/pid/sd-jwt/types.d.ts +36 -36
- package/lib/typescript/pid/sd-jwt/types.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/index.d.ts +40 -68
- package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/types.d.ts +64 -121
- package/lib/typescript/sd-jwt/types.d.ts.map +1 -1
- package/lib/typescript/trust/index.d.ts +150 -48
- package/lib/typescript/trust/index.d.ts.map +1 -1
- package/lib/typescript/trust/types.d.ts +2838 -1740
- package/lib/typescript/trust/types.d.ts.map +1 -1
- package/lib/typescript/utils/auth.d.ts +52 -0
- package/lib/typescript/utils/auth.d.ts.map +1 -0
- package/lib/typescript/utils/errors.d.ts +48 -0
- package/lib/typescript/utils/errors.d.ts.map +1 -1
- package/lib/typescript/utils/integrity.d.ts +21 -0
- package/lib/typescript/utils/integrity.d.ts.map +1 -0
- package/lib/typescript/utils/misc.d.ts +18 -0
- package/lib/typescript/utils/misc.d.ts.map +1 -1
- package/lib/typescript/utils/par.d.ts +8 -31
- package/lib/typescript/utils/par.d.ts.map +1 -1
- package/lib/typescript/utils/pop.d.ts +26 -0
- package/lib/typescript/utils/pop.d.ts.map +1 -0
- package/lib/typescript/wallet-instance/index.d.ts +7 -0
- package/lib/typescript/wallet-instance/index.d.ts.map +1 -0
- package/lib/typescript/wallet-instance-attestation/issuing.d.ts +17 -4
- package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
- package/lib/typescript/wallet-instance-attestation/types.d.ts +64 -64
- package/lib/typescript/wallet-instance-attestation/types.d.ts.map +1 -1
- package/package.json +9 -5
- package/src/client/generated/wallet-provider.ts +173 -0
- package/src/client/index.ts +53 -0
- package/src/credential/issuance/01-start-flow.ts +1 -0
- package/src/credential/issuance/02-evaluate-issuer-trust.ts +2 -1
- package/src/credential/issuance/03-start-credential-issuance.ts +407 -0
- package/src/credential/issuance/03-start-user-authorization.ts +91 -92
- package/src/credential/issuance/04-complete-user-authorization.ts +114 -13
- package/src/credential/issuance/05-authorize-access.ts +74 -49
- package/src/credential/issuance/06-obtain-credential.ts +77 -111
- package/src/credential/issuance/07-verify-and-parse-credential.ts +30 -67
- package/src/credential/issuance/index.ts +6 -4
- package/src/credential/issuance/types.ts +25 -0
- package/src/index.ts +8 -0
- package/src/pid/sd-jwt/converters.ts +5 -11
- package/src/pid/sd-jwt/types.ts +8 -6
- package/src/sd-jwt/__test__/converters.test.ts +1 -1
- package/src/sd-jwt/__test__/index.test.ts +45 -74
- package/src/sd-jwt/__test__/types.test.ts +21 -33
- package/src/sd-jwt/index.ts +3 -12
- package/src/sd-jwt/types.ts +17 -22
- package/src/trust/types.ts +64 -32
- package/src/utils/auth.ts +37 -0
- package/src/utils/errors.ts +112 -0
- package/src/utils/integrity.ts +23 -0
- package/src/utils/misc.ts +43 -0
- package/src/utils/par.ts +29 -17
- package/src/utils/pop.ts +34 -0
- package/src/wallet-instance/index.ts +29 -0
- package/src/wallet-instance-attestation/issuing.ts +101 -97
- package/src/wallet-instance-attestation/types.ts +12 -8
- package/lib/commonjs/credential/issuance/07-confirm-credential.js +0 -6
- package/lib/commonjs/credential/issuance/07-confirm-credential.js.map +0 -1
- package/lib/commonjs/credential/issuance/08-confirm-credential.js +0 -6
- package/lib/commonjs/credential/issuance/08-confirm-credential.js.map +0 -1
- package/lib/module/credential/issuance/07-confirm-credential.js +0 -2
- package/lib/module/credential/issuance/07-confirm-credential.js.map +0 -1
- package/lib/module/credential/issuance/08-confirm-credential.js +0 -2
- package/lib/module/credential/issuance/08-confirm-credential.js.map +0 -1
- package/lib/typescript/credential/issuance/07-confirm-credential.d.ts +0 -11
- package/lib/typescript/credential/issuance/07-confirm-credential.d.ts.map +0 -1
- package/lib/typescript/credential/issuance/08-confirm-credential.d.ts +0 -11
- package/lib/typescript/credential/issuance/08-confirm-credential.d.ts.map +0 -1
- package/src/credential/issuance/07-confirm-credential.ts +0 -14
- package/src/credential/issuance/08-confirm-credential.ts +0 -14
@@ -1,18 +1,22 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import { makeParRequest } from "../../utils/par";
|
4
|
-
import { getJwtFromFormPost } from "../../utils/decoder";
|
5
|
-
import { hasStatus } from "../../utils/misc";
|
1
|
+
import { generateRandomAlphaNumericString } from "../../../src/utils/misc";
|
2
|
+
import { makeParRequest } from "../../../src/utils/par";
|
6
3
|
import { ASSERTION_TYPE } from "./const";
|
4
|
+
/**
|
5
|
+
* Ensures that the credential type requested is supported by the issuer and contained in the
|
6
|
+
* issuer configuration.
|
7
|
+
* @param issuerConf The issuer configuration returned by {@link evaluateIssuerTrust}
|
8
|
+
* @param credentialType The type of the credential to be requested returned by {@link startFlow}
|
9
|
+
* @param context.wiaCryptoContext The Wallet Instance's crypto context
|
10
|
+
* @param context.walletInstanceAttestation The Wallet Instance's attestation
|
11
|
+
* @param context.redirectUri The redirect URI which is the custom URL scheme that the Wallet Instance is registered to handle
|
12
|
+
* @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
|
13
|
+
* @returns The credential definition to be used in the request which includes the format and the type and its type
|
14
|
+
*/
|
7
15
|
const selectCredentialDefinition = (issuerConf, credentialType) => {
|
8
|
-
const
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
credential_definition: {
|
13
|
-
type: credentialType
|
14
|
-
},
|
15
|
-
format: e.format,
|
16
|
+
const credential_configurations_supported = issuerConf.openid_credential_issuer.credential_configurations_supported;
|
17
|
+
const [result] = Object.keys(credential_configurations_supported).filter(e => e.includes(credentialType)).map(e => ({
|
18
|
+
credential_configuration_id: credentialType,
|
19
|
+
format: credential_configurations_supported[e].format,
|
16
20
|
type: "openid_credential"
|
17
21
|
}));
|
18
22
|
if (!result) {
|
@@ -20,90 +24,62 @@ const selectCredentialDefinition = (issuerConf, credentialType) => {
|
|
20
24
|
}
|
21
25
|
return result;
|
22
26
|
};
|
23
|
-
const decodeAuthorizationResponse = async raw => {
|
24
|
-
const {
|
25
|
-
decodedJwt: {
|
26
|
-
payload
|
27
|
-
}
|
28
|
-
} = await getJwtFromFormPost(raw);
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
*
|
42
|
-
* This workaround will be obsolete once the PID issuer fixes its implementation
|
43
|
-
*/
|
44
|
-
const CorrectShape = z.object({
|
45
|
-
request_uri: z.string()
|
46
|
-
});
|
47
|
-
const WrongShapeForPID = z.object({
|
48
|
-
code: z.string(),
|
49
|
-
state: z.string()
|
50
|
-
});
|
51
|
-
const [correct, wrong] = [CorrectShape.safeParse(payload), WrongShapeForPID.safeParse(payload)];
|
52
|
-
if (correct.success) {
|
53
|
-
return correct.data;
|
54
|
-
} else if (wrong.success) {
|
55
|
-
return {
|
56
|
-
request_uri: "https://fake-request-uri"
|
57
|
-
};
|
28
|
+
/**
|
29
|
+
* Ensures that the response mode requested is supported by the issuer and contained in the issuer configuration.
|
30
|
+
* @param issuerConf The issuer configuration
|
31
|
+
* @param credentialType The type of the credential to be requested
|
32
|
+
* @returns The response mode to be used in the request, "query" for PersonIdentificationData and "form_post.jwt" for all other types.
|
33
|
+
*/
|
34
|
+
const selectResponseMode = (issuerConf, credentialType) => {
|
35
|
+
const responseModeSupported = issuerConf.oauth_authorization_server.response_modes_supported;
|
36
|
+
const responseMode = credentialType === "PersonIdentificationData" ? "query" : "form_post.jwt";
|
37
|
+
if (!responseModeSupported.includes(responseMode)) {
|
38
|
+
throw new Error(`No response mode support the type '${credentialType}'`);
|
58
39
|
}
|
59
|
-
|
40
|
+
return responseMode;
|
60
41
|
};
|
42
|
+
|
61
43
|
/**
|
62
|
-
*
|
63
|
-
*
|
64
|
-
*
|
65
|
-
*
|
66
|
-
*
|
67
|
-
*
|
68
|
-
*
|
69
|
-
*
|
70
|
-
*
|
71
|
-
*
|
72
|
-
*
|
73
|
-
*
|
74
|
-
* @
|
44
|
+
* WARNING: This function must be called after {@link evaluateIssuerTrust} and {@link startFlow}. The next steam is {@link compeUserAuthorizationWithQueryMode} or {@link compeUserAuthorizationWithFormPostJwtMode}
|
45
|
+
* Creates and sends a PAR request to the /as/par endpoint of the authroization server.
|
46
|
+
* This starts the authentication flow to obtain an access token.
|
47
|
+
* This token enables the Wallet Instance to request a digital credential from the Credential Endpoint of the Credential Issuer.
|
48
|
+
* 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
|
49
|
+
* along with the WTE and its proof of possession (WTE-PoP).
|
50
|
+
* Additionally, it includes a request object, which is a signed JWT encapsulating the type of digital credential requested (authorization_details),
|
51
|
+
* the application session identifier on the Wallet Instance side (state),
|
52
|
+
* the method (query or form_post.jwt) by which the Authorization Server
|
53
|
+
* should transmit the Authorization Response containing the authorization code issued upon the end user's authentication (response_mode)
|
54
|
+
* to the Wallet Instance's Token Endpoint to obtain the Access Token, and the redirect_uri of the Wallet Instance where the Authorization Response
|
55
|
+
* should be delivered. The redirect is achived by using a custom URL scheme that the Wallet Instance is registered to handle.
|
56
|
+
* @param issuerConf The issuer configuration
|
57
|
+
* @param credentialType The type of the credential to be requested returned by {@link selectCredentialDefinition}
|
58
|
+
* @param ctx The context object containing the Wallet Instance's cryptographic context, the Wallet Instance's attestation, the redirect URI and the fetch implementation
|
59
|
+
* @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
|
75
60
|
*/
|
76
61
|
export const startUserAuthorization = async (issuerConf, credentialType, ctx) => {
|
77
62
|
const {
|
78
63
|
wiaCryptoContext,
|
79
64
|
walletInstanceAttestation,
|
80
|
-
|
81
|
-
additionalParams = {},
|
65
|
+
redirectUri,
|
82
66
|
appFetch = fetch
|
83
67
|
} = ctx;
|
84
68
|
const clientId = await wiaCryptoContext.getPublicKey().then(_ => _.kid);
|
85
|
-
const codeVerifier =
|
86
|
-
|
87
|
-
const
|
69
|
+
const codeVerifier = generateRandomAlphaNumericString(64);
|
70
|
+
const parEndpoint = issuerConf.oauth_authorization_server.pushed_authorization_request_endpoint;
|
71
|
+
const credentialDefinition = selectCredentialDefinition(issuerConf, credentialType);
|
72
|
+
const responseMode = selectResponseMode(issuerConf, credentialType);
|
88
73
|
const getPar = makeParRequest({
|
89
74
|
wiaCryptoContext,
|
90
75
|
appFetch
|
91
76
|
});
|
92
|
-
const issuerRequestUri = await getPar(clientId, codeVerifier,
|
93
|
-
|
94
|
-
// Initialize authorization by requesting the authz request uri
|
95
|
-
const authzRequestEndpoint = issuerConf.openid_credential_issuer.authorization_endpoint;
|
96
|
-
const params = new URLSearchParams({
|
97
|
-
client_id: clientId,
|
98
|
-
request_uri: issuerRequestUri,
|
99
|
-
...additionalParams
|
100
|
-
});
|
101
|
-
const {
|
102
|
-
request_uri
|
103
|
-
} = await appFetch(`${authzRequestEndpoint}?${params}`).then(hasStatus(200)).then(res => res.text()).then(decodeAuthorizationResponse);
|
77
|
+
const issuerRequestUri = await getPar(clientId, codeVerifier, redirectUri, responseMode, parEndpoint, walletInstanceAttestation, [credentialDefinition], ASSERTION_TYPE);
|
104
78
|
return {
|
105
|
-
|
106
|
-
clientId
|
79
|
+
issuerRequestUri,
|
80
|
+
clientId,
|
81
|
+
codeVerifier,
|
82
|
+
credentialDefinition
|
107
83
|
};
|
108
84
|
};
|
109
85
|
//# sourceMappingURL=03-start-user-authorization.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["generateRandomAlphaNumericString","makeParRequest","ASSERTION_TYPE","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","parEndpoint","pushed_authorization_request_endpoint","credentialDefinition","getPar","issuerRequestUri"],"sourceRoot":"../../../../src","sources":["credential/issuance/03-start-user-authorization.ts"],"mappings":"AAEA,SACEA,gCAAgC,QAE3B,yBAAyB;AAIhC,SAA8BC,cAAc,QAAQ,wBAAwB;AAC5E,SAASC,cAAc,QAAQ,SAAS;AAkBxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,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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C"}
|
@@ -1,2 +1,86 @@
|
|
1
|
-
|
1
|
+
import { AuthorizationErrorShape, AuthorizationResultShape } from "../../../src/utils/auth";
|
2
|
+
import { until } from "../../utils/misc";
|
3
|
+
import parseUrl from "parse-url";
|
4
|
+
import { AuthorizationError, AuthorizationIdpError } from "../../utils/errors";
|
5
|
+
import { Linking } from "react-native";
|
6
|
+
|
7
|
+
/**
|
8
|
+
* 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.
|
9
|
+
*/
|
10
|
+
|
11
|
+
/**
|
12
|
+
* WARNING: This function must be called after {@link startUserAuthorization}. The next function to be called is {@link authorizeAccess}.
|
13
|
+
* 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.
|
14
|
+
* It is used to complete the user authorization by catching the redirectSchema from the authorization server which then contains the authorization response.
|
15
|
+
* 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.
|
16
|
+
* If the 302 redirect happens and the redirectSchema is caught, the function will return the authorization response after parsing it from the query string.
|
17
|
+
* @param issuerRequestUri the URI of the issuer where the request is sent
|
18
|
+
* @param clientId Identifies the current client across all the requests of the issuing flow returned by {@link startUserAuthorization}
|
19
|
+
* @param issuerConf The issuer configuration returned by {@link evaluateIssuerTrust}
|
20
|
+
* @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.
|
21
|
+
* If not specified, the default browser is used
|
22
|
+
* @param idphint Unique identifier of the SPID IDP selected by the user
|
23
|
+
* @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
|
24
|
+
* @throws {AuthorizationError} if an error occurs during the authorization process
|
25
|
+
* @throws {AuthorizationIdpError} if an error occurs during the authorization process and the error is related to the IDP
|
26
|
+
* @returns the authorization response which contains code, state and iss
|
27
|
+
*/
|
28
|
+
export const completeUserAuthorizationWithQueryMode = async (issuerRequestUri, clientId, issuerConf, idpHint, redirectUri, authorizationContext) => {
|
29
|
+
/**
|
30
|
+
* Starts the authorization flow which dependes on the response mode and the request credential.
|
31
|
+
* 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.
|
32
|
+
* The form_post.jwt mode is not currently supported.
|
33
|
+
*/
|
34
|
+
const authzRequestEndpoint = issuerConf.oauth_authorization_server.authorization_endpoint;
|
35
|
+
const params = new URLSearchParams({
|
36
|
+
client_id: clientId,
|
37
|
+
request_uri: issuerRequestUri,
|
38
|
+
idphint: idpHint
|
39
|
+
});
|
40
|
+
const authUrl = `${authzRequestEndpoint}?${params}`;
|
41
|
+
var authRedirectUrl;
|
42
|
+
if (authorizationContext) {
|
43
|
+
const redirectSchema = new URL(redirectUri).protocol.replace(":", "");
|
44
|
+
authRedirectUrl = await authorizationContext.authorize(authUrl, redirectSchema).catch(e => {
|
45
|
+
throw new AuthorizationError(e.message);
|
46
|
+
});
|
47
|
+
} else {
|
48
|
+
// handler for redirectUri
|
49
|
+
Linking.addEventListener("url", _ref => {
|
50
|
+
let {
|
51
|
+
url
|
52
|
+
} = _ref;
|
53
|
+
if (url.includes(redirectUri)) {
|
54
|
+
authRedirectUrl = url;
|
55
|
+
}
|
56
|
+
});
|
57
|
+
const openAuthUrlInBrowser = Linking.openURL(authUrl);
|
58
|
+
|
59
|
+
/*
|
60
|
+
* Waits for 120 seconds for the identificationRedirectUrl variable to be set
|
61
|
+
* by the custom url handler. If the timeout is exceeded, throw an exception
|
62
|
+
*/
|
63
|
+
const unitAuthRedirectIsNotUndefined = until(() => authRedirectUrl !== undefined, 120);
|
64
|
+
await Promise.all([openAuthUrlInBrowser, unitAuthRedirectIsNotUndefined]);
|
65
|
+
if (authRedirectUrl === undefined) {
|
66
|
+
throw new AuthorizationError("Invalid authentication redirect url");
|
67
|
+
}
|
68
|
+
}
|
69
|
+
const urlParse = parseUrl(authRedirectUrl);
|
70
|
+
const authRes = AuthorizationResultShape.safeParse(urlParse.query);
|
71
|
+
if (!authRes.success) {
|
72
|
+
const authErr = AuthorizationErrorShape.safeParse(urlParse.query);
|
73
|
+
if (!authErr.success) {
|
74
|
+
throw new AuthorizationError(authRes.error.message); // an error occured while parsing the result and the error
|
75
|
+
}
|
76
|
+
|
77
|
+
throw new AuthorizationIdpError(authErr.data.error, authErr.data.error_description);
|
78
|
+
}
|
79
|
+
return authRes.data;
|
80
|
+
};
|
81
|
+
|
82
|
+
// TODO: SIW-1120 implement generic credential issuance flow
|
83
|
+
export const completeUserAuthorizationWithFormPostJwtMode = () => {
|
84
|
+
throw new Error("Not implemented");
|
85
|
+
};
|
2
86
|
//# 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":["AuthorizationErrorShape","AuthorizationResultShape","until","parseUrl","AuthorizationError","AuthorizationIdpError","Linking","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","message","addEventListener","_ref","url","includes","openAuthUrlInBrowser","openURL","unitAuthRedirectIsNotUndefined","undefined","Promise","all","urlParse","authRes","safeParse","query","success","authErr","error","data","error_description","completeUserAuthorizationWithFormPostJwtMode","Error"],"sourceRoot":"../../../../src","sources":["credential/issuance/04-complete-user-authorization.ts"],"mappings":"AAAA,SACEA,uBAAuB,EACvBC,wBAAwB,QAGnB,yBAAyB;AAChC,SAASC,KAAK,QAAkB,kBAAkB;AAElD,OAAOC,QAAQ,MAAM,WAAW;AAChC,SAASC,kBAAkB,EAAEC,qBAAqB,QAAQ,oBAAoB;AAE9E,SAASC,OAAO,QAAQ,cAAc;;AAEtC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,MAAMqB,eAAe,KAAKgB,SAAS,EACnC,GACF,CAAC;IAED,MAAMC,OAAO,CAACC,GAAG,CAAC,CAACL,oBAAoB,EAAEE,8BAA8B,CAAC,CAAC;IAEzE,IAAIf,eAAe,KAAKgB,SAAS,EAAE;MACjC,MAAM,IAAInC,kBAAkB,CAAC,qCAAqC,CAAC;IACrE;EACF;EAEA,MAAMsC,QAAQ,GAAGvC,QAAQ,CAACoB,eAAe,CAAC;EAC1C,MAAMoB,OAAO,GAAG1C,wBAAwB,CAAC2C,SAAS,CAACF,QAAQ,CAACG,KAAK,CAAC;EAClE,IAAI,CAACF,OAAO,CAACG,OAAO,EAAE;IACpB,MAAMC,OAAO,GAAG/C,uBAAuB,CAAC4C,SAAS,CAACF,QAAQ,CAACG,KAAK,CAAC;IACjE,IAAI,CAACE,OAAO,CAACD,OAAO,EAAE;MACpB,MAAM,IAAI1C,kBAAkB,CAACuC,OAAO,CAACK,KAAK,CAACjB,OAAO,CAAC,CAAC,CAAC;IACvD;;IACA,MAAM,IAAI1B,qBAAqB,CAC7B0C,OAAO,CAACE,IAAI,CAACD,KAAK,EAClBD,OAAO,CAACE,IAAI,CAACC,iBACf,CAAC;EACH;EACA,OAAOP,OAAO,CAACM,IAAI;AACrB,CAAC;;AAEH;AACA,OAAO,MAAME,4CAA4C,GAAGA,CAAA,KAAM;EAChE,MAAM,IAAIC,KAAK,CAAC,iBAAiB,CAAC;AACpC,CAAC"}
|
@@ -1,55 +1,76 @@
|
|
1
|
+
import { hasStatus } from "../../../src/utils/misc";
|
2
|
+
import { withEphemeralKey } from "../../../src/utils/crypto";
|
3
|
+
import { createDPopToken } from "../../../src/utils/dpop";
|
1
4
|
import uuid from "react-native-uuid";
|
2
|
-
import {
|
3
|
-
import
|
4
|
-
import { hasStatus } from "../../utils/misc";
|
5
|
+
import { createPopToken } from "../../../src/utils/pop";
|
6
|
+
import * as WalletInstanceAttestation from "../../wallet-instance-attestation";
|
5
7
|
import { ASSERTION_TYPE } from "./const";
|
8
|
+
import { TokenResponse } from "./types";
|
9
|
+
import { ValidationFailed } from "../../../src/utils/errors";
|
6
10
|
/**
|
7
|
-
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
* @param
|
12
|
-
* @param
|
13
|
-
* @param
|
11
|
+
* Creates and sends the DPoP Proof JWT to be presented with the authorization code to the /token endpoint of the authorization server
|
12
|
+
* for requesting the issuance of an access token bound to the public key of the Wallet Instance contained within the DPoP.
|
13
|
+
* This enables the Wallet Instance to request a digital credential.
|
14
|
+
* The DPoP Proof JWT is generated according to the section 4.3 of the DPoP RFC 9449 specification.
|
15
|
+
* @param issuerConf The issuer configuration returned by {@link evaluateIssuerTrust}
|
16
|
+
* @param code The authorization code returned by {@link completeUserAuthorizationWithQueryMode} or {@link completeUserAuthorizationWithFormPost}
|
17
|
+
* @param redirectUri The redirect URI which is the custom URL scheme that the Wallet Instance is registered to handle
|
18
|
+
* @param clientId The client id returned by {@link startUserAuthorization}
|
19
|
+
* @param codeVerifier The code verifier returned by {@link startUserAuthorization}
|
20
|
+
* @param context.walletInstanceAttestation The Wallet Instance's attestation
|
21
|
+
* @param context.wiaCryptoContext The Wallet Instance's crypto context
|
14
22
|
* @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
|
15
|
-
* @
|
23
|
+
* @throws {ValidationFailed} if an error occurs while parsing the token response
|
24
|
+
* @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.
|
16
25
|
*/
|
17
|
-
export const authorizeAccess = async (issuerConf, code, clientId, context) => {
|
26
|
+
export const authorizeAccess = async (issuerConf, code, clientId, redirectUri, codeVerifier, context) => {
|
18
27
|
const {
|
19
28
|
appFetch = fetch,
|
20
29
|
walletInstanceAttestation,
|
21
|
-
|
30
|
+
wiaCryptoContext
|
22
31
|
} = context;
|
23
|
-
const
|
24
|
-
|
32
|
+
const parEndpoint = issuerConf.oauth_authorization_server.pushed_authorization_request_endpoint;
|
33
|
+
const parUrl = new URL(parEndpoint);
|
34
|
+
const aud = `${parUrl.protocol}//${parUrl.hostname}`;
|
35
|
+
const iss = WalletInstanceAttestation.decode(walletInstanceAttestation).payload.cnf.jwk.kid;
|
36
|
+
const tokenUrl = issuerConf.oauth_authorization_server.token_endpoint;
|
25
37
|
// Use an ephemeral key to be destroyed after use
|
26
|
-
const
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
38
|
+
const tokenRequestSignedDPop = await withEphemeralKey(async ephimeralContext => {
|
39
|
+
return await createDPopToken({
|
40
|
+
htm: "POST",
|
41
|
+
htu: tokenUrl,
|
42
|
+
jti: `${uuid.v4()}`
|
43
|
+
}, ephimeralContext);
|
44
|
+
});
|
45
|
+
const signedWiaPoP = await createPopToken({
|
46
|
+
jti: `${uuid.v4()}`,
|
47
|
+
aud,
|
48
|
+
iss
|
49
|
+
}, wiaCryptoContext);
|
32
50
|
const requestBody = {
|
33
|
-
grant_type: "
|
51
|
+
grant_type: "authorization_code",
|
34
52
|
client_id: clientId,
|
35
53
|
code,
|
54
|
+
redirect_uri: redirectUri,
|
36
55
|
code_verifier: codeVerifier,
|
37
56
|
client_assertion_type: ASSERTION_TYPE,
|
38
|
-
client_assertion: walletInstanceAttestation
|
39
|
-
redirect_uri: walletProviderBaseUrl
|
57
|
+
client_assertion: walletInstanceAttestation + "~" + signedWiaPoP
|
40
58
|
};
|
41
|
-
|
42
|
-
|
59
|
+
const authorizationRequestFormBody = new URLSearchParams(requestBody);
|
60
|
+
const tokenRes = await appFetch(tokenUrl, {
|
43
61
|
method: "POST",
|
44
62
|
headers: {
|
45
63
|
"Content-Type": "application/x-www-form-urlencoded",
|
46
|
-
DPoP:
|
64
|
+
DPoP: tokenRequestSignedDPop
|
47
65
|
},
|
48
|
-
body:
|
49
|
-
}).then(hasStatus(200)).then(res => res.json()).then(body => (
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
66
|
+
body: authorizationRequestFormBody.toString()
|
67
|
+
}).then(hasStatus(200)).then(res => res.json()).then(body => TokenResponse.safeParse(body));
|
68
|
+
if (!tokenRes.success) {
|
69
|
+
throw new ValidationFailed(tokenRes.error.message);
|
70
|
+
}
|
71
|
+
return {
|
72
|
+
accessToken: tokenRes.data,
|
73
|
+
tokenRequestSignedDPop
|
74
|
+
};
|
54
75
|
};
|
55
76
|
//# sourceMappingURL=05-authorize-access.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["hasStatus","withEphemeralKey","createDPopToken","uuid","createPopToken","WalletInstanceAttestation","ASSERTION_TYPE","TokenResponse","ValidationFailed","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","ephimeralContext","htm","htu","jti","v4","signedWiaPoP","requestBody","grant_type","client_id","redirect_uri","code_verifier","client_assertion_type","client_assertion","authorizationRequestFormBody","URLSearchParams","tokenRes","method","headers","DPoP","body","toString","then","res","json","safeParse","success","error","message","accessToken","data"],"sourceRoot":"../../../../src","sources":["credential/issuance/05-authorize-access.ts"],"mappings":"AAAA,SAASA,SAAS,QAAkB,yBAAyB;AAG7D,SAASC,gBAAgB,QAAQ,2BAA2B;AAC5D,SAASC,eAAe,QAAQ,yBAAyB;AACzD,OAAOC,IAAI,MAAM,mBAAmB;AACpC,SAASC,cAAc,QAAQ,wBAAwB;AACvD,OAAO,KAAKC,yBAAyB,MAAM,mCAAmC;AAE9E,SAASC,cAAc,QAAQ,SAAS;AACxC,SAASC,aAAa,QAAQ,SAAS;AACvC,SAASC,gBAAgB,QAAQ,2BAA2B;AAgB5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAgC,GAAG,MAAAA,CA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MQ,4BAA4B,GAAG,IAAIC,eAAe,CAACR,WAAW,CAAC;EACrE,MAAMS,QAAQ,GAAG,MAAMpC,QAAQ,CAACkB,QAAQ,EAAE;IACxCmB,MAAM,EAAE,MAAM;IACdC,OAAO,EAAE;MACP,cAAc,EAAE,mCAAmC;MACnDC,IAAI,EAAEnB;IACR,CAAC;IACDoB,IAAI,EAAEN,4BAA4B,CAACO,QAAQ,CAAC;EAC9C,CAAC,CAAC,CACCC,IAAI,CAAC1D,SAAS,CAAC,GAAG,CAAC,CAAC,CACpB0D,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBF,IAAI,CAAEF,IAAI,IAAKjD,aAAa,CAACsD,SAAS,CAACL,IAAI,CAAC,CAAC;EAEhD,IAAI,CAACJ,QAAQ,CAACU,OAAO,EAAE;IACrB,MAAM,IAAItD,gBAAgB,CAAC4C,QAAQ,CAACW,KAAK,CAACC,OAAO,CAAC;EACpD;EAEA,OAAO;IAAEC,WAAW,EAAEb,QAAQ,CAACc,IAAI;IAAE9B;EAAuB,CAAC;AAC/D,CAAC"}
|
@@ -1,100 +1,75 @@
|
|
1
|
-
import * as z from "zod";
|
2
|
-
import uuid from "react-native-uuid";
|
3
1
|
import { SignJWT } from "@pagopa/io-react-native-jwt";
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
|
8
|
-
/**
|
9
|
-
* Return the signed jwt for nonce proof of possession
|
10
|
-
*/
|
2
|
+
import { hasStatus } from "../../../src/utils/misc";
|
3
|
+
import { ValidationFailed } from "../../../src/utils/errors";
|
4
|
+
import { CredentialResponse } from "./types";
|
11
5
|
export const createNonceProof = async (nonce, issuer, audience, ctx) => {
|
6
|
+
const jwk = await ctx.getPublicKey();
|
12
7
|
return new SignJWT(ctx).setPayload({
|
13
|
-
nonce
|
14
|
-
jwk: await ctx.getPublicKey()
|
8
|
+
nonce
|
15
9
|
}).setProtectedHeader({
|
16
|
-
|
17
|
-
|
10
|
+
typ: "openid4vci-proof+jwt",
|
11
|
+
jwk
|
12
|
+
}).setAudience(audience).setIssuer(issuer).setIssuedAt().setExpirationTime("5min").sign();
|
18
13
|
};
|
19
|
-
const CredentialEndpointResponse = z.object({
|
20
|
-
credential: z.string(),
|
21
|
-
format: SupportedCredentialFormat,
|
22
|
-
// nonce used to perform multiple credential requests
|
23
|
-
// re-using the same authorization profile
|
24
|
-
c_nonce: z.string(),
|
25
|
-
c_nonce_expires_in: z.number()
|
26
|
-
});
|
27
|
-
// Checks whether in the Entity confoguration at least one credential
|
28
|
-
// is defined for the given type and format
|
29
|
-
const isCredentialAvailable = (issuerConf, credentialType, credentialFormat) => issuerConf.openid_credential_issuer.credentials_supported.some(c => c.format === credentialFormat && c.credential_definition.type.includes(credentialType));
|
30
14
|
|
31
15
|
/**
|
32
|
-
*
|
33
|
-
*
|
34
|
-
*
|
35
|
-
*
|
36
|
-
*
|
37
|
-
* @param
|
38
|
-
* @param
|
39
|
-
* @param
|
40
|
-
* @param
|
41
|
-
* @param
|
16
|
+
* Obtains the credential from the issuer.
|
17
|
+
* The key pair of the credentialCryptoContext is used for Openid4vci proof JWT to be presented with the Access Token and the DPoP Proof JWT at the Credential Endpoint
|
18
|
+
* of the Credential Issuer to request the issuance of a credential linked to the public key contained in the JWT proof.
|
19
|
+
* The Openid4vci proof JWT incapsulates the nonce extracted from the token response from the {@link authorizeAccess} step.
|
20
|
+
* The credential request is sent to the Credential Endpoint of the Credential Issuer via HTTP POST with the type of the credential, its format, the access token and the JWT proof.
|
21
|
+
* @param issuerConf The issuer configuration returned by {@link evaluateIssuerTrust}
|
22
|
+
* @param accessToken The access token response returned by {@link authorizeAccess}
|
23
|
+
* @param clientId The client id returned by {@link startUserAuthorization}
|
24
|
+
* @param credentialDefinition The credential definition of the credential to be obtained returned by {@link startUserAuthorization}
|
25
|
+
* @param tokenRequestSignedDPop The DPoP signed token request returned by {@link authorizeAccess}
|
26
|
+
* @param context.credentialCryptoContext The crypto context used to obtain the credential
|
42
27
|
* @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
|
43
|
-
* @returns The
|
28
|
+
* @returns The credential response containing the credential
|
44
29
|
*/
|
45
|
-
export const obtainCredential = async (issuerConf, accessToken,
|
30
|
+
export const obtainCredential = async (issuerConf, accessToken, clientId, credentialDefinition, tokenRequestSignedDPop, context) => {
|
46
31
|
const {
|
47
32
|
credentialCryptoContext,
|
48
|
-
walletProviderBaseUrl,
|
49
33
|
appFetch = fetch
|
50
34
|
} = context;
|
51
|
-
if (!isCredentialAvailable(issuerConf, credentialType, credentialFormat)) {
|
52
|
-
throw new Error(`The Issuer provides no credential for type ${credentialType} and format ${credentialFormat}`);
|
53
|
-
}
|
54
35
|
const credentialUrl = issuerConf.openid_credential_issuer.credential_endpoint;
|
55
36
|
|
56
|
-
/**
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
jti: `${uuid.v4()}`
|
63
|
-
}, credentialCryptoContext);
|
37
|
+
/**
|
38
|
+
* JWT proof token to bind the request nonce to the key that will bind the holder User with the Credential
|
39
|
+
* This is presented along with the access token to the Credential Endpoint as proof of possession of the private key used to sign the Access Token.
|
40
|
+
* @see https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html#name-proof-types
|
41
|
+
*/
|
42
|
+
const signedNonceProof = await createNonceProof(accessToken.c_nonce, clientId, credentialUrl, credentialCryptoContext);
|
64
43
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
44
|
+
// Validation of accessTokenResponse.authorization_details if contain credentialDefinition
|
45
|
+
const constainsCredentialDefinition = accessToken.authorization_details.some(c => c.credential_configuration_id === credentialDefinition.credential_configuration_id && c.format === credentialDefinition.format && c.type === credentialDefinition.type);
|
46
|
+
if (!constainsCredentialDefinition) {
|
47
|
+
throw new ValidationFailed("The access token response does not contain the requested credential");
|
48
|
+
}
|
69
49
|
|
70
50
|
/** The credential request body */
|
71
|
-
const
|
72
|
-
credential_definition:
|
73
|
-
type: [
|
74
|
-
}
|
75
|
-
format:
|
76
|
-
proof:
|
51
|
+
const credentialRequestFormBody = {
|
52
|
+
credential_definition: {
|
53
|
+
type: [credentialDefinition.credential_configuration_id]
|
54
|
+
},
|
55
|
+
format: credentialDefinition.format,
|
56
|
+
proof: {
|
77
57
|
jwt: signedNonceProof,
|
78
58
|
proof_type: "jwt"
|
79
|
-
}
|
80
|
-
}
|
81
|
-
const {
|
82
|
-
credential,
|
83
|
-
format,
|
84
|
-
c_nonce
|
85
|
-
} = await appFetch(credentialUrl, {
|
59
|
+
}
|
60
|
+
};
|
61
|
+
const credentialRes = await appFetch(credentialUrl, {
|
86
62
|
method: "POST",
|
87
63
|
headers: {
|
88
|
-
"Content-Type": "application/
|
89
|
-
DPoP:
|
90
|
-
Authorization: accessToken
|
64
|
+
"Content-Type": "application/json",
|
65
|
+
DPoP: tokenRequestSignedDPop,
|
66
|
+
Authorization: `${accessToken.token_type} ${accessToken.access_token}`
|
91
67
|
},
|
92
|
-
body:
|
93
|
-
}).then(hasStatus(200)).then(res => res.json()).then(
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
};
|
68
|
+
body: JSON.stringify(credentialRequestFormBody)
|
69
|
+
}).then(hasStatus(200)).then(res => res.json()).then(body => CredentialResponse.safeParse(body));
|
70
|
+
if (!credentialRes.success) {
|
71
|
+
throw new ValidationFailed(credentialRes.error.message);
|
72
|
+
}
|
73
|
+
return credentialRes.data;
|
99
74
|
};
|
100
75
|
//# sourceMappingURL=06-obtain-credential.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["SignJWT","hasStatus","ValidationFailed","CredentialResponse","createNonceProof","nonce","issuer","audience","ctx","jwk","getPublicKey","setPayload","setProtectedHeader","typ","setAudience","setIssuer","setIssuedAt","setExpirationTime","sign","obtainCredential","issuerConf","accessToken","clientId","credentialDefinition","tokenRequestSignedDPop","context","credentialCryptoContext","appFetch","fetch","credentialUrl","openid_credential_issuer","credential_endpoint","signedNonceProof","c_nonce","constainsCredentialDefinition","authorization_details","some","c","credential_configuration_id","format","type","credentialRequestFormBody","credential_definition","proof","jwt","proof_type","credentialRes","method","headers","DPoP","Authorization","token_type","access_token","body","JSON","stringify","then","res","json","safeParse","success","error","message","data"],"sourceRoot":"../../../../src","sources":["credential/issuance/06-obtain-credential.ts"],"mappings":"AAAA,SAASA,OAAO,QAA4B,6BAA6B;AAGzE,SAASC,SAAS,QAAkB,yBAAyB;AAE7D,SAASC,gBAAgB,QAAQ,2BAA2B;AAC5D,SAASC,kBAAkB,QAAQ,SAAS;AAc5C,OAAO,MAAMC,gBAAgB,GAAG,MAAAA,CAC9BC,KAAa,EACbC,MAAc,EACdC,QAAgB,EAChBC,GAAkB,KACE;EACpB,MAAMC,GAAG,GAAG,MAAMD,GAAG,CAACE,YAAY,CAAC,CAAC;EACpC,OAAO,IAAIV,OAAO,CAACQ,GAAG,CAAC,CACpBG,UAAU,CAAC;IACVN;EACF,CAAC,CAAC,CACDO,kBAAkB,CAAC;IAClBC,GAAG,EAAE,sBAAsB;IAC3BJ;EACF,CAAC,CAAC,CACDK,WAAW,CAACP,QAAQ,CAAC,CACrBQ,SAAS,CAACT,MAAM,CAAC,CACjBU,WAAW,CAAC,CAAC,CACbC,iBAAiB,CAAC,MAAM,CAAC,CACzBC,IAAI,CAAC,CAAC;AACX,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,gBAAkC,GAAG,MAAAA,CAChDC,UAAU,EACVC,WAAW,EACXC,QAAQ,EACRC,oBAAoB,EACpBC,sBAAsB,EACtBC,OAAO,KACJ;EACH,MAAM;IAAEC,uBAAuB;IAAEC,QAAQ,GAAGC;EAAM,CAAC,GAAGH,OAAO;EAE7D,MAAMI,aAAa,GAAGT,UAAU,CAACU,wBAAwB,CAACC,mBAAmB;;EAE7E;AACF;AACA;AACA;A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