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