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