@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api 0.34.1-next.29 → 0.34.1-next.299
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 +210 -152
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -13
- package/dist/index.d.ts +41 -13
- package/dist/index.js +208 -150
- package/dist/index.js.map +1 -1
- package/package.json +24 -19
- package/src/index.ts +1 -1
- package/src/middleware/validationMiddleware.ts +20 -0
- package/src/siop-api-functions.ts +53 -40
- 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,26 +32,27 @@ 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);
|
|
43
44
|
|
|
44
45
|
// 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");
|
|
48
49
|
var parseAuthorizationResponse = /* @__PURE__ */ __name((request) => {
|
|
49
50
|
const contentType = request.header("content-type");
|
|
50
|
-
if (contentType
|
|
51
|
+
if (contentType?.startsWith("application/json")) {
|
|
51
52
|
const payload = typeof request.body === "string" ? JSON.parse(request.body) : request.body;
|
|
52
53
|
return payload;
|
|
53
54
|
}
|
|
54
|
-
if (contentType
|
|
55
|
+
if (contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
55
56
|
const payload = request.body;
|
|
56
57
|
if (typeof payload.presentation_submission === "string") {
|
|
57
58
|
console.log(`Supplied presentation_submission was a string instead of JSON. Correcting, but external party should fix their implementation!`);
|
|
@@ -67,34 +68,31 @@ var parseAuthorizationResponse = /* @__PURE__ */ __name((request) => {
|
|
|
67
68
|
}
|
|
68
69
|
throw new Error(`Unsupported content type: ${contentType}. Currently only application/x-www-form-urlencoded and application/json (for direct_post) are supported`);
|
|
69
70
|
}, "parseAuthorizationResponse");
|
|
71
|
+
var validatePresentationSubmission = /* @__PURE__ */ __name((query, submission) => {
|
|
72
|
+
return query.credentials.every((credential) => credential.id in submission);
|
|
73
|
+
}, "validatePresentationSubmission");
|
|
70
74
|
function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
71
75
|
if (opts?.enabled === false) {
|
|
72
76
|
console.log(`verifyAuthResponse SIOP endpoint is disabled`);
|
|
73
77
|
return;
|
|
74
78
|
}
|
|
75
|
-
const path = opts?.path ?? "/siop/
|
|
79
|
+
const path = opts?.path ?? "/siop/queries/:queryId/auth-responses/:correlationId";
|
|
76
80
|
router.post(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
77
81
|
try {
|
|
78
|
-
const { correlationId,
|
|
79
|
-
if (!correlationId
|
|
80
|
-
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}`);
|
|
81
85
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, "No authorization request could be found");
|
|
82
86
|
}
|
|
83
|
-
console.
|
|
84
|
-
console.
|
|
87
|
+
console.debug("Authorization Response (siop-sessions");
|
|
88
|
+
console.debug(JSON.stringify(request.body, null, 2));
|
|
85
89
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
86
|
-
filter:
|
|
87
|
-
{
|
|
88
|
-
definitionId,
|
|
89
|
-
tenantId,
|
|
90
|
-
version
|
|
91
|
-
}
|
|
92
|
-
]
|
|
90
|
+
filter: buildQueryIdFilter(queryId, tenantId, version)
|
|
93
91
|
});
|
|
94
92
|
if (definitionItems.length === 0) {
|
|
95
|
-
console.log(`Could not get
|
|
93
|
+
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`);
|
|
96
94
|
response.statusCode = 404;
|
|
97
|
-
response.statusMessage = `No definition ${
|
|
95
|
+
response.statusMessage = `No definition ${queryId}`;
|
|
98
96
|
return response.send();
|
|
99
97
|
}
|
|
100
98
|
const authorizationResponse = parseAuthorizationResponse(request);
|
|
@@ -103,18 +101,11 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
103
101
|
const verifiedResponse = await context.agent.siopVerifyAuthResponse({
|
|
104
102
|
authorizationResponse,
|
|
105
103
|
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
|
|
104
|
+
dcqlQuery: definitionItem.query
|
|
114
105
|
});
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
117
|
-
console.log("
|
|
106
|
+
const presentation = verifiedResponse?.oid4vpSubmission?.presentation;
|
|
107
|
+
if (presentation && validatePresentationSubmission(definitionItem.query, presentation)) {
|
|
108
|
+
console.log("PRESENTATIONS:" + JSON.stringify(presentation, null, 2));
|
|
118
109
|
response.statusCode = 200;
|
|
119
110
|
const authorizationChallengeValidationResponse = {
|
|
120
111
|
presentation_during_issuance_session: verifiedResponse.correlationId
|
|
@@ -125,7 +116,6 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
125
116
|
}
|
|
126
117
|
const responseRedirectURI = await context.agent.siopGetRedirectURI({
|
|
127
118
|
correlationId,
|
|
128
|
-
definitionId,
|
|
129
119
|
state: verifiedResponse.state
|
|
130
120
|
});
|
|
131
121
|
if (responseRedirectURI) {
|
|
@@ -152,24 +142,34 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
152
142
|
console.log(`getAuthRequest SIOP endpoint is disabled`);
|
|
153
143
|
return;
|
|
154
144
|
}
|
|
155
|
-
const path = opts?.path ?? "/siop/
|
|
145
|
+
const path = opts?.path ?? "/siop/queries/:queryId/auth-requests/:correlationId";
|
|
156
146
|
router.get(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
157
147
|
try {
|
|
158
148
|
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},
|
|
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}`);
|
|
162
152
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, "No authorization request could be found");
|
|
163
153
|
}
|
|
164
154
|
const requestState = await context.agent.siopGetAuthRequestState({
|
|
165
155
|
correlationId,
|
|
166
|
-
definitionId,
|
|
167
156
|
errorOnNotFound: false
|
|
168
157
|
});
|
|
169
158
|
if (!requestState) {
|
|
170
|
-
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}`);
|
|
171
160
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, `No authorization request could be found`);
|
|
172
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;
|
|
173
173
|
const requestObject = await requestState.request?.requestObject?.toJwt();
|
|
174
174
|
console.log("JWT Request object:");
|
|
175
175
|
console.log(requestObject);
|
|
@@ -184,8 +184,7 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
184
184
|
} finally {
|
|
185
185
|
await context.agent.siopUpdateAuthRequestState({
|
|
186
186
|
correlationId,
|
|
187
|
-
|
|
188
|
-
state: "sent",
|
|
187
|
+
state: "authorization_request_created",
|
|
189
188
|
error
|
|
190
189
|
});
|
|
191
190
|
}
|
|
@@ -195,192 +194,251 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
195
194
|
});
|
|
196
195
|
}
|
|
197
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");
|
|
198
217
|
|
|
199
|
-
// src/
|
|
200
|
-
var
|
|
218
|
+
// src/universal-oid4vp-api-functions.ts
|
|
219
|
+
var import_did_auth_siop = require("@sphereon/did-auth-siop");
|
|
201
220
|
var import_ssi_express_support2 = require("@sphereon/ssi-express-support");
|
|
202
221
|
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
222
|
var import_short_uuid = __toESM(require("short-uuid"), 1);
|
|
205
|
-
|
|
206
|
-
|
|
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) {
|
|
207
253
|
if (opts?.enabled === false) {
|
|
208
|
-
console.log(`createAuthRequest
|
|
254
|
+
console.log(`createAuthRequest universal OID4VP endpoint is disabled`);
|
|
209
255
|
return;
|
|
210
256
|
}
|
|
211
|
-
const path = opts?.path ?? "/
|
|
212
|
-
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) => {
|
|
213
259
|
try {
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
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
|
+
});
|
|
217
275
|
}
|
|
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
|
|
276
|
+
const requestByReferenceURI = (0, import_ssi_sdk.uriWithBase)(`/siop/queries/${queryId}/auth-requests/${correlationId}`, {
|
|
277
|
+
baseURI: authRequest.requestUriBase ?? opts?.siopBaseURI
|
|
223
278
|
});
|
|
224
|
-
const responseURI = (0, import_ssi_sdk.uriWithBase)(`/siop/
|
|
279
|
+
const responseURI = (0, import_ssi_sdk.uriWithBase)(`/siop/queries/${queryId}/auth-responses/${correlationId}`, {
|
|
225
280
|
baseURI: opts?.siopBaseURI
|
|
226
281
|
});
|
|
227
|
-
const responseRedirectURI = ("response_redirect_uri" in request.body && request.body.response_redirect_uri) ?? ("responseRedirectURI" in request.body && request.body.responseRedirectURI);
|
|
228
282
|
const authRequestURI = await context.agent.siopCreateAuthRequestURI({
|
|
229
|
-
|
|
283
|
+
queryId,
|
|
230
284
|
correlationId,
|
|
231
|
-
state,
|
|
232
285
|
nonce: import_short_uuid.default.uuid(),
|
|
233
286
|
requestByReferenceURI,
|
|
234
287
|
responseURIType: "response_uri",
|
|
235
288
|
responseURI,
|
|
236
|
-
...
|
|
237
|
-
responseRedirectURI
|
|
289
|
+
...authRequest.directPostResponseRedirectUri && {
|
|
290
|
+
responseRedirectURI: authRequest.directPostResponseRedirectUri
|
|
291
|
+
},
|
|
292
|
+
...authRequest.callback && {
|
|
293
|
+
callback: authRequest.callback
|
|
238
294
|
}
|
|
239
295
|
});
|
|
240
296
|
let qrCodeDataUri;
|
|
241
297
|
if (qrCodeOpts) {
|
|
242
298
|
const { AwesomeQR } = await import("awesome-qr");
|
|
243
299
|
const qrCode = new AwesomeQR({
|
|
244
|
-
|
|
245
|
-
|
|
300
|
+
text: authRequestURI,
|
|
301
|
+
size: qrCodeOpts.size ?? 250,
|
|
302
|
+
colorDark: qrCodeOpts.colorDark ?? "#000000",
|
|
303
|
+
colorLight: qrCodeOpts.colorLight ?? "#FFFFFF"
|
|
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")) {
|