@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api 0.34.1-feature.FIDES.1.274 → 0.34.1-feature.IDK.11.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +152 -210
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -41
- package/dist/index.d.ts +13 -41
- package/dist/index.js +150 -208
- package/dist/index.js.map +1 -1
- package/package.json +19 -24
- package/src/index.ts +1 -1
- package/src/siop-api-functions.ts +40 -53
- package/src/siopv2-rp-api-server.ts +10 -9
- package/src/types/types.ts +3 -38
- package/src/webapp-api-functions.ts +183 -0
- package/src/middleware/validationMiddleware.ts +0 -20
- package/src/universal-oid4vp-api-functions.ts +0 -194
package/dist/index.cjs
CHANGED
|
@@ -32,27 +32,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
34
|
SIOPv2RPApiServer: () => SIOPv2RPApiServer,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
createAuthRequestUniversalOID4VPEndpoint: () => createAuthRequestUniversalOID4VPEndpoint,
|
|
35
|
+
authStatusWebappEndpoint: () => authStatusWebappEndpoint,
|
|
36
|
+
createAuthRequestWebappEndpoint: () => createAuthRequestWebappEndpoint,
|
|
38
37
|
getAuthRequestSIOPv2Endpoint: () => getAuthRequestSIOPv2Endpoint,
|
|
39
38
|
getDefinitionsEndpoint: () => getDefinitionsEndpoint,
|
|
40
|
-
|
|
39
|
+
removeAuthRequestStateWebappEndpoint: () => removeAuthRequestStateWebappEndpoint,
|
|
41
40
|
verifyAuthResponseSIOPv2Endpoint: () => verifyAuthResponseSIOPv2Endpoint
|
|
42
41
|
});
|
|
43
42
|
module.exports = __toCommonJS(index_exports);
|
|
44
43
|
|
|
45
44
|
// src/siop-api-functions.ts
|
|
45
|
+
var import_did_auth_siop = require("@sphereon/did-auth-siop");
|
|
46
46
|
var import_ssi_express_support = require("@sphereon/ssi-express-support");
|
|
47
47
|
var import_ssi_types = require("@sphereon/ssi-types");
|
|
48
|
-
var import_uuid = require("uuid");
|
|
49
48
|
var parseAuthorizationResponse = /* @__PURE__ */ __name((request) => {
|
|
50
49
|
const contentType = request.header("content-type");
|
|
51
|
-
if (contentType
|
|
50
|
+
if (contentType === "application/json") {
|
|
52
51
|
const payload = typeof request.body === "string" ? JSON.parse(request.body) : request.body;
|
|
53
52
|
return payload;
|
|
54
53
|
}
|
|
55
|
-
if (contentType
|
|
54
|
+
if (contentType === "application/x-www-form-urlencoded") {
|
|
56
55
|
const payload = request.body;
|
|
57
56
|
if (typeof payload.presentation_submission === "string") {
|
|
58
57
|
console.log(`Supplied presentation_submission was a string instead of JSON. Correcting, but external party should fix their implementation!`);
|
|
@@ -68,31 +67,34 @@ var parseAuthorizationResponse = /* @__PURE__ */ __name((request) => {
|
|
|
68
67
|
}
|
|
69
68
|
throw new Error(`Unsupported content type: ${contentType}. Currently only application/x-www-form-urlencoded and application/json (for direct_post) are supported`);
|
|
70
69
|
}, "parseAuthorizationResponse");
|
|
71
|
-
var validatePresentationSubmission = /* @__PURE__ */ __name((query, submission) => {
|
|
72
|
-
return query.credentials.every((credential) => credential.id in submission);
|
|
73
|
-
}, "validatePresentationSubmission");
|
|
74
70
|
function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
75
71
|
if (opts?.enabled === false) {
|
|
76
72
|
console.log(`verifyAuthResponse SIOP endpoint is disabled`);
|
|
77
73
|
return;
|
|
78
74
|
}
|
|
79
|
-
const path = opts?.path ?? "/siop/
|
|
75
|
+
const path = opts?.path ?? "/siop/definitions/:definitionId/auth-responses/:correlationId";
|
|
80
76
|
router.post(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
81
77
|
try {
|
|
82
|
-
const { correlationId,
|
|
83
|
-
if (!correlationId) {
|
|
84
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}`);
|
|
78
|
+
const { correlationId, definitionId, tenantId, version } = request.params;
|
|
79
|
+
if (!correlationId || !definitionId) {
|
|
80
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`);
|
|
85
81
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, "No authorization request could be found");
|
|
86
82
|
}
|
|
87
|
-
console.
|
|
88
|
-
console.
|
|
83
|
+
console.log("Authorization Response (siop-sessions");
|
|
84
|
+
console.log(JSON.stringify(request.body, null, 2));
|
|
89
85
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
90
|
-
filter:
|
|
86
|
+
filter: [
|
|
87
|
+
{
|
|
88
|
+
definitionId,
|
|
89
|
+
tenantId,
|
|
90
|
+
version
|
|
91
|
+
}
|
|
92
|
+
]
|
|
91
93
|
});
|
|
92
94
|
if (definitionItems.length === 0) {
|
|
93
|
-
console.log(`Could not get
|
|
95
|
+
console.log(`Could not get definition ${definitionId} from agent. Will return 404`);
|
|
94
96
|
response.statusCode = 404;
|
|
95
|
-
response.statusMessage = `No definition ${
|
|
97
|
+
response.statusMessage = `No definition ${definitionId}`;
|
|
96
98
|
return response.send();
|
|
97
99
|
}
|
|
98
100
|
const authorizationResponse = parseAuthorizationResponse(request);
|
|
@@ -101,11 +103,18 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
101
103
|
const verifiedResponse = await context.agent.siopVerifyAuthResponse({
|
|
102
104
|
authorizationResponse,
|
|
103
105
|
correlationId,
|
|
104
|
-
|
|
106
|
+
definitionId,
|
|
107
|
+
presentationDefinitions: [
|
|
108
|
+
{
|
|
109
|
+
location: opts?.presentationDefinitionLocation ?? import_did_auth_siop.PresentationDefinitionLocation.TOPLEVEL_PRESENTATION_DEF,
|
|
110
|
+
definition: definitionItem.definitionPayload
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
dcqlQuery: definitionItem.dcqlPayload
|
|
105
114
|
});
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
console.log("
|
|
115
|
+
const wrappedPresentation = verifiedResponse?.oid4vpSubmission?.presentations[0];
|
|
116
|
+
if (wrappedPresentation) {
|
|
117
|
+
console.log("PRESENTATION:" + JSON.stringify(wrappedPresentation.presentation, null, 2));
|
|
109
118
|
response.statusCode = 200;
|
|
110
119
|
const authorizationChallengeValidationResponse = {
|
|
111
120
|
presentation_during_issuance_session: verifiedResponse.correlationId
|
|
@@ -116,6 +125,7 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
116
125
|
}
|
|
117
126
|
const responseRedirectURI = await context.agent.siopGetRedirectURI({
|
|
118
127
|
correlationId,
|
|
128
|
+
definitionId,
|
|
119
129
|
state: verifiedResponse.state
|
|
120
130
|
});
|
|
121
131
|
if (responseRedirectURI) {
|
|
@@ -142,34 +152,24 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
142
152
|
console.log(`getAuthRequest SIOP endpoint is disabled`);
|
|
143
153
|
return;
|
|
144
154
|
}
|
|
145
|
-
const path = opts?.path ?? "/siop/
|
|
155
|
+
const path = opts?.path ?? "/siop/definitions/:definitionId/auth-requests/:correlationId";
|
|
146
156
|
router.get(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
147
157
|
try {
|
|
148
158
|
const correlationId = request.params.correlationId;
|
|
149
|
-
const
|
|
150
|
-
if (!correlationId || !
|
|
151
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId},
|
|
159
|
+
const definitionId = request.params.definitionId;
|
|
160
|
+
if (!correlationId || !definitionId) {
|
|
161
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`);
|
|
152
162
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, "No authorization request could be found");
|
|
153
163
|
}
|
|
154
164
|
const requestState = await context.agent.siopGetAuthRequestState({
|
|
155
165
|
correlationId,
|
|
166
|
+
definitionId,
|
|
156
167
|
errorOnNotFound: false
|
|
157
168
|
});
|
|
158
169
|
if (!requestState) {
|
|
159
|
-
console.log(`No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${
|
|
170
|
+
console.log(`No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${definitionId}`);
|
|
160
171
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, `No authorization request could be found`);
|
|
161
172
|
}
|
|
162
|
-
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
163
|
-
filter: buildQueryIdFilter(queryId)
|
|
164
|
-
});
|
|
165
|
-
if (definitionItems.length === 0) {
|
|
166
|
-
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`);
|
|
167
|
-
response.statusCode = 404;
|
|
168
|
-
response.statusMessage = `No definition ${queryId}`;
|
|
169
|
-
return response.send();
|
|
170
|
-
}
|
|
171
|
-
const payload = requestState.request?.requestObject?.getPayload();
|
|
172
|
-
payload.dcql_query = definitionItems[0].query;
|
|
173
173
|
const requestObject = await requestState.request?.requestObject?.toJwt();
|
|
174
174
|
console.log("JWT Request object:");
|
|
175
175
|
console.log(requestObject);
|
|
@@ -184,7 +184,8 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
184
184
|
} finally {
|
|
185
185
|
await context.agent.siopUpdateAuthRequestState({
|
|
186
186
|
correlationId,
|
|
187
|
-
|
|
187
|
+
definitionId,
|
|
188
|
+
state: "sent",
|
|
188
189
|
error
|
|
189
190
|
});
|
|
190
191
|
}
|
|
@@ -194,251 +195,192 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
194
195
|
});
|
|
195
196
|
}
|
|
196
197
|
__name(getAuthRequestSIOPv2Endpoint, "getAuthRequestSIOPv2Endpoint");
|
|
197
|
-
function buildQueryIdFilter(queryId, tenantId, version) {
|
|
198
|
-
const queryFilter = {
|
|
199
|
-
queryId,
|
|
200
|
-
...tenantId ? {
|
|
201
|
-
tenantId
|
|
202
|
-
} : {},
|
|
203
|
-
...version ? {
|
|
204
|
-
version
|
|
205
|
-
} : {}
|
|
206
|
-
};
|
|
207
|
-
return [
|
|
208
|
-
queryFilter,
|
|
209
|
-
...(0, import_uuid.validate)(queryId) ? [
|
|
210
|
-
{
|
|
211
|
-
id: queryId
|
|
212
|
-
}
|
|
213
|
-
] : []
|
|
214
|
-
];
|
|
215
|
-
}
|
|
216
|
-
__name(buildQueryIdFilter, "buildQueryIdFilter");
|
|
217
198
|
|
|
218
|
-
// src/
|
|
219
|
-
var
|
|
199
|
+
// src/webapp-api-functions.ts
|
|
200
|
+
var import_did_auth_siop2 = require("@sphereon/did-auth-siop");
|
|
220
201
|
var import_ssi_express_support2 = require("@sphereon/ssi-express-support");
|
|
221
202
|
var import_ssi_sdk = require("@sphereon/ssi-sdk.siopv2-oid4vp-common");
|
|
203
|
+
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth");
|
|
222
204
|
var import_short_uuid = __toESM(require("short-uuid"), 1);
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
var import_zod = require("zod");
|
|
226
|
-
var validateData = /* @__PURE__ */ __name((schema) => {
|
|
227
|
-
return (req, res, next) => {
|
|
228
|
-
try {
|
|
229
|
-
schema.parse(req.body);
|
|
230
|
-
next();
|
|
231
|
-
} catch (error) {
|
|
232
|
-
if (error instanceof import_zod.ZodError) {
|
|
233
|
-
const errorMessages = error.issues.map((issue) => ({
|
|
234
|
-
message: `${issue.path.join(".")} is ${issue.message}`
|
|
235
|
-
}));
|
|
236
|
-
res.status(400).json({
|
|
237
|
-
status: 400,
|
|
238
|
-
message: "Invalid data",
|
|
239
|
-
error_details: errorMessages[0].message
|
|
240
|
-
});
|
|
241
|
-
} else {
|
|
242
|
-
res.status(500).json({
|
|
243
|
-
status: 500,
|
|
244
|
-
message: "Internal Server Error"
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
}, "validateData");
|
|
250
|
-
|
|
251
|
-
// src/universal-oid4vp-api-functions.ts
|
|
252
|
-
function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
205
|
+
var import_ssi_sdk3 = require("@sphereon/ssi-sdk.core");
|
|
206
|
+
function createAuthRequestWebappEndpoint(router, context, opts) {
|
|
253
207
|
if (opts?.enabled === false) {
|
|
254
|
-
console.log(`createAuthRequest
|
|
208
|
+
console.log(`createAuthRequest Webapp endpoint is disabled`);
|
|
255
209
|
return;
|
|
256
210
|
}
|
|
257
|
-
const path = opts?.path ?? "/
|
|
258
|
-
router.post(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint),
|
|
211
|
+
const path = opts?.path ?? "/webapp/definitions/:definitionId/auth-requests";
|
|
212
|
+
router.post(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
259
213
|
try {
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
...authRequest.qrCode
|
|
264
|
-
} : opts?.qrCodeOpts;
|
|
265
|
-
const queryId = authRequest.queryId;
|
|
266
|
-
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
267
|
-
filter: buildQueryIdFilter(queryId)
|
|
268
|
-
});
|
|
269
|
-
if (definitionItems.length === 0) {
|
|
270
|
-
console.log(`No query could be found for the given id. Query id: ${queryId}`);
|
|
271
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 404, {
|
|
272
|
-
status: 404,
|
|
273
|
-
message: "No query could be found"
|
|
274
|
-
});
|
|
214
|
+
const definitionId = request.params.definitionId;
|
|
215
|
+
if (!definitionId) {
|
|
216
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 400, "No definitionId query parameter provided");
|
|
275
217
|
}
|
|
276
|
-
const
|
|
277
|
-
|
|
218
|
+
const state = request.body.state ?? import_short_uuid.default.uuid();
|
|
219
|
+
const correlationId = request.body.correlationId ?? state;
|
|
220
|
+
const qrCodeOpts = request.body.qrCodeOpts ?? opts?.qrCodeOpts;
|
|
221
|
+
const requestByReferenceURI = (0, import_ssi_sdk.uriWithBase)(`/siop/definitions/${definitionId}/auth-requests/${state}`, {
|
|
222
|
+
baseURI: opts?.siopBaseURI
|
|
278
223
|
});
|
|
279
|
-
const responseURI = (0, import_ssi_sdk.uriWithBase)(`/siop/
|
|
224
|
+
const responseURI = (0, import_ssi_sdk.uriWithBase)(`/siop/definitions/${definitionId}/auth-responses/${state}`, {
|
|
280
225
|
baseURI: opts?.siopBaseURI
|
|
281
226
|
});
|
|
227
|
+
const responseRedirectURI = ("response_redirect_uri" in request.body && request.body.response_redirect_uri) ?? ("responseRedirectURI" in request.body && request.body.responseRedirectURI);
|
|
282
228
|
const authRequestURI = await context.agent.siopCreateAuthRequestURI({
|
|
283
|
-
|
|
229
|
+
definitionId,
|
|
284
230
|
correlationId,
|
|
231
|
+
state,
|
|
285
232
|
nonce: import_short_uuid.default.uuid(),
|
|
286
233
|
requestByReferenceURI,
|
|
287
234
|
responseURIType: "response_uri",
|
|
288
235
|
responseURI,
|
|
289
|
-
...
|
|
290
|
-
responseRedirectURI
|
|
291
|
-
},
|
|
292
|
-
...authRequest.callback && {
|
|
293
|
-
callback: authRequest.callback
|
|
236
|
+
...responseRedirectURI && {
|
|
237
|
+
responseRedirectURI
|
|
294
238
|
}
|
|
295
239
|
});
|
|
296
240
|
let qrCodeDataUri;
|
|
297
241
|
if (qrCodeOpts) {
|
|
298
242
|
const { AwesomeQR } = await import("awesome-qr");
|
|
299
243
|
const qrCode = new AwesomeQR({
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
colorDark: qrCodeOpts.colorDark ?? "#000000",
|
|
303
|
-
colorLight: qrCodeOpts.colorLight ?? "#FFFFFF"
|
|
244
|
+
...qrCodeOpts,
|
|
245
|
+
text: authRequestURI
|
|
304
246
|
});
|
|
305
247
|
qrCodeDataUri = `data:image/png;base64,${(await qrCode.draw()).toString("base64")}`;
|
|
306
|
-
} else {
|
|
307
|
-
qrCodeDataUri = authRequestURI;
|
|
308
248
|
}
|
|
309
249
|
const authRequestBody = {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
250
|
+
correlationId,
|
|
251
|
+
state,
|
|
252
|
+
definitionId,
|
|
253
|
+
authRequestURI,
|
|
254
|
+
authStatusURI: `${(0, import_ssi_sdk.uriWithBase)(opts?.webappAuthStatusPath ?? "/webapp/auth-status", {
|
|
314
255
|
baseURI: opts?.webappBaseURI
|
|
315
256
|
})}`,
|
|
316
257
|
...qrCodeDataUri && {
|
|
317
|
-
|
|
258
|
+
qrCodeDataUri
|
|
318
259
|
}
|
|
319
260
|
};
|
|
320
261
|
console.log(`Auth Request URI data to send back: ${JSON.stringify(authRequestBody)}`);
|
|
321
|
-
return response.
|
|
262
|
+
return response.json(authRequestBody);
|
|
322
263
|
} catch (error) {
|
|
323
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500,
|
|
324
|
-
status: 500,
|
|
325
|
-
message: "Could not create an authorization request URI"
|
|
326
|
-
}, error);
|
|
264
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, "Could not create an authorization request URI", error);
|
|
327
265
|
}
|
|
328
266
|
});
|
|
329
267
|
}
|
|
330
|
-
__name(
|
|
331
|
-
function
|
|
268
|
+
__name(createAuthRequestWebappEndpoint, "createAuthRequestWebappEndpoint");
|
|
269
|
+
function authStatusWebappEndpoint(router, context, opts) {
|
|
332
270
|
if (opts?.enabled === false) {
|
|
333
|
-
console.log(`
|
|
271
|
+
console.log(`authStatus Webapp endpoint is disabled`);
|
|
334
272
|
return;
|
|
335
273
|
}
|
|
336
|
-
const path = opts?.path ?? "/
|
|
337
|
-
router.
|
|
338
|
-
try {
|
|
339
|
-
const correlationId = request.params.correlationId;
|
|
340
|
-
const authRequestState = await context.agent.siopGetAuthRequestState({
|
|
341
|
-
correlationId,
|
|
342
|
-
errorOnNotFound: false
|
|
343
|
-
});
|
|
344
|
-
if (!authRequestState) {
|
|
345
|
-
console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`);
|
|
346
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 404, {
|
|
347
|
-
status: 404,
|
|
348
|
-
message: "No authorization request could be found"
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
await context.agent.siopDeleteAuthState({
|
|
352
|
-
correlationId
|
|
353
|
-
});
|
|
354
|
-
return response.status(204).json();
|
|
355
|
-
} catch (error) {
|
|
356
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, {
|
|
357
|
-
status: 500,
|
|
358
|
-
message: error.message
|
|
359
|
-
}, error);
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
__name(removeAuthRequestStateUniversalOID4VPEndpoint, "removeAuthRequestStateUniversalOID4VPEndpoint");
|
|
364
|
-
function authStatusUniversalOID4VPEndpoint(router, context, opts) {
|
|
365
|
-
if (opts?.enabled === false) {
|
|
366
|
-
console.log(`authStatus universal OID4VP endpoint is disabled`);
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
const path = opts?.path ?? "/backend/auth/status/:correlationId";
|
|
370
|
-
router.get(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
274
|
+
const path = opts?.path ?? "/webapp/auth-status";
|
|
275
|
+
router.post(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
371
276
|
try {
|
|
372
277
|
console.log("Received auth-status request...");
|
|
373
|
-
const correlationId = request.
|
|
374
|
-
const
|
|
278
|
+
const correlationId = request.body.correlationId;
|
|
279
|
+
const definitionId = request.body.definitionId;
|
|
280
|
+
const requestState = correlationId && definitionId ? await context.agent.siopGetAuthRequestState({
|
|
375
281
|
correlationId,
|
|
282
|
+
definitionId,
|
|
376
283
|
errorOnNotFound: false
|
|
377
|
-
});
|
|
378
|
-
if (!requestState) {
|
|
379
|
-
console.log(`No
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
284
|
+
}) : void 0;
|
|
285
|
+
if (!requestState || !definitionId || !correlationId) {
|
|
286
|
+
console.log(`No authentication request mapping could be found for the given URL. correlation: ${correlationId}, definitionId: ${definitionId}`);
|
|
287
|
+
response.statusCode = 404;
|
|
288
|
+
const statusBody2 = {
|
|
289
|
+
status: requestState ? requestState.status : "error",
|
|
290
|
+
error: "No authentication request mapping could be found for the given URL.",
|
|
291
|
+
correlationId,
|
|
292
|
+
definitionId,
|
|
293
|
+
lastUpdated: requestState ? requestState.lastUpdated : Date.now()
|
|
294
|
+
};
|
|
295
|
+
return response.json(statusBody2);
|
|
296
|
+
}
|
|
297
|
+
let includeVerifiedData = import_ssi_sdk2.VerifiedDataMode.NONE;
|
|
298
|
+
if ("includeVerifiedData" in request.body) {
|
|
299
|
+
includeVerifiedData = request.body.includeVerifiedData;
|
|
384
300
|
}
|
|
385
301
|
let responseState;
|
|
386
|
-
if (requestState.status ===
|
|
302
|
+
if (requestState.status === "sent") {
|
|
387
303
|
responseState = await context.agent.siopGetAuthResponseState({
|
|
388
304
|
correlationId,
|
|
305
|
+
definitionId,
|
|
306
|
+
includeVerifiedData,
|
|
389
307
|
errorOnNotFound: false
|
|
390
308
|
});
|
|
391
309
|
}
|
|
392
310
|
const overallState = responseState ?? requestState;
|
|
393
311
|
const statusBody = {
|
|
394
312
|
status: overallState.status,
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
...
|
|
402
|
-
|
|
403
|
-
|
|
313
|
+
...overallState.error ? {
|
|
314
|
+
error: overallState.error?.message
|
|
315
|
+
} : {},
|
|
316
|
+
correlationId,
|
|
317
|
+
definitionId,
|
|
318
|
+
lastUpdated: overallState.lastUpdated,
|
|
319
|
+
...responseState && responseState.status === import_did_auth_siop2.AuthorizationResponseStateStatus.VERIFIED ? {
|
|
320
|
+
payload: await responseState.response.mergedPayloads({
|
|
321
|
+
hasher: import_ssi_sdk3.shaHasher
|
|
322
|
+
}),
|
|
323
|
+
verifiedData: responseState.verifiedData
|
|
324
|
+
} : {}
|
|
404
325
|
};
|
|
405
326
|
console.debug(`Will send auth status: ${JSON.stringify(statusBody)}`);
|
|
406
327
|
if (overallState.status === "error") {
|
|
407
|
-
|
|
328
|
+
response.statusCode = 500;
|
|
329
|
+
return response.json(statusBody);
|
|
330
|
+
}
|
|
331
|
+
response.statusCode = 200;
|
|
332
|
+
return response.json(statusBody);
|
|
333
|
+
} catch (error) {
|
|
334
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, error.message, error);
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
__name(authStatusWebappEndpoint, "authStatusWebappEndpoint");
|
|
339
|
+
function removeAuthRequestStateWebappEndpoint(router, context, opts) {
|
|
340
|
+
if (opts?.enabled === false) {
|
|
341
|
+
console.log(`removeAuthStatus Webapp endpoint is disabled`);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const path = opts?.path ?? "/webapp/definitions/:definitionId/auth-requests/:correlationId";
|
|
345
|
+
router.delete(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
346
|
+
try {
|
|
347
|
+
const correlationId = request.params.correlationId;
|
|
348
|
+
const definitionId = request.params.definitionId;
|
|
349
|
+
if (!correlationId || !definitionId) {
|
|
350
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`);
|
|
351
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 404, "No authorization request could be found");
|
|
408
352
|
}
|
|
409
|
-
|
|
353
|
+
response.statusCode = 200;
|
|
354
|
+
return response.json(await context.agent.siopDeleteAuthState({
|
|
355
|
+
definitionId,
|
|
356
|
+
correlationId
|
|
357
|
+
}));
|
|
410
358
|
} catch (error) {
|
|
411
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500,
|
|
412
|
-
status: 500,
|
|
413
|
-
message: error.message
|
|
414
|
-
}, error);
|
|
359
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, error.message, error);
|
|
415
360
|
}
|
|
416
361
|
});
|
|
417
362
|
}
|
|
418
|
-
__name(
|
|
363
|
+
__name(removeAuthRequestStateWebappEndpoint, "removeAuthRequestStateWebappEndpoint");
|
|
419
364
|
function getDefinitionsEndpoint(router, context, opts) {
|
|
420
365
|
if (opts?.enabled === false) {
|
|
421
|
-
console.log(`getDefinitions
|
|
366
|
+
console.log(`getDefinitions Webapp endpoint is disabled`);
|
|
422
367
|
return;
|
|
423
368
|
}
|
|
424
|
-
const path = opts?.path ?? "/
|
|
369
|
+
const path = opts?.path ?? "/webapp/definitions";
|
|
425
370
|
router.get(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
426
371
|
try {
|
|
427
372
|
const definitions = await context.agent.pdmGetDefinitions();
|
|
428
373
|
response.statusCode = 200;
|
|
429
374
|
return response.json(definitions);
|
|
430
375
|
} catch (error) {
|
|
431
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500,
|
|
432
|
-
status: 500,
|
|
433
|
-
message: error.message
|
|
434
|
-
}, error);
|
|
376
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, error.message, error);
|
|
435
377
|
}
|
|
436
378
|
});
|
|
437
379
|
}
|
|
438
380
|
__name(getDefinitionsEndpoint, "getDefinitionsEndpoint");
|
|
439
381
|
|
|
440
382
|
// src/siopv2-rp-api-server.ts
|
|
441
|
-
var
|
|
383
|
+
var import_ssi_sdk4 = require("@sphereon/ssi-sdk.core");
|
|
442
384
|
var import_ssi_express_support3 = require("@sphereon/ssi-express-support");
|
|
443
385
|
var import_express = __toESM(require("express"), 1);
|
|
444
386
|
var import_swagger_ui_express = __toESM(require("swagger-ui-express"), 1);
|
|
@@ -475,16 +417,16 @@ var SIOPv2RPApiServer = class {
|
|
|
475
417
|
this._opts = opts;
|
|
476
418
|
this._express = args.expressSupport.express;
|
|
477
419
|
this._router = import_express.default.Router();
|
|
478
|
-
const context = (0,
|
|
420
|
+
const context = (0, import_ssi_sdk4.agentContext)(agent);
|
|
479
421
|
const features = opts?.enableFeatures ?? [
|
|
480
422
|
"rp-status",
|
|
481
423
|
"siop"
|
|
482
424
|
];
|
|
483
425
|
console.log(`SIOPv2 API enabled, with features: ${JSON.stringify(features)}}`);
|
|
484
426
|
if (features.includes("rp-status")) {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
427
|
+
createAuthRequestWebappEndpoint(this._router, context, opts?.endpointOpts?.webappCreateAuthRequest);
|
|
428
|
+
authStatusWebappEndpoint(this._router, context, opts?.endpointOpts?.webappAuthStatus);
|
|
429
|
+
removeAuthRequestStateWebappEndpoint(this._router, context, opts?.endpointOpts?.webappDeleteAuthRequest);
|
|
488
430
|
getDefinitionsEndpoint(this._router, context, opts?.endpointOpts?.webappGetDefinitions);
|
|
489
431
|
}
|
|
490
432
|
if (features.includes("siop")) {
|