@pagopa/io-react-native-wallet 0.15.3 → 0.15.4
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/credential/issuance/05-authorize-access.js +13 -9
- package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -1
- package/lib/commonjs/credential/issuance/06-obtain-credential.js +13 -1
- package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
- package/lib/commonjs/credential/issuance/const.js +3 -1
- package/lib/commonjs/credential/issuance/const.js.map +1 -1
- package/lib/module/credential/issuance/05-authorize-access.js +15 -11
- package/lib/module/credential/issuance/05-authorize-access.js.map +1 -1
- package/lib/module/credential/issuance/06-obtain-credential.js +13 -2
- package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
- package/lib/module/credential/issuance/const.js +1 -0
- package/lib/module/credential/issuance/const.js.map +1 -1
- package/lib/typescript/credential/issuance/05-authorize-access.d.ts +1 -1
- package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/06-obtain-credential.d.ts +1 -1
- package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/const.d.ts +1 -0
- package/lib/typescript/credential/issuance/const.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/credential/issuance/05-authorize-access.ts +21 -16
- package/src/credential/issuance/06-obtain-credential.ts +23 -3
- package/src/credential/issuance/const.ts +2 -0
@@ -13,6 +13,7 @@ var WalletInstanceAttestation = _interopRequireWildcard(require("../../wallet-in
|
|
13
13
|
var _const = require("./const");
|
14
14
|
var _types = require("./types");
|
15
15
|
var _errors = require("../../utils/errors");
|
16
|
+
var _ioReactNativeCrypto = require("@pagopa/io-react-native-crypto");
|
16
17
|
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
18
|
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; }
|
18
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -43,14 +44,17 @@ const authorizeAccess = async (issuerConf, code, clientId, redirectUri, codeVeri
|
|
43
44
|
const aud = `${parUrl.protocol}//${parUrl.hostname}`;
|
44
45
|
const iss = WalletInstanceAttestation.decode(walletInstanceAttestation).payload.cnf.jwk.kid;
|
45
46
|
const tokenUrl = issuerConf.oauth_authorization_server.token_endpoint;
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
try {
|
48
|
+
await (0, _ioReactNativeCrypto.generate)(_const.DPOP_KET_TAG);
|
49
|
+
} catch {
|
50
|
+
console.log("DPoP key already exist");
|
51
|
+
}
|
52
|
+
const dPoPContext = (0, _crypto.createCryptoContextFor)(_const.DPOP_KET_TAG);
|
53
|
+
const tokenRequestSignedDPop = await (0, _dpop.createDPopToken)({
|
54
|
+
htm: "POST",
|
55
|
+
htu: tokenUrl,
|
56
|
+
jti: `${_reactNativeUuid.default.v4()}`
|
57
|
+
}, dPoPContext);
|
54
58
|
const signedWiaPoP = await (0, _pop.createPopToken)({
|
55
59
|
jti: `${_reactNativeUuid.default.v4()}`,
|
56
60
|
aud,
|
@@ -79,7 +83,7 @@ const authorizeAccess = async (issuerConf, code, clientId, redirectUri, codeVeri
|
|
79
83
|
}
|
80
84
|
return {
|
81
85
|
accessToken: tokenRes.data,
|
82
|
-
|
86
|
+
dPoPContext
|
83
87
|
};
|
84
88
|
};
|
85
89
|
exports.authorizeAccess = authorizeAccess;
|
@@ -1 +1 @@
|
|
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","
|
1
|
+
{"version":3,"names":["_misc","require","_crypto","_dpop","_reactNativeUuid","_interopRequireDefault","_pop","WalletInstanceAttestation","_interopRequireWildcard","_const","_types","_errors","_ioReactNativeCrypto","_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","generate","DPOP_KET_TAG","console","log","dPoPContext","createCryptoContextFor","tokenRequestSignedDPop","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"],"sourceRoot":"../../../../src","sources":["credential/issuance/05-authorize-access.ts"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAGA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,IAAA,GAAAL,OAAA;AACA,IAAAM,yBAAA,GAAAC,uBAAA,CAAAP,OAAA;AAEA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,OAAA,GAAAV,OAAA;AAEA,IAAAW,oBAAA,GAAAX,OAAA;AAA0D,SAAAY,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,SAAAN,wBAAAU,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,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IAAI,CAAC,CAAC;EAEhD,IAAI,CAACJ,QAAQ,CAACY,OAAO,EAAE;IACrB,MAAM,IAAIC,wBAAgB,CAACb,QAAQ,CAACc,KAAK,CAACC,OAAO,CAAC;EACpD;EAEA,OAAO;IAAEC,WAAW,EAAEhB,QAAQ,CAACiB,IAAI;IAAEtC;EAAY,CAAC;AACpD,CAAC;AAACuC,OAAA,CAAAtE,eAAA,GAAAA,eAAA"}
|
@@ -8,6 +8,11 @@ var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
|
|
8
8
|
var _misc = require("../../utils/misc");
|
9
9
|
var _errors = require("../../utils/errors");
|
10
10
|
var _types = require("./types");
|
11
|
+
var _dpop = require("../../utils/dpop");
|
12
|
+
var _reactNativeUuid = _interopRequireDefault(require("react-native-uuid"));
|
13
|
+
var _ioReactNativeCrypto = require("@pagopa/io-react-native-crypto");
|
14
|
+
var _const = require("./const");
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
16
|
const createNonceProof = async (nonce, issuer, audience, ctx) => {
|
12
17
|
const jwk = await ctx.getPublicKey();
|
13
18
|
return new _ioReactNativeJwt.SignJWT(ctx).setPayload({
|
@@ -34,7 +39,7 @@ const createNonceProof = async (nonce, issuer, audience, ctx) => {
|
|
34
39
|
* @returns The credential response containing the credential
|
35
40
|
*/
|
36
41
|
exports.createNonceProof = createNonceProof;
|
37
|
-
const obtainCredential = async (issuerConf, accessToken, clientId, credentialDefinition,
|
42
|
+
const obtainCredential = async (issuerConf, accessToken, clientId, credentialDefinition, dPoPContext, context) => {
|
38
43
|
const {
|
39
44
|
credentialCryptoContext,
|
40
45
|
appFetch = fetch
|
@@ -65,6 +70,13 @@ const obtainCredential = async (issuerConf, accessToken, clientId, credentialDef
|
|
65
70
|
proof_type: "jwt"
|
66
71
|
}
|
67
72
|
};
|
73
|
+
const tokenRequestSignedDPop = await await (0, _dpop.createDPopToken)({
|
74
|
+
htm: "POST",
|
75
|
+
htu: credentialUrl,
|
76
|
+
jti: `${_reactNativeUuid.default.v4()}`,
|
77
|
+
ath: await (0, _ioReactNativeJwt.sha256ToBase64)(accessToken.access_token)
|
78
|
+
}, dPoPContext);
|
79
|
+
await (0, _ioReactNativeCrypto.deleteKey)(_const.DPOP_KET_TAG);
|
68
80
|
const credentialRes = await appFetch(credentialUrl, {
|
69
81
|
method: "POST",
|
70
82
|
headers: {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_ioReactNativeJwt","require","_misc","_errors","_types","createNonceProof","nonce","issuer","audience","ctx","jwk","getPublicKey","SignJWT","setPayload","setProtectedHeader","typ","setAudience","setIssuer","setIssuedAt","setExpirationTime","sign","exports","obtainCredential","issuerConf","accessToken","clientId","credentialDefinition","
|
1
|
+
{"version":3,"names":["_ioReactNativeJwt","require","_misc","_errors","_types","_dpop","_reactNativeUuid","_interopRequireDefault","_ioReactNativeCrypto","_const","obj","__esModule","default","createNonceProof","nonce","issuer","audience","ctx","jwk","getPublicKey","SignJWT","setPayload","setProtectedHeader","typ","setAudience","setIssuer","setIssuedAt","setExpirationTime","sign","exports","obtainCredential","issuerConf","accessToken","clientId","credentialDefinition","dPoPContext","context","credentialCryptoContext","appFetch","fetch","credentialUrl","openid_credential_issuer","credential_endpoint","signedNonceProof","c_nonce","constainsCredentialDefinition","authorization_details","some","c","credential_configuration_id","format","type","ValidationFailed","credentialRequestFormBody","credential_definition","proof","jwt","proof_type","tokenRequestSignedDPop","createDPopToken","htm","htu","jti","uuid","v4","ath","sha256ToBase64","access_token","deleteKey","DPOP_KET_TAG","credentialRes","method","headers","DPoP","Authorization","token_type","body","JSON","stringify","then","hasStatus","res","json","CredentialResponse","safeParse","success","error","message","data"],"sourceRoot":"../../../../src","sources":["credential/issuance/06-obtain-credential.ts"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AAOA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,M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CAAC,CAAC,CACC0B,IAAI,CAAC,IAAAC,eAAS,EAAC,GAAG,CAAC,CAAC,CACpBD,IAAI,CAAEE,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBH,IAAI,CAAEH,IAAI,IAAKO,yBAAkB,CAACC,SAAS,CAACR,IAAI,CAAC,CAAC;EAErD,IAAI,CAACN,aAAa,CAACe,OAAO,EAAE;IAC1B,MAAM,IAAIjC,wBAAgB,CAACkB,aAAa,CAACgB,KAAK,CAACC,OAAO,CAAC;EACzD;EAEA,OAAOjB,aAAa,CAACkB,IAAI;AAC3B,CAAC;AAAC3D,OAAA,CAAAC,gBAAA,GAAAA,gBAAA"}
|
@@ -3,12 +3,14 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.SupportedCredentialFormat = exports.ASSERTION_TYPE = void 0;
|
6
|
+
exports.SupportedCredentialFormat = exports.DPOP_KET_TAG = exports.ASSERTION_TYPE = void 0;
|
7
7
|
var z = _interopRequireWildcard(require("zod"));
|
8
8
|
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); }
|
9
9
|
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
10
|
const ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-client-attestation";
|
11
11
|
exports.ASSERTION_TYPE = ASSERTION_TYPE;
|
12
|
+
const DPOP_KET_TAG = `dpop`;
|
13
|
+
exports.DPOP_KET_TAG = DPOP_KET_TAG;
|
12
14
|
const SupportedCredentialFormat = z.union([z.literal("vc+sd-jwt"), z.literal("vc+mdoc-cbor")]);
|
13
15
|
exports.SupportedCredentialFormat = SupportedCredentialFormat;
|
14
16
|
//# sourceMappingURL=const.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["z","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ASSERTION_TYPE","exports","SupportedCredentialFormat","union","literal"],"sourceRoot":"../../../../src","sources":["credential/issuance/const.ts"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAyB,SAAAC,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,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA;AAClB,MAAMW,cAAc,GACzB,oEAAoE;AAACC,OAAA,CAAAD,cAAA,GAAAA,cAAA;
|
1
|
+
{"version":3,"names":["z","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ASSERTION_TYPE","exports","DPOP_KET_TAG","SupportedCredentialFormat","union","literal"],"sourceRoot":"../../../../src","sources":["credential/issuance/const.ts"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAyB,SAAAC,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,SAAAH,wBAAAO,GAAA,EAA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1,12 +1,13 @@
|
|
1
1
|
import { hasStatus } from "../../utils/misc";
|
2
|
-
import {
|
2
|
+
import { createCryptoContextFor } from "../../utils/crypto";
|
3
3
|
import { createDPopToken } from "../../utils/dpop";
|
4
4
|
import uuid from "react-native-uuid";
|
5
5
|
import { createPopToken } from "../../utils/pop";
|
6
6
|
import * as WalletInstanceAttestation from "../../wallet-instance-attestation";
|
7
|
-
import { ASSERTION_TYPE } from "./const";
|
7
|
+
import { ASSERTION_TYPE, DPOP_KET_TAG } from "./const";
|
8
8
|
import { TokenResponse } from "./types";
|
9
9
|
import { ValidationFailed } from "../../utils/errors";
|
10
|
+
import { generate } from "@pagopa/io-react-native-crypto";
|
10
11
|
/**
|
11
12
|
* Creates and sends the DPoP Proof JWT to be presented with the authorization code to the /token endpoint of the authorization server
|
12
13
|
* for requesting the issuance of an access token bound to the public key of the Wallet Instance contained within the DPoP.
|
@@ -34,14 +35,17 @@ export const authorizeAccess = async (issuerConf, code, clientId, redirectUri, c
|
|
34
35
|
const aud = `${parUrl.protocol}//${parUrl.hostname}`;
|
35
36
|
const iss = WalletInstanceAttestation.decode(walletInstanceAttestation).payload.cnf.jwk.kid;
|
36
37
|
const tokenUrl = issuerConf.oauth_authorization_server.token_endpoint;
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
try {
|
39
|
+
await generate(DPOP_KET_TAG);
|
40
|
+
} catch {
|
41
|
+
console.log("DPoP key already exist");
|
42
|
+
}
|
43
|
+
const dPoPContext = createCryptoContextFor(DPOP_KET_TAG);
|
44
|
+
const tokenRequestSignedDPop = await createDPopToken({
|
45
|
+
htm: "POST",
|
46
|
+
htu: tokenUrl,
|
47
|
+
jti: `${uuid.v4()}`
|
48
|
+
}, dPoPContext);
|
45
49
|
const signedWiaPoP = await createPopToken({
|
46
50
|
jti: `${uuid.v4()}`,
|
47
51
|
aud,
|
@@ -70,7 +74,7 @@ export const authorizeAccess = async (issuerConf, code, clientId, redirectUri, c
|
|
70
74
|
}
|
71
75
|
return {
|
72
76
|
accessToken: tokenRes.data,
|
73
|
-
|
77
|
+
dPoPContext
|
74
78
|
};
|
75
79
|
};
|
76
80
|
//# sourceMappingURL=05-authorize-access.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["hasStatus","
|
1
|
+
{"version":3,"names":["hasStatus","createCryptoContextFor","createDPopToken","uuid","createPopToken","WalletInstanceAttestation","ASSERTION_TYPE","DPOP_KET_TAG","TokenResponse","ValidationFailed","generate","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","console","log","dPoPContext","tokenRequestSignedDPop","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,kBAAkB;AAGtD,SAASC,sBAAsB,QAAQ,oBAAoB;AAC3D,SAASC,eAAe,QAAQ,kBAAkB;AAClD,OAAOC,IAAI,MAAM,mBAAmB;AACpC,SAASC,cAAc,QAAQ,iBAAiB;AAChD,OAAO,KAAKC,yBAAyB,MAAM,mCAAmC;AAE9E,SAASC,cAAc,EAAEC,YAAY,QAAQ,SAAS;AACtD,SAASC,aAAa,QAAQ,SAAS;AACvC,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,SAASC,QAAQ,QAAQ,gCAAgC;AAezD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAgC,GAA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AEnC,YAAY;IAC3BoC,qBAAqB,EAAE9C,cAAc;IACrC+C,gBAAgB,EAAEjC,yBAAyB,GAAG,GAAG,GAAG0B;EACtD,CAAC;EAED,MAAMQ,4BAA4B,GAAG,IAAIC,eAAe,CAACR,WAAW,CAAC;EACrE,MAAMS,QAAQ,GAAG,MAAMtC,QAAQ,CAACkB,QAAQ,EAAE;IACxCqB,MAAM,EAAE,MAAM;IACdC,OAAO,EAAE;MACP,cAAc,EAAE,mCAAmC;MACnDC,IAAI,EAAElB;IACR,CAAC;IACDmB,IAAI,EAAEN,4BAA4B,CAACO,QAAQ,CAAC;EAC9C,CAAC,CAAC,CACCC,IAAI,CAAC9D,SAAS,CAAC,GAAG,CAAC,CAAC,CACpB8D,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBF,IAAI,CAAEF,IAAI,IAAKpD,aAAa,CAACyD,SAAS,CAACL,IAAI,CAAC,CAAC;EAEhD,IAAI,CAACJ,QAAQ,CAACU,OAAO,EAAE;IACrB,MAAM,IAAIzD,gBAAgB,CAAC+C,QAAQ,CAACW,KAAK,CAACC,OAAO,CAAC;EACpD;EAEA,OAAO;IAAEC,WAAW,EAAEb,QAAQ,CAACc,IAAI;IAAE9B;EAAY,CAAC;AACpD,CAAC"}
|
@@ -1,7 +1,11 @@
|
|
1
|
-
import { SignJWT } from "@pagopa/io-react-native-jwt";
|
1
|
+
import { sha256ToBase64, SignJWT } from "@pagopa/io-react-native-jwt";
|
2
2
|
import { hasStatus } from "../../utils/misc";
|
3
3
|
import { ValidationFailed } from "../../utils/errors";
|
4
4
|
import { CredentialResponse } from "./types";
|
5
|
+
import { createDPopToken } from "../../utils/dpop";
|
6
|
+
import uuid from "react-native-uuid";
|
7
|
+
import { deleteKey } from "@pagopa/io-react-native-crypto";
|
8
|
+
import { DPOP_KET_TAG } from "./const";
|
5
9
|
export const createNonceProof = async (nonce, issuer, audience, ctx) => {
|
6
10
|
const jwk = await ctx.getPublicKey();
|
7
11
|
return new SignJWT(ctx).setPayload({
|
@@ -27,7 +31,7 @@ export const createNonceProof = async (nonce, issuer, audience, ctx) => {
|
|
27
31
|
* @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
|
28
32
|
* @returns The credential response containing the credential
|
29
33
|
*/
|
30
|
-
export const obtainCredential = async (issuerConf, accessToken, clientId, credentialDefinition,
|
34
|
+
export const obtainCredential = async (issuerConf, accessToken, clientId, credentialDefinition, dPoPContext, context) => {
|
31
35
|
const {
|
32
36
|
credentialCryptoContext,
|
33
37
|
appFetch = fetch
|
@@ -58,6 +62,13 @@ export const obtainCredential = async (issuerConf, accessToken, clientId, creden
|
|
58
62
|
proof_type: "jwt"
|
59
63
|
}
|
60
64
|
};
|
65
|
+
const tokenRequestSignedDPop = await await createDPopToken({
|
66
|
+
htm: "POST",
|
67
|
+
htu: credentialUrl,
|
68
|
+
jti: `${uuid.v4()}`,
|
69
|
+
ath: await sha256ToBase64(accessToken.access_token)
|
70
|
+
}, dPoPContext);
|
71
|
+
await deleteKey(DPOP_KET_TAG);
|
61
72
|
const credentialRes = await appFetch(credentialUrl, {
|
62
73
|
method: "POST",
|
63
74
|
headers: {
|
@@ -1 +1 @@
|
|
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","
|
1
|
+
{"version":3,"names":["sha256ToBase64","SignJWT","hasStatus","ValidationFailed","CredentialResponse","createDPopToken","uuid","deleteKey","DPOP_KET_TAG","createNonceProof","nonce","issuer","audience","ctx","jwk","getPublicKey","setPayload","setProtectedHeader","typ","setAudience","setIssuer","setIssuedAt","setExpirationTime","sign","obtainCredential","issuerConf","accessToken","clientId","credentialDefinition","dPoPContext","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","tokenRequestSignedDPop","htm","htu","jti","v4","ath","access_token","credentialRes","method","headers","DPoP","Authorization","token_type","body","JSON","stringify","then","res","json","safeParse","success","error","message","data"],"sourceRoot":"../../../../src","sources":["credential/issuance/06-obtain-credential.ts"],"mappings":"AAAA,SACEA,cAAc,EACdC,OAAO,QAEF,6BAA6B;AAGpC,SAASC,SAAS,QAAkB,kBAAkB;AAEtD,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,kBAAkB,QAAQ,SAAS;AAE5C,SAASC,eAAe,QAAQ,kBAAkB;AAClD,OAAOC,IAAI,MAAM,mBAAmB;AACpC,SAASC,SAAS,QAAQ,gCAAgC;AAC1D,SAASC,YAAY,QAAQ,SAAS;AActC,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,IAAId,OAAO,CAACY,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,WAAW,EACXC,OAAO,KACJ;EACH,MA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AAE,MAAM;IACdC,OAAO,EAAE;MACP,cAAc,EAAE,kBAAkB;MAClCC,IAAI,EAAEV,sBAAsB;MAC5BW,aAAa,EAAG,GAAEpC,WAAW,CAACqC,UAAW,IAAGrC,WAAW,CAAC+B,YAAa;IACvE,CAAC;IACDO,IAAI,EAAEC,IAAI,CAACC,SAAS,CAACpB,yBAAyB;EAChD,CAAC,CAAC,CACCqB,IAAI,CAACjE,SAAS,CAAC,GAAG,CAAC,CAAC,CACpBiE,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBF,IAAI,CAAEH,IAAI,IAAK5D,kBAAkB,CAACkE,SAAS,CAACN,IAAI,CAAC,CAAC;EAErD,IAAI,CAACN,aAAa,CAACa,OAAO,EAAE;IAC1B,MAAM,IAAIpE,gBAAgB,CAACuD,aAAa,CAACc,KAAK,CAACC,OAAO,CAAC;EACzD;EAEA,OAAOf,aAAa,CAACgB,IAAI;AAC3B,CAAC"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import * as z from "zod";
|
2
2
|
export const ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-client-attestation";
|
3
|
+
export const DPOP_KET_TAG = `dpop`;
|
3
4
|
export const SupportedCredentialFormat = z.union([z.literal("vc+sd-jwt"), z.literal("vc+mdoc-cbor")]);
|
4
5
|
//# sourceMappingURL=const.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["z","ASSERTION_TYPE","SupportedCredentialFormat","union","literal"],"sourceRoot":"../../../../src","sources":["credential/issuance/const.ts"],"mappings":"AAAA,OAAO,KAAKA,CAAC,MAAM,KAAK;AACxB,OAAO,MAAMC,cAAc,GACzB,oEAAoE;
|
1
|
+
{"version":3,"names":["z","ASSERTION_TYPE","DPOP_KET_TAG","SupportedCredentialFormat","union","literal"],"sourceRoot":"../../../../src","sources":["credential/issuance/const.ts"],"mappings":"AAAA,OAAO,KAAKA,CAAC,MAAM,KAAK;AACxB,OAAO,MAAMC,cAAc,GACzB,oEAAoE;AAEtE,OAAO,MAAMC,YAAY,GAAI,MAAK;AAKlC,OAAO,MAAMC,yBAAyB,GAAGH,CAAC,CAACI,KAAK,CAAC,CAC/CJ,CAAC,CAACK,OAAO,CAAC,WAAW,CAAC,EACtBL,CAAC,CAACK,OAAO,CAAC,cAAc,CAAC,CAC1B,CAAC"}
|
@@ -10,7 +10,7 @@ export type AuthorizeAccess = (issuerConf: Out<EvaluateIssuerTrust>["issuerConf"
|
|
10
10
|
wiaCryptoContext: CryptoContext;
|
11
11
|
}) => Promise<{
|
12
12
|
accessToken: TokenResponse;
|
13
|
-
|
13
|
+
dPoPContext: CryptoContext;
|
14
14
|
}>;
|
15
15
|
/**
|
16
16
|
* Creates and sends the DPoP Proof JWT to be presented with the authorization code to the /token endpoint of the authorization server
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"05-authorize-access.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/05-authorize-access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAM5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,KAAK,EAAE,sCAAsC,EAAE,MAAM,kCAAkC,CAAC;
|
1
|
+
{"version":3,"file":"05-authorize-access.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/05-authorize-access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAM5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,KAAK,EAAE,sCAAsC,EAAE,MAAM,kCAAkC,CAAC;AAG/F,MAAM,MAAM,eAAe,GAAG,CAC5B,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,IAAI,EAAE,GAAG,CAAC,sCAAsC,CAAC,CAAC,MAAM,CAAC,EACzD,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,UAAU,CAAC,EACjD,YAAY,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,cAAc,CAAC,EACzD,OAAO,EAAE;IACP,yBAAyB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAChC,gBAAgB,EAAE,aAAa,CAAC;CACjC,KACE,OAAO,CAAC;IAAE,WAAW,EAAE,aAAa,CAAC;IAAC,WAAW,EAAE,aAAa,CAAA;CAAE,CAAC,CAAC;AAEzE;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,EAAE,eA6E7B,CAAC"}
|
@@ -4,7 +4,7 @@ import type { EvaluateIssuerTrust } from "./02-evaluate-issuer-trust";
|
|
4
4
|
import { type Out } from "../../utils/misc";
|
5
5
|
import type { StartUserAuthorization } from "./03-start-user-authorization";
|
6
6
|
import { CredentialResponse } from "./types";
|
7
|
-
export type ObtainCredential = (issuerConf: Out<EvaluateIssuerTrust>["issuerConf"], accessToken: Out<AuthorizeAccess>["accessToken"], clientId: Out<StartUserAuthorization>["clientId"], credentialDefinition: Out<StartUserAuthorization>["credentialDefinition"],
|
7
|
+
export type ObtainCredential = (issuerConf: Out<EvaluateIssuerTrust>["issuerConf"], accessToken: Out<AuthorizeAccess>["accessToken"], clientId: Out<StartUserAuthorization>["clientId"], credentialDefinition: Out<StartUserAuthorization>["credentialDefinition"], dPoPContext: CryptoContext, context: {
|
8
8
|
credentialCryptoContext: CryptoContext;
|
9
9
|
appFetch?: GlobalFetch["fetch"];
|
10
10
|
}) => Promise<CredentialResponse>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"06-obtain-credential.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/06-obtain-credential.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"06-obtain-credential.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/06-obtain-credential.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAO7C,MAAM,MAAM,gBAAgB,GAAG,CAC7B,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,WAAW,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC,aAAa,CAAC,EAChD,QAAQ,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,UAAU,CAAC,EACjD,oBAAoB,EAAE,GAAG,CAAC,sBAAsB,CAAC,CAAC,sBAAsB,CAAC,EACzE,WAAW,EAAE,aAAa,EAC1B,OAAO,EAAE;IACP,uBAAuB,EAAE,aAAa,CAAC;IACvC,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CACjC,KACE,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEjC,eAAO,MAAM,gBAAgB,UACpB,MAAM,UACL,MAAM,YACJ,MAAM,OACX,aAAa,KACjB,QAAQ,MAAM,CAehB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBAgF9B,CAAC"}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import * as z from "zod";
|
2
2
|
export declare const ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-client-attestation";
|
3
|
+
export declare const DPOP_KET_TAG = "dpop";
|
3
4
|
export type SupportedCredentialFormat = z.infer<typeof SupportedCredentialFormat>;
|
4
5
|
export declare const SupportedCredentialFormat: z.ZodUnion<[z.ZodLiteral<"vc+sd-jwt">, z.ZodLiteral<"vc+mdoc-cbor">]>;
|
5
6
|
//# sourceMappingURL=const.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/const.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,eAAO,MAAM,cAAc,uEAC2C,CAAC;AAEvE,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,yBAAyB,CACjC,CAAC;AACF,eAAO,MAAM,yBAAyB,uEAGpC,CAAC"}
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/const.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,eAAO,MAAM,cAAc,uEAC2C,CAAC;AAEvE,eAAO,MAAM,YAAY,SAAS,CAAC;AAEnC,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,yBAAyB,CACjC,CAAC;AACF,eAAO,MAAM,yBAAyB,uEAGpC,CAAC"}
|
package/package.json
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
import { hasStatus, type Out } from "../../utils/misc";
|
2
2
|
import type { EvaluateIssuerTrust } from "./02-evaluate-issuer-trust";
|
3
3
|
import type { StartUserAuthorization } from "./03-start-user-authorization";
|
4
|
-
import {
|
4
|
+
import { createCryptoContextFor } from "../../utils/crypto";
|
5
5
|
import { createDPopToken } from "../../utils/dpop";
|
6
6
|
import uuid from "react-native-uuid";
|
7
7
|
import { createPopToken } from "../../utils/pop";
|
8
8
|
import * as WalletInstanceAttestation from "../../wallet-instance-attestation";
|
9
9
|
import type { CryptoContext } from "@pagopa/io-react-native-jwt";
|
10
|
-
import { ASSERTION_TYPE } from "./const";
|
10
|
+
import { ASSERTION_TYPE, DPOP_KET_TAG } from "./const";
|
11
11
|
import { TokenResponse } from "./types";
|
12
12
|
import { ValidationFailed } from "../../utils/errors";
|
13
13
|
import type { CompleteUserAuthorizationWithQueryMode } from "./04-complete-user-authorization";
|
14
|
+
import { generate } from "@pagopa/io-react-native-crypto";
|
14
15
|
|
15
16
|
export type AuthorizeAccess = (
|
16
17
|
issuerConf: Out<EvaluateIssuerTrust>["issuerConf"],
|
@@ -23,7 +24,7 @@ export type AuthorizeAccess = (
|
|
23
24
|
appFetch?: GlobalFetch["fetch"];
|
24
25
|
wiaCryptoContext: CryptoContext;
|
25
26
|
}
|
26
|
-
) => Promise<{ accessToken: TokenResponse;
|
27
|
+
) => Promise<{ accessToken: TokenResponse; dPoPContext: CryptoContext }>;
|
27
28
|
|
28
29
|
/**
|
29
30
|
* Creates and sends the DPoP Proof JWT to be presented with the authorization code to the /token endpoint of the authorization server
|
@@ -63,18 +64,22 @@ export const authorizeAccess: AuthorizeAccess = async (
|
|
63
64
|
.payload.cnf.jwk.kid;
|
64
65
|
|
65
66
|
const tokenUrl = issuerConf.oauth_authorization_server.token_endpoint;
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
67
|
+
|
68
|
+
try {
|
69
|
+
await generate(DPOP_KET_TAG);
|
70
|
+
} catch {
|
71
|
+
console.log("DPoP key already exist");
|
72
|
+
}
|
73
|
+
|
74
|
+
const dPoPContext = createCryptoContextFor(DPOP_KET_TAG);
|
75
|
+
|
76
|
+
const tokenRequestSignedDPop = await createDPopToken(
|
77
|
+
{
|
78
|
+
htm: "POST",
|
79
|
+
htu: tokenUrl,
|
80
|
+
jti: `${uuid.v4()}`,
|
81
|
+
},
|
82
|
+
dPoPContext
|
78
83
|
);
|
79
84
|
|
80
85
|
const signedWiaPoP = await createPopToken(
|
@@ -113,5 +118,5 @@ export const authorizeAccess: AuthorizeAccess = async (
|
|
113
118
|
throw new ValidationFailed(tokenRes.error.message);
|
114
119
|
}
|
115
120
|
|
116
|
-
return { accessToken: tokenRes.data,
|
121
|
+
return { accessToken: tokenRes.data, dPoPContext };
|
117
122
|
};
|
@@ -1,4 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
sha256ToBase64,
|
3
|
+
SignJWT,
|
4
|
+
type CryptoContext,
|
5
|
+
} from "@pagopa/io-react-native-jwt";
|
2
6
|
import type { AuthorizeAccess } from "./05-authorize-access";
|
3
7
|
import type { EvaluateIssuerTrust } from "./02-evaluate-issuer-trust";
|
4
8
|
import { hasStatus, type Out } from "../../utils/misc";
|
@@ -6,12 +10,17 @@ import type { StartUserAuthorization } from "./03-start-user-authorization";
|
|
6
10
|
import { ValidationFailed } from "../../utils/errors";
|
7
11
|
import { CredentialResponse } from "./types";
|
8
12
|
|
13
|
+
import { createDPopToken } from "../../utils/dpop";
|
14
|
+
import uuid from "react-native-uuid";
|
15
|
+
import { deleteKey } from "@pagopa/io-react-native-crypto";
|
16
|
+
import { DPOP_KET_TAG } from "./const";
|
17
|
+
|
9
18
|
export type ObtainCredential = (
|
10
19
|
issuerConf: Out<EvaluateIssuerTrust>["issuerConf"],
|
11
20
|
accessToken: Out<AuthorizeAccess>["accessToken"],
|
12
21
|
clientId: Out<StartUserAuthorization>["clientId"],
|
13
22
|
credentialDefinition: Out<StartUserAuthorization>["credentialDefinition"],
|
14
|
-
|
23
|
+
dPoPContext: CryptoContext,
|
15
24
|
context: {
|
16
25
|
credentialCryptoContext: CryptoContext;
|
17
26
|
appFetch?: GlobalFetch["fetch"];
|
@@ -60,7 +69,7 @@ export const obtainCredential: ObtainCredential = async (
|
|
60
69
|
accessToken,
|
61
70
|
clientId,
|
62
71
|
credentialDefinition,
|
63
|
-
|
72
|
+
dPoPContext,
|
64
73
|
context
|
65
74
|
) => {
|
66
75
|
const { credentialCryptoContext, appFetch = fetch } = context;
|
@@ -106,6 +115,17 @@ export const obtainCredential: ObtainCredential = async (
|
|
106
115
|
},
|
107
116
|
};
|
108
117
|
|
118
|
+
const tokenRequestSignedDPop = await await createDPopToken(
|
119
|
+
{
|
120
|
+
htm: "POST",
|
121
|
+
htu: credentialUrl,
|
122
|
+
jti: `${uuid.v4()}`,
|
123
|
+
ath: await sha256ToBase64(accessToken.access_token),
|
124
|
+
},
|
125
|
+
dPoPContext
|
126
|
+
);
|
127
|
+
|
128
|
+
await deleteKey(DPOP_KET_TAG);
|
109
129
|
const credentialRes = await appFetch(credentialUrl, {
|
110
130
|
method: "POST",
|
111
131
|
headers: {
|