@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api 0.34.1-feat.SSISDK.35.64 → 0.34.1-feat.SSISDK.55.244
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 +202 -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 +200 -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,6 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
125
127
|
}
|
|
126
128
|
const responseRedirectURI = await context.agent.siopGetRedirectURI({
|
|
127
129
|
correlationId,
|
|
128
|
-
definitionId,
|
|
129
130
|
state: verifiedResponse.state
|
|
130
131
|
});
|
|
131
132
|
if (responseRedirectURI) {
|
|
@@ -152,24 +153,38 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
152
153
|
console.log(`getAuthRequest SIOP endpoint is disabled`);
|
|
153
154
|
return;
|
|
154
155
|
}
|
|
155
|
-
const path = opts?.path ?? "/siop/
|
|
156
|
+
const path = opts?.path ?? "/siop/queries/:queryId/auth-requests/:correlationId";
|
|
156
157
|
router.get(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
157
158
|
try {
|
|
158
159
|
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},
|
|
160
|
+
const queryId = request.params.queryId;
|
|
161
|
+
if (!correlationId || !queryId) {
|
|
162
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, queryId: ${queryId}`);
|
|
162
163
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, "No authorization request could be found");
|
|
163
164
|
}
|
|
164
165
|
const requestState = await context.agent.siopGetAuthRequestState({
|
|
165
166
|
correlationId,
|
|
166
|
-
definitionId,
|
|
167
167
|
errorOnNotFound: false
|
|
168
168
|
});
|
|
169
169
|
if (!requestState) {
|
|
170
|
-
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: ${queryId}`);
|
|
171
171
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, `No authorization request could be found`);
|
|
172
172
|
}
|
|
173
|
+
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
174
|
+
filter: [
|
|
175
|
+
{
|
|
176
|
+
queryId
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
});
|
|
180
|
+
if (definitionItems.length === 0) {
|
|
181
|
+
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`);
|
|
182
|
+
response.statusCode = 404;
|
|
183
|
+
response.statusMessage = `No definition ${queryId}`;
|
|
184
|
+
return response.send();
|
|
185
|
+
}
|
|
186
|
+
const payload = requestState.request?.requestObject?.getPayload();
|
|
187
|
+
payload.dcql_query = definitionItems[0].query;
|
|
173
188
|
const requestObject = await requestState.request?.requestObject?.toJwt();
|
|
174
189
|
console.log("JWT Request object:");
|
|
175
190
|
console.log(requestObject);
|
|
@@ -184,8 +199,7 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
184
199
|
} finally {
|
|
185
200
|
await context.agent.siopUpdateAuthRequestState({
|
|
186
201
|
correlationId,
|
|
187
|
-
|
|
188
|
-
state: "sent",
|
|
202
|
+
state: "authorization_request_created",
|
|
189
203
|
error
|
|
190
204
|
});
|
|
191
205
|
}
|
|
@@ -196,45 +210,89 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
196
210
|
}
|
|
197
211
|
__name(getAuthRequestSIOPv2Endpoint, "getAuthRequestSIOPv2Endpoint");
|
|
198
212
|
|
|
199
|
-
// src/
|
|
200
|
-
var
|
|
213
|
+
// src/universal-oid4vp-api-functions.ts
|
|
214
|
+
var import_did_auth_siop = require("@sphereon/did-auth-siop");
|
|
201
215
|
var import_ssi_express_support2 = require("@sphereon/ssi-express-support");
|
|
202
216
|
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
217
|
var import_short_uuid = __toESM(require("short-uuid"), 1);
|
|
205
|
-
|
|
206
|
-
|
|
218
|
+
|
|
219
|
+
// src/middleware/validationMiddleware.ts
|
|
220
|
+
var import_zod = require("zod");
|
|
221
|
+
var validateData = /* @__PURE__ */ __name((schema) => {
|
|
222
|
+
return (req, res, next) => {
|
|
223
|
+
try {
|
|
224
|
+
schema.parse(req.body);
|
|
225
|
+
next();
|
|
226
|
+
} catch (error) {
|
|
227
|
+
if (error instanceof import_zod.ZodError) {
|
|
228
|
+
const errorMessages = error.issues.map((issue) => ({
|
|
229
|
+
message: `${issue.path.join(".")} is ${issue.message}`
|
|
230
|
+
}));
|
|
231
|
+
res.status(400).json({
|
|
232
|
+
status: 400,
|
|
233
|
+
message: "Invalid data",
|
|
234
|
+
error_details: errorMessages[0].message
|
|
235
|
+
});
|
|
236
|
+
} else {
|
|
237
|
+
res.status(500).json({
|
|
238
|
+
status: 500,
|
|
239
|
+
message: "Internal Server Error"
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}, "validateData");
|
|
245
|
+
|
|
246
|
+
// src/universal-oid4vp-api-functions.ts
|
|
247
|
+
function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
207
248
|
if (opts?.enabled === false) {
|
|
208
|
-
console.log(`createAuthRequest
|
|
249
|
+
console.log(`createAuthRequest universal OID4VP endpoint is disabled`);
|
|
209
250
|
return;
|
|
210
251
|
}
|
|
211
|
-
const path = opts?.path ?? "/
|
|
212
|
-
router.post(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
252
|
+
const path = opts?.path ?? "/backend/auth/requests";
|
|
253
|
+
router.post(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), validateData(import_did_auth_siop.CreateAuthorizationRequestPayloadSchema), async (request, response) => {
|
|
213
254
|
try {
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
255
|
+
const authRequest = (0, import_did_auth_siop.createAuthorizationRequestFromPayload)(request.body);
|
|
256
|
+
const correlationId = authRequest.correlationId ?? import_short_uuid.default.uuid();
|
|
257
|
+
const qrCodeOpts = authRequest.qrCode ? {
|
|
258
|
+
...authRequest.qrCode
|
|
259
|
+
} : opts?.qrCodeOpts;
|
|
260
|
+
const queryId = authRequest.queryId;
|
|
261
|
+
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
262
|
+
filter: [
|
|
263
|
+
{
|
|
264
|
+
id: queryId
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
queryId
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
});
|
|
271
|
+
if (definitionItems.length === 0) {
|
|
272
|
+
console.log(`No query could be found for the given id. Query id: ${queryId}`);
|
|
273
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 404, {
|
|
274
|
+
status: 404,
|
|
275
|
+
message: "No query could be found"
|
|
276
|
+
});
|
|
217
277
|
}
|
|
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
|
|
278
|
+
const requestByReferenceURI = (0, import_ssi_sdk.uriWithBase)(`/siop/queries/${queryId}/auth-requests/${correlationId}`, {
|
|
279
|
+
baseURI: authRequest.requestUriBase ?? opts?.siopBaseURI
|
|
223
280
|
});
|
|
224
|
-
const responseURI = (0, import_ssi_sdk.uriWithBase)(`/siop/
|
|
281
|
+
const responseURI = (0, import_ssi_sdk.uriWithBase)(`/siop/queries/${queryId}/auth-responses/${correlationId}`, {
|
|
225
282
|
baseURI: opts?.siopBaseURI
|
|
226
283
|
});
|
|
227
|
-
const responseRedirectURI = ("response_redirect_uri" in request.body && request.body.response_redirect_uri) ?? ("responseRedirectURI" in request.body && request.body.responseRedirectURI);
|
|
228
284
|
const authRequestURI = await context.agent.siopCreateAuthRequestURI({
|
|
229
|
-
|
|
285
|
+
queryId,
|
|
230
286
|
correlationId,
|
|
231
|
-
state,
|
|
232
287
|
nonce: import_short_uuid.default.uuid(),
|
|
233
288
|
requestByReferenceURI,
|
|
234
289
|
responseURIType: "response_uri",
|
|
235
290
|
responseURI,
|
|
236
|
-
...
|
|
237
|
-
responseRedirectURI
|
|
291
|
+
...authRequest.directPostResponseRedirectUri && {
|
|
292
|
+
responseRedirectURI: authRequest.directPostResponseRedirectUri
|
|
293
|
+
},
|
|
294
|
+
...authRequest.callback && {
|
|
295
|
+
callback: authRequest.callback
|
|
238
296
|
}
|
|
239
297
|
});
|
|
240
298
|
let qrCodeDataUri;
|
|
@@ -245,142 +303,142 @@ function createAuthRequestWebappEndpoint(router, context, opts) {
|
|
|
245
303
|
text: authRequestURI
|
|
246
304
|
});
|
|
247
305
|
qrCodeDataUri = `data:image/png;base64,${(await qrCode.draw()).toString("base64")}`;
|
|
306
|
+
} else {
|
|
307
|
+
qrCodeDataUri = authRequestURI;
|
|
248
308
|
}
|
|
249
309
|
const authRequestBody = {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
authStatusURI: `${(0, import_ssi_sdk.uriWithBase)(opts?.webappAuthStatusPath ?? "/webapp/auth-status", {
|
|
310
|
+
query_id: queryId,
|
|
311
|
+
correlation_id: correlationId,
|
|
312
|
+
request_uri: authRequestURI,
|
|
313
|
+
status_uri: `${(0, import_ssi_sdk.uriWithBase)(opts?.webappAuthStatusPath ?? `/backend/auth/status/${correlationId}`, {
|
|
255
314
|
baseURI: opts?.webappBaseURI
|
|
256
315
|
})}`,
|
|
257
316
|
...qrCodeDataUri && {
|
|
258
|
-
qrCodeDataUri
|
|
317
|
+
qr_uri: qrCodeDataUri
|
|
259
318
|
}
|
|
260
319
|
};
|
|
261
320
|
console.log(`Auth Request URI data to send back: ${JSON.stringify(authRequestBody)}`);
|
|
262
|
-
return response.json(authRequestBody);
|
|
321
|
+
return response.status(201).json(authRequestBody);
|
|
263
322
|
} catch (error) {
|
|
264
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500,
|
|
323
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, {
|
|
324
|
+
status: 500,
|
|
325
|
+
message: "Could not create an authorization request URI"
|
|
326
|
+
}, error);
|
|
265
327
|
}
|
|
266
328
|
});
|
|
267
329
|
}
|
|
268
|
-
__name(
|
|
269
|
-
function
|
|
330
|
+
__name(createAuthRequestUniversalOID4VPEndpoint, "createAuthRequestUniversalOID4VPEndpoint");
|
|
331
|
+
function removeAuthRequestStateUniversalOID4VPEndpoint(router, context, opts) {
|
|
270
332
|
if (opts?.enabled === false) {
|
|
271
|
-
console.log(`
|
|
333
|
+
console.log(`removeAuthStatus universal OID4VP endpoint is disabled`);
|
|
272
334
|
return;
|
|
273
335
|
}
|
|
274
|
-
const path = opts?.path ?? "/
|
|
275
|
-
router.
|
|
336
|
+
const path = opts?.path ?? "/backend/auth/requests/:correlationId";
|
|
337
|
+
router.delete(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
276
338
|
try {
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
const definitionId = request.body.definitionId;
|
|
280
|
-
const requestState = correlationId && definitionId ? await context.agent.siopGetAuthRequestState({
|
|
339
|
+
const correlationId = request.params.correlationId;
|
|
340
|
+
const authRequestState = await context.agent.siopGetAuthRequestState({
|
|
281
341
|
correlationId,
|
|
282
|
-
definitionId,
|
|
283
342
|
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);
|
|
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
|
+
});
|
|
296
350
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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) => {
|
|
371
|
+
try {
|
|
372
|
+
console.log("Received auth-status request...");
|
|
373
|
+
const correlationId = request.params.correlationId;
|
|
374
|
+
const requestState = await context.agent.siopGetAuthRequestState({
|
|
375
|
+
correlationId,
|
|
376
|
+
errorOnNotFound: false
|
|
377
|
+
});
|
|
378
|
+
if (!requestState) {
|
|
379
|
+
console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`);
|
|
380
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 404, {
|
|
381
|
+
status: 404,
|
|
382
|
+
message: "No authorization request could be found"
|
|
383
|
+
});
|
|
300
384
|
}
|
|
301
385
|
let responseState;
|
|
302
|
-
if (requestState.status ===
|
|
386
|
+
if (requestState.status === import_did_auth_siop.AuthorizationRequestStateStatus.RETRIEVED) {
|
|
303
387
|
responseState = await context.agent.siopGetAuthResponseState({
|
|
304
388
|
correlationId,
|
|
305
|
-
definitionId,
|
|
306
|
-
includeVerifiedData,
|
|
307
389
|
errorOnNotFound: false
|
|
308
390
|
});
|
|
309
391
|
}
|
|
310
392
|
const overallState = responseState ?? requestState;
|
|
311
393
|
const statusBody = {
|
|
312
394
|
status: overallState.status,
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
...
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}),
|
|
323
|
-
verifiedData: responseState.verifiedData
|
|
324
|
-
} : {}
|
|
395
|
+
correlation_id: overallState.correlationId,
|
|
396
|
+
query_id: overallState.queryId,
|
|
397
|
+
last_updated: overallState.lastUpdated,
|
|
398
|
+
..."verifiedData" in overallState && {
|
|
399
|
+
verified_data: overallState.verifiedData
|
|
400
|
+
},
|
|
401
|
+
...overallState.error && {
|
|
402
|
+
message: overallState.error.message
|
|
403
|
+
}
|
|
325
404
|
};
|
|
326
405
|
console.debug(`Will send auth status: ${JSON.stringify(statusBody)}`);
|
|
327
406
|
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");
|
|
407
|
+
return response.status(500).json(statusBody);
|
|
352
408
|
}
|
|
353
|
-
response.
|
|
354
|
-
return response.json(await context.agent.siopDeleteAuthState({
|
|
355
|
-
definitionId,
|
|
356
|
-
correlationId
|
|
357
|
-
}));
|
|
409
|
+
return response.status(200).json(statusBody);
|
|
358
410
|
} catch (error) {
|
|
359
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500,
|
|
411
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, {
|
|
412
|
+
status: 500,
|
|
413
|
+
message: error.message
|
|
414
|
+
}, error);
|
|
360
415
|
}
|
|
361
416
|
});
|
|
362
417
|
}
|
|
363
|
-
__name(
|
|
418
|
+
__name(authStatusUniversalOID4VPEndpoint, "authStatusUniversalOID4VPEndpoint");
|
|
364
419
|
function getDefinitionsEndpoint(router, context, opts) {
|
|
365
420
|
if (opts?.enabled === false) {
|
|
366
|
-
console.log(`getDefinitions
|
|
421
|
+
console.log(`getDefinitions universal OID4VP endpoint is disabled`);
|
|
367
422
|
return;
|
|
368
423
|
}
|
|
369
|
-
const path = opts?.path ?? "/
|
|
424
|
+
const path = opts?.path ?? "/backend/definitions";
|
|
370
425
|
router.get(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
371
426
|
try {
|
|
372
427
|
const definitions = await context.agent.pdmGetDefinitions();
|
|
373
428
|
response.statusCode = 200;
|
|
374
429
|
return response.json(definitions);
|
|
375
430
|
} catch (error) {
|
|
376
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500,
|
|
431
|
+
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, {
|
|
432
|
+
status: 500,
|
|
433
|
+
message: error.message
|
|
434
|
+
}, error);
|
|
377
435
|
}
|
|
378
436
|
});
|
|
379
437
|
}
|
|
380
438
|
__name(getDefinitionsEndpoint, "getDefinitionsEndpoint");
|
|
381
439
|
|
|
382
440
|
// src/siopv2-rp-api-server.ts
|
|
383
|
-
var
|
|
441
|
+
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.core");
|
|
384
442
|
var import_ssi_express_support3 = require("@sphereon/ssi-express-support");
|
|
385
443
|
var import_express = __toESM(require("express"), 1);
|
|
386
444
|
var import_swagger_ui_express = __toESM(require("swagger-ui-express"), 1);
|
|
@@ -417,16 +475,16 @@ var SIOPv2RPApiServer = class {
|
|
|
417
475
|
this._opts = opts;
|
|
418
476
|
this._express = args.expressSupport.express;
|
|
419
477
|
this._router = import_express.default.Router();
|
|
420
|
-
const context = (0,
|
|
478
|
+
const context = (0, import_ssi_sdk2.agentContext)(agent);
|
|
421
479
|
const features = opts?.enableFeatures ?? [
|
|
422
480
|
"rp-status",
|
|
423
481
|
"siop"
|
|
424
482
|
];
|
|
425
483
|
console.log(`SIOPv2 API enabled, with features: ${JSON.stringify(features)}}`);
|
|
426
484
|
if (features.includes("rp-status")) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
485
|
+
createAuthRequestUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappCreateAuthRequest);
|
|
486
|
+
authStatusUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappAuthStatus);
|
|
487
|
+
removeAuthRequestStateUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappDeleteAuthRequest);
|
|
430
488
|
getDefinitionsEndpoint(this._router, context, opts?.endpointOpts?.webappGetDefinitions);
|
|
431
489
|
}
|
|
432
490
|
if (features.includes("siop")) {
|