@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api 0.34.1-fix.80 → 0.34.1-next.278
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 +233 -141
- 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 +232 -140
- 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 +73 -49
- 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,45 +68,67 @@ 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);
|
|
100
99
|
console.log(`URI: ${JSON.stringify(authorizationResponse)}`);
|
|
101
100
|
const definitionItem = definitionItems[0];
|
|
102
|
-
await context.agent.siopVerifyAuthResponse({
|
|
101
|
+
const verifiedResponse = await context.agent.siopVerifyAuthResponse({
|
|
103
102
|
authorizationResponse,
|
|
104
103
|
correlationId,
|
|
105
|
-
|
|
106
|
-
dcqlQuery: definitionItem.dcqlPayload
|
|
104
|
+
dcqlQuery: definitionItem.query
|
|
107
105
|
});
|
|
106
|
+
const presentation = verifiedResponse?.oid4vpSubmission?.presentation;
|
|
107
|
+
if (presentation && validatePresentationSubmission(definitionItem.query, presentation)) {
|
|
108
|
+
console.log("PRESENTATIONS:" + JSON.stringify(presentation, null, 2));
|
|
109
|
+
response.statusCode = 200;
|
|
110
|
+
const authorizationChallengeValidationResponse = {
|
|
111
|
+
presentation_during_issuance_session: verifiedResponse.correlationId
|
|
112
|
+
};
|
|
113
|
+
if (authorizationResponse.is_first_party) {
|
|
114
|
+
response.setHeader("Content-Type", "application/json");
|
|
115
|
+
return response.send(JSON.stringify(authorizationChallengeValidationResponse));
|
|
116
|
+
}
|
|
117
|
+
const responseRedirectURI = await context.agent.siopGetRedirectURI({
|
|
118
|
+
correlationId,
|
|
119
|
+
state: verifiedResponse.state
|
|
120
|
+
});
|
|
121
|
+
if (responseRedirectURI) {
|
|
122
|
+
response.setHeader("Content-Type", "application/json");
|
|
123
|
+
return response.send(JSON.stringify({
|
|
124
|
+
redirect_uri: responseRedirectURI
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
console.log("Missing Presentation (Verifiable Credentials)");
|
|
129
|
+
response.statusCode = 500;
|
|
130
|
+
response.statusMessage = "Missing Presentation (Verifiable Credentials)";
|
|
131
|
+
}
|
|
108
132
|
return response.send();
|
|
109
133
|
} catch (error) {
|
|
110
134
|
console.error(error);
|
|
@@ -118,24 +142,34 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
118
142
|
console.log(`getAuthRequest SIOP endpoint is disabled`);
|
|
119
143
|
return;
|
|
120
144
|
}
|
|
121
|
-
const path = opts?.path ?? "/siop/
|
|
145
|
+
const path = opts?.path ?? "/siop/queries/:queryId/auth-requests/:correlationId";
|
|
122
146
|
router.get(path, (0, import_ssi_express_support.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
123
147
|
try {
|
|
124
148
|
const correlationId = request.params.correlationId;
|
|
125
|
-
const
|
|
126
|
-
if (!correlationId || !
|
|
127
|
-
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}`);
|
|
128
152
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, "No authorization request could be found");
|
|
129
153
|
}
|
|
130
154
|
const requestState = await context.agent.siopGetAuthRequestState({
|
|
131
155
|
correlationId,
|
|
132
|
-
definitionId,
|
|
133
156
|
errorOnNotFound: false
|
|
134
157
|
});
|
|
135
158
|
if (!requestState) {
|
|
136
|
-
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}`);
|
|
137
160
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, `No authorization request could be found`);
|
|
138
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;
|
|
139
173
|
const requestObject = await requestState.request?.requestObject?.toJwt();
|
|
140
174
|
console.log("JWT Request object:");
|
|
141
175
|
console.log(requestObject);
|
|
@@ -150,8 +184,7 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
150
184
|
} finally {
|
|
151
185
|
await context.agent.siopUpdateAuthRequestState({
|
|
152
186
|
correlationId,
|
|
153
|
-
|
|
154
|
-
state: "sent",
|
|
187
|
+
state: "authorization_request_created",
|
|
155
188
|
error
|
|
156
189
|
});
|
|
157
190
|
}
|
|
@@ -161,192 +194,251 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
161
194
|
});
|
|
162
195
|
}
|
|
163
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");
|
|
164
217
|
|
|
165
|
-
// src/
|
|
218
|
+
// src/universal-oid4vp-api-functions.ts
|
|
166
219
|
var import_did_auth_siop = require("@sphereon/did-auth-siop");
|
|
167
220
|
var import_ssi_express_support2 = require("@sphereon/ssi-express-support");
|
|
168
221
|
var import_ssi_sdk = require("@sphereon/ssi-sdk.siopv2-oid4vp-common");
|
|
169
|
-
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth");
|
|
170
222
|
var import_short_uuid = __toESM(require("short-uuid"), 1);
|
|
171
|
-
|
|
172
|
-
|
|
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) {
|
|
173
253
|
if (opts?.enabled === false) {
|
|
174
|
-
console.log(`createAuthRequest
|
|
254
|
+
console.log(`createAuthRequest universal OID4VP endpoint is disabled`);
|
|
175
255
|
return;
|
|
176
256
|
}
|
|
177
|
-
const path = opts?.path ?? "/
|
|
178
|
-
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) => {
|
|
179
259
|
try {
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
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
|
+
});
|
|
183
275
|
}
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
const qrCodeOpts = request.body.qrCodeOpts ?? opts?.qrCodeOpts;
|
|
187
|
-
const requestByReferenceURI = (0, import_ssi_sdk.uriWithBase)(`/siop/definitions/${definitionId}/auth-requests/${state}`, {
|
|
188
|
-
baseURI: opts?.siopBaseURI
|
|
276
|
+
const requestByReferenceURI = (0, import_ssi_sdk.uriWithBase)(`/siop/queries/${queryId}/auth-requests/${correlationId}`, {
|
|
277
|
+
baseURI: authRequest.requestUriBase ?? opts?.siopBaseURI
|
|
189
278
|
});
|
|
190
|
-
const responseURI = (0, import_ssi_sdk.uriWithBase)(`/siop/
|
|
279
|
+
const responseURI = (0, import_ssi_sdk.uriWithBase)(`/siop/queries/${queryId}/auth-responses/${correlationId}`, {
|
|
191
280
|
baseURI: opts?.siopBaseURI
|
|
192
281
|
});
|
|
193
|
-
const responseRedirectURI = ("response_redirect_uri" in request.body && request.body.response_redirect_uri) ?? ("responseRedirectURI" in request.body && request.body.responseRedirectURI);
|
|
194
282
|
const authRequestURI = await context.agent.siopCreateAuthRequestURI({
|
|
195
|
-
|
|
283
|
+
queryId,
|
|
196
284
|
correlationId,
|
|
197
|
-
state,
|
|
198
285
|
nonce: import_short_uuid.default.uuid(),
|
|
199
286
|
requestByReferenceURI,
|
|
200
287
|
responseURIType: "response_uri",
|
|
201
288
|
responseURI,
|
|
202
|
-
...
|
|
203
|
-
responseRedirectURI
|
|
289
|
+
...authRequest.directPostResponseRedirectUri && {
|
|
290
|
+
responseRedirectURI: authRequest.directPostResponseRedirectUri
|
|
291
|
+
},
|
|
292
|
+
...authRequest.callback && {
|
|
293
|
+
callback: authRequest.callback
|
|
204
294
|
}
|
|
205
295
|
});
|
|
206
296
|
let qrCodeDataUri;
|
|
207
297
|
if (qrCodeOpts) {
|
|
208
298
|
const { AwesomeQR } = await import("awesome-qr");
|
|
209
299
|
const qrCode = new AwesomeQR({
|
|
210
|
-
|
|
211
|
-
|
|
300
|
+
text: authRequestURI,
|
|
301
|
+
size: qrCodeOpts.size ?? 250,
|
|
302
|
+
colorDark: qrCodeOpts.colorDark ?? "#000000",
|
|
303
|
+
colorLight: qrCodeOpts.colorLight ?? "#FFFFFF"
|
|
212
304
|
});
|
|
213
305
|
qrCodeDataUri = `data:image/png;base64,${(await qrCode.draw()).toString("base64")}`;
|
|
306
|
+
} else {
|
|
307
|
+
qrCodeDataUri = authRequestURI;
|
|
214
308
|
}
|
|
215
309
|
const authRequestBody = {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
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}`, {
|
|
221
314
|
baseURI: opts?.webappBaseURI
|
|
222
315
|
})}`,
|
|
223
316
|
...qrCodeDataUri && {
|
|
224
|
-
qrCodeDataUri
|
|
317
|
+
qr_uri: qrCodeDataUri
|
|
225
318
|
}
|
|
226
319
|
};
|
|
227
320
|
console.log(`Auth Request URI data to send back: ${JSON.stringify(authRequestBody)}`);
|
|
228
|
-
return response.json(authRequestBody);
|
|
321
|
+
return response.status(201).json(authRequestBody);
|
|
229
322
|
} catch (error) {
|
|
230
|
-
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);
|
|
231
327
|
}
|
|
232
328
|
});
|
|
233
329
|
}
|
|
234
|
-
__name(
|
|
235
|
-
function
|
|
330
|
+
__name(createAuthRequestUniversalOID4VPEndpoint, "createAuthRequestUniversalOID4VPEndpoint");
|
|
331
|
+
function removeAuthRequestStateUniversalOID4VPEndpoint(router, context, opts) {
|
|
236
332
|
if (opts?.enabled === false) {
|
|
237
|
-
console.log(`
|
|
333
|
+
console.log(`removeAuthStatus universal OID4VP endpoint is disabled`);
|
|
238
334
|
return;
|
|
239
335
|
}
|
|
240
|
-
const path = opts?.path ?? "/
|
|
241
|
-
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) => {
|
|
242
338
|
try {
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
const definitionId = request.body.definitionId;
|
|
246
|
-
const requestState = correlationId && definitionId ? await context.agent.siopGetAuthRequestState({
|
|
339
|
+
const correlationId = request.params.correlationId;
|
|
340
|
+
const authRequestState = await context.agent.siopGetAuthRequestState({
|
|
247
341
|
correlationId,
|
|
248
|
-
definitionId,
|
|
249
342
|
errorOnNotFound: false
|
|
250
|
-
})
|
|
251
|
-
if (!
|
|
252
|
-
console.log(`No
|
|
253
|
-
response
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
correlationId,
|
|
258
|
-
definitionId,
|
|
259
|
-
lastUpdated: requestState ? requestState.lastUpdated : Date.now()
|
|
260
|
-
};
|
|
261
|
-
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
|
+
});
|
|
262
350
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
+
});
|
|
266
384
|
}
|
|
267
385
|
let responseState;
|
|
268
|
-
if (requestState.status ===
|
|
386
|
+
if (requestState.status === import_did_auth_siop.AuthorizationRequestStateStatus.RETRIEVED) {
|
|
269
387
|
responseState = await context.agent.siopGetAuthResponseState({
|
|
270
388
|
correlationId,
|
|
271
|
-
definitionId,
|
|
272
|
-
includeVerifiedData,
|
|
273
389
|
errorOnNotFound: false
|
|
274
390
|
});
|
|
275
391
|
}
|
|
276
392
|
const overallState = responseState ?? requestState;
|
|
277
393
|
const statusBody = {
|
|
278
394
|
status: overallState.status,
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
...
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}),
|
|
289
|
-
verifiedData: responseState.verifiedData
|
|
290
|
-
} : {}
|
|
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
|
+
}
|
|
291
404
|
};
|
|
292
405
|
console.debug(`Will send auth status: ${JSON.stringify(statusBody)}`);
|
|
293
406
|
if (overallState.status === "error") {
|
|
294
|
-
response.
|
|
295
|
-
return response.json(statusBody);
|
|
407
|
+
return response.status(500).json(statusBody);
|
|
296
408
|
}
|
|
297
|
-
response.
|
|
298
|
-
return response.json(statusBody);
|
|
299
|
-
} catch (error) {
|
|
300
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 500, error.message, error);
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
__name(authStatusWebappEndpoint, "authStatusWebappEndpoint");
|
|
305
|
-
function removeAuthRequestStateWebappEndpoint(router, context, opts) {
|
|
306
|
-
if (opts?.enabled === false) {
|
|
307
|
-
console.log(`removeAuthStatus Webapp endpoint is disabled`);
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
const path = opts?.path ?? "/webapp/definitions/:definitionId/auth-requests/:correlationId";
|
|
311
|
-
router.delete(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
312
|
-
try {
|
|
313
|
-
const correlationId = request.params.correlationId;
|
|
314
|
-
const definitionId = request.params.definitionId;
|
|
315
|
-
if (!correlationId || !definitionId) {
|
|
316
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`);
|
|
317
|
-
return (0, import_ssi_express_support2.sendErrorResponse)(response, 404, "No authorization request could be found");
|
|
318
|
-
}
|
|
319
|
-
response.statusCode = 200;
|
|
320
|
-
return response.json(await context.agent.siopDeleteAuthState({
|
|
321
|
-
definitionId,
|
|
322
|
-
correlationId
|
|
323
|
-
}));
|
|
409
|
+
return response.status(200).json(statusBody);
|
|
324
410
|
} catch (error) {
|
|
325
|
-
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);
|
|
326
415
|
}
|
|
327
416
|
});
|
|
328
417
|
}
|
|
329
|
-
__name(
|
|
418
|
+
__name(authStatusUniversalOID4VPEndpoint, "authStatusUniversalOID4VPEndpoint");
|
|
330
419
|
function getDefinitionsEndpoint(router, context, opts) {
|
|
331
420
|
if (opts?.enabled === false) {
|
|
332
|
-
console.log(`getDefinitions
|
|
421
|
+
console.log(`getDefinitions universal OID4VP endpoint is disabled`);
|
|
333
422
|
return;
|
|
334
423
|
}
|
|
335
|
-
const path = opts?.path ?? "/
|
|
424
|
+
const path = opts?.path ?? "/backend/definitions";
|
|
336
425
|
router.get(path, (0, import_ssi_express_support2.checkAuth)(opts?.endpoint), async (request, response) => {
|
|
337
426
|
try {
|
|
338
427
|
const definitions = await context.agent.pdmGetDefinitions();
|
|
339
428
|
response.statusCode = 200;
|
|
340
429
|
return response.json(definitions);
|
|
341
430
|
} catch (error) {
|
|
342
|
-
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);
|
|
343
435
|
}
|
|
344
436
|
});
|
|
345
437
|
}
|
|
346
438
|
__name(getDefinitionsEndpoint, "getDefinitionsEndpoint");
|
|
347
439
|
|
|
348
440
|
// src/siopv2-rp-api-server.ts
|
|
349
|
-
var
|
|
441
|
+
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.core");
|
|
350
442
|
var import_ssi_express_support3 = require("@sphereon/ssi-express-support");
|
|
351
443
|
var import_express = __toESM(require("express"), 1);
|
|
352
444
|
var import_swagger_ui_express = __toESM(require("swagger-ui-express"), 1);
|
|
@@ -383,16 +475,16 @@ var SIOPv2RPApiServer = class {
|
|
|
383
475
|
this._opts = opts;
|
|
384
476
|
this._express = args.expressSupport.express;
|
|
385
477
|
this._router = import_express.default.Router();
|
|
386
|
-
const context = (0,
|
|
478
|
+
const context = (0, import_ssi_sdk2.agentContext)(agent);
|
|
387
479
|
const features = opts?.enableFeatures ?? [
|
|
388
480
|
"rp-status",
|
|
389
481
|
"siop"
|
|
390
482
|
];
|
|
391
483
|
console.log(`SIOPv2 API enabled, with features: ${JSON.stringify(features)}}`);
|
|
392
484
|
if (features.includes("rp-status")) {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
485
|
+
createAuthRequestUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappCreateAuthRequest);
|
|
486
|
+
authStatusUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappAuthStatus);
|
|
487
|
+
removeAuthRequestStateUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappDeleteAuthRequest);
|
|
396
488
|
getDefinitionsEndpoint(this._router, context, opts?.endpointOpts?.webappGetDefinitions);
|
|
397
489
|
}
|
|
398
490
|
if (features.includes("siop")) {
|