@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.js
CHANGED
|
@@ -4,13 +4,14 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/siop-api-functions.ts
|
|
5
5
|
import { checkAuth, sendErrorResponse } from "@sphereon/ssi-express-support";
|
|
6
6
|
import { CredentialMapper } from "@sphereon/ssi-types";
|
|
7
|
+
import { validate as isValidUUID } from "uuid";
|
|
7
8
|
var parseAuthorizationResponse = /* @__PURE__ */ __name((request) => {
|
|
8
9
|
const contentType = request.header("content-type");
|
|
9
|
-
if (contentType
|
|
10
|
+
if (contentType?.startsWith("application/json")) {
|
|
10
11
|
const payload = typeof request.body === "string" ? JSON.parse(request.body) : request.body;
|
|
11
12
|
return payload;
|
|
12
13
|
}
|
|
13
|
-
if (contentType
|
|
14
|
+
if (contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
14
15
|
const payload = request.body;
|
|
15
16
|
if (typeof payload.presentation_submission === "string") {
|
|
16
17
|
console.log(`Supplied presentation_submission was a string instead of JSON. Correcting, but external party should fix their implementation!`);
|
|
@@ -26,34 +27,31 @@ var parseAuthorizationResponse = /* @__PURE__ */ __name((request) => {
|
|
|
26
27
|
}
|
|
27
28
|
throw new Error(`Unsupported content type: ${contentType}. Currently only application/x-www-form-urlencoded and application/json (for direct_post) are supported`);
|
|
28
29
|
}, "parseAuthorizationResponse");
|
|
30
|
+
var validatePresentationSubmission = /* @__PURE__ */ __name((query, submission) => {
|
|
31
|
+
return query.credentials.every((credential) => credential.id in submission);
|
|
32
|
+
}, "validatePresentationSubmission");
|
|
29
33
|
function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
30
34
|
if (opts?.enabled === false) {
|
|
31
35
|
console.log(`verifyAuthResponse SIOP endpoint is disabled`);
|
|
32
36
|
return;
|
|
33
37
|
}
|
|
34
|
-
const path = opts?.path ?? "/siop/
|
|
38
|
+
const path = opts?.path ?? "/siop/queries/:queryId/auth-responses/:correlationId";
|
|
35
39
|
router.post(path, checkAuth(opts?.endpoint), async (request, response) => {
|
|
36
40
|
try {
|
|
37
|
-
const { correlationId,
|
|
38
|
-
if (!correlationId
|
|
39
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}
|
|
41
|
+
const { correlationId, queryId, tenantId, version } = request.params;
|
|
42
|
+
if (!correlationId) {
|
|
43
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}`);
|
|
40
44
|
return sendErrorResponse(response, 404, "No authorization request could be found");
|
|
41
45
|
}
|
|
42
|
-
console.
|
|
43
|
-
console.
|
|
46
|
+
console.debug("Authorization Response (siop-sessions");
|
|
47
|
+
console.debug(JSON.stringify(request.body, null, 2));
|
|
44
48
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
45
|
-
filter:
|
|
46
|
-
{
|
|
47
|
-
definitionId,
|
|
48
|
-
tenantId,
|
|
49
|
-
version
|
|
50
|
-
}
|
|
51
|
-
]
|
|
49
|
+
filter: buildQueryIdFilter(queryId, tenantId, version)
|
|
52
50
|
});
|
|
53
51
|
if (definitionItems.length === 0) {
|
|
54
|
-
console.log(`Could not get
|
|
52
|
+
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`);
|
|
55
53
|
response.statusCode = 404;
|
|
56
|
-
response.statusMessage = `No definition ${
|
|
54
|
+
response.statusMessage = `No definition ${queryId}`;
|
|
57
55
|
return response.send();
|
|
58
56
|
}
|
|
59
57
|
const authorizationResponse = parseAuthorizationResponse(request);
|
|
@@ -62,12 +60,11 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
62
60
|
const verifiedResponse = await context.agent.siopVerifyAuthResponse({
|
|
63
61
|
authorizationResponse,
|
|
64
62
|
correlationId,
|
|
65
|
-
|
|
66
|
-
dcqlQuery: definitionItem.dcqlPayload
|
|
63
|
+
dcqlQuery: definitionItem.query
|
|
67
64
|
});
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
70
|
-
console.log("
|
|
65
|
+
const presentation = verifiedResponse?.oid4vpSubmission?.presentation;
|
|
66
|
+
if (presentation && validatePresentationSubmission(definitionItem.query, presentation)) {
|
|
67
|
+
console.log("PRESENTATIONS:" + JSON.stringify(presentation, null, 2));
|
|
71
68
|
response.statusCode = 200;
|
|
72
69
|
const authorizationChallengeValidationResponse = {
|
|
73
70
|
presentation_during_issuance_session: verifiedResponse.correlationId
|
|
@@ -78,7 +75,6 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
78
75
|
}
|
|
79
76
|
const responseRedirectURI = await context.agent.siopGetRedirectURI({
|
|
80
77
|
correlationId,
|
|
81
|
-
definitionId,
|
|
82
78
|
state: verifiedResponse.state
|
|
83
79
|
});
|
|
84
80
|
if (responseRedirectURI) {
|
|
@@ -105,24 +101,34 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
105
101
|
console.log(`getAuthRequest SIOP endpoint is disabled`);
|
|
106
102
|
return;
|
|
107
103
|
}
|
|
108
|
-
const path = opts?.path ?? "/siop/
|
|
104
|
+
const path = opts?.path ?? "/siop/queries/:queryId/auth-requests/:correlationId";
|
|
109
105
|
router.get(path, checkAuth(opts?.endpoint), async (request, response) => {
|
|
110
106
|
try {
|
|
111
107
|
const correlationId = request.params.correlationId;
|
|
112
|
-
const
|
|
113
|
-
if (!correlationId || !
|
|
114
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId},
|
|
108
|
+
const queryId = request.params.queryId;
|
|
109
|
+
if (!correlationId || !queryId) {
|
|
110
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, queryId: ${queryId}`);
|
|
115
111
|
return sendErrorResponse(response, 404, "No authorization request could be found");
|
|
116
112
|
}
|
|
117
113
|
const requestState = await context.agent.siopGetAuthRequestState({
|
|
118
114
|
correlationId,
|
|
119
|
-
definitionId,
|
|
120
115
|
errorOnNotFound: false
|
|
121
116
|
});
|
|
122
117
|
if (!requestState) {
|
|
123
|
-
console.log(`No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${
|
|
118
|
+
console.log(`No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${queryId}`);
|
|
124
119
|
return sendErrorResponse(response, 404, `No authorization request could be found`);
|
|
125
120
|
}
|
|
121
|
+
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
122
|
+
filter: buildQueryIdFilter(queryId)
|
|
123
|
+
});
|
|
124
|
+
if (definitionItems.length === 0) {
|
|
125
|
+
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`);
|
|
126
|
+
response.statusCode = 404;
|
|
127
|
+
response.statusMessage = `No definition ${queryId}`;
|
|
128
|
+
return response.send();
|
|
129
|
+
}
|
|
130
|
+
const payload = requestState.request?.requestObject?.getPayload();
|
|
131
|
+
payload.dcql_query = definitionItems[0].query;
|
|
126
132
|
const requestObject = await requestState.request?.requestObject?.toJwt();
|
|
127
133
|
console.log("JWT Request object:");
|
|
128
134
|
console.log(requestObject);
|
|
@@ -137,8 +143,7 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
137
143
|
} finally {
|
|
138
144
|
await context.agent.siopUpdateAuthRequestState({
|
|
139
145
|
correlationId,
|
|
140
|
-
|
|
141
|
-
state: "sent",
|
|
146
|
+
state: "authorization_request_created",
|
|
142
147
|
error
|
|
143
148
|
});
|
|
144
149
|
}
|
|
@@ -148,185 +153,244 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
148
153
|
});
|
|
149
154
|
}
|
|
150
155
|
__name(getAuthRequestSIOPv2Endpoint, "getAuthRequestSIOPv2Endpoint");
|
|
156
|
+
function buildQueryIdFilter(queryId, tenantId, version) {
|
|
157
|
+
const queryFilter = {
|
|
158
|
+
queryId,
|
|
159
|
+
...tenantId ? {
|
|
160
|
+
tenantId
|
|
161
|
+
} : {},
|
|
162
|
+
...version ? {
|
|
163
|
+
version
|
|
164
|
+
} : {}
|
|
165
|
+
};
|
|
166
|
+
return [
|
|
167
|
+
queryFilter,
|
|
168
|
+
...isValidUUID(queryId) ? [
|
|
169
|
+
{
|
|
170
|
+
id: queryId
|
|
171
|
+
}
|
|
172
|
+
] : []
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
__name(buildQueryIdFilter, "buildQueryIdFilter");
|
|
151
176
|
|
|
152
|
-
// src/
|
|
153
|
-
import {
|
|
177
|
+
// src/universal-oid4vp-api-functions.ts
|
|
178
|
+
import { AuthorizationRequestStateStatus, createAuthorizationRequestFromPayload, CreateAuthorizationRequestPayloadSchema } from "@sphereon/did-auth-siop";
|
|
154
179
|
import { checkAuth as checkAuth2, sendErrorResponse as sendErrorResponse2 } from "@sphereon/ssi-express-support";
|
|
155
180
|
import { uriWithBase } from "@sphereon/ssi-sdk.siopv2-oid4vp-common";
|
|
156
|
-
import { VerifiedDataMode } from "@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth";
|
|
157
181
|
import uuid from "short-uuid";
|
|
158
|
-
|
|
159
|
-
|
|
182
|
+
|
|
183
|
+
// src/middleware/validationMiddleware.ts
|
|
184
|
+
import { ZodError } from "zod";
|
|
185
|
+
var validateData = /* @__PURE__ */ __name((schema) => {
|
|
186
|
+
return (req, res, next) => {
|
|
187
|
+
try {
|
|
188
|
+
schema.parse(req.body);
|
|
189
|
+
next();
|
|
190
|
+
} catch (error) {
|
|
191
|
+
if (error instanceof ZodError) {
|
|
192
|
+
const errorMessages = error.issues.map((issue) => ({
|
|
193
|
+
message: `${issue.path.join(".")} is ${issue.message}`
|
|
194
|
+
}));
|
|
195
|
+
res.status(400).json({
|
|
196
|
+
status: 400,
|
|
197
|
+
message: "Invalid data",
|
|
198
|
+
error_details: errorMessages[0].message
|
|
199
|
+
});
|
|
200
|
+
} else {
|
|
201
|
+
res.status(500).json({
|
|
202
|
+
status: 500,
|
|
203
|
+
message: "Internal Server Error"
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}, "validateData");
|
|
209
|
+
|
|
210
|
+
// src/universal-oid4vp-api-functions.ts
|
|
211
|
+
function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
160
212
|
if (opts?.enabled === false) {
|
|
161
|
-
console.log(`createAuthRequest
|
|
213
|
+
console.log(`createAuthRequest universal OID4VP endpoint is disabled`);
|
|
162
214
|
return;
|
|
163
215
|
}
|
|
164
|
-
const path = opts?.path ?? "/
|
|
165
|
-
router.post(path, checkAuth2(opts?.endpoint), async (request, response) => {
|
|
216
|
+
const path = opts?.path ?? "/backend/auth/requests";
|
|
217
|
+
router.post(path, checkAuth2(opts?.endpoint), validateData(CreateAuthorizationRequestPayloadSchema), async (request, response) => {
|
|
166
218
|
try {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
219
|
+
const authRequest = createAuthorizationRequestFromPayload(request.body);
|
|
220
|
+
const correlationId = authRequest.correlationId ?? uuid.uuid();
|
|
221
|
+
const qrCodeOpts = authRequest.qrCode ? {
|
|
222
|
+
...authRequest.qrCode
|
|
223
|
+
} : opts?.qrCodeOpts;
|
|
224
|
+
const queryId = authRequest.queryId;
|
|
225
|
+
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
226
|
+
filter: buildQueryIdFilter(queryId)
|
|
227
|
+
});
|
|
228
|
+
if (definitionItems.length === 0) {
|
|
229
|
+
console.log(`No query could be found for the given id. Query id: ${queryId}`);
|
|
230
|
+
return sendErrorResponse2(response, 404, {
|
|
231
|
+
status: 404,
|
|
232
|
+
message: "No query could be found"
|
|
233
|
+
});
|
|
170
234
|
}
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
const qrCodeOpts = request.body.qrCodeOpts ?? opts?.qrCodeOpts;
|
|
174
|
-
const requestByReferenceURI = uriWithBase(`/siop/definitions/${definitionId}/auth-requests/${state}`, {
|
|
175
|
-
baseURI: opts?.siopBaseURI
|
|
235
|
+
const requestByReferenceURI = uriWithBase(`/siop/queries/${queryId}/auth-requests/${correlationId}`, {
|
|
236
|
+
baseURI: authRequest.requestUriBase ?? opts?.siopBaseURI
|
|
176
237
|
});
|
|
177
|
-
const responseURI = uriWithBase(`/siop/
|
|
238
|
+
const responseURI = uriWithBase(`/siop/queries/${queryId}/auth-responses/${correlationId}`, {
|
|
178
239
|
baseURI: opts?.siopBaseURI
|
|
179
240
|
});
|
|
180
|
-
const responseRedirectURI = ("response_redirect_uri" in request.body && request.body.response_redirect_uri) ?? ("responseRedirectURI" in request.body && request.body.responseRedirectURI);
|
|
181
241
|
const authRequestURI = await context.agent.siopCreateAuthRequestURI({
|
|
182
|
-
|
|
242
|
+
queryId,
|
|
183
243
|
correlationId,
|
|
184
|
-
state,
|
|
185
244
|
nonce: uuid.uuid(),
|
|
186
245
|
requestByReferenceURI,
|
|
187
246
|
responseURIType: "response_uri",
|
|
188
247
|
responseURI,
|
|
189
|
-
...
|
|
190
|
-
responseRedirectURI
|
|
248
|
+
...authRequest.directPostResponseRedirectUri && {
|
|
249
|
+
responseRedirectURI: authRequest.directPostResponseRedirectUri
|
|
250
|
+
},
|
|
251
|
+
...authRequest.callback && {
|
|
252
|
+
callback: authRequest.callback
|
|
191
253
|
}
|
|
192
254
|
});
|
|
193
255
|
let qrCodeDataUri;
|
|
194
256
|
if (qrCodeOpts) {
|
|
195
257
|
const { AwesomeQR } = await import("awesome-qr");
|
|
196
258
|
const qrCode = new AwesomeQR({
|
|
197
|
-
|
|
198
|
-
|
|
259
|
+
text: authRequestURI,
|
|
260
|
+
size: qrCodeOpts.size ?? 250,
|
|
261
|
+
colorDark: qrCodeOpts.colorDark ?? "#000000",
|
|
262
|
+
colorLight: qrCodeOpts.colorLight ?? "#FFFFFF"
|
|
199
263
|
});
|
|
200
264
|
qrCodeDataUri = `data:image/png;base64,${(await qrCode.draw()).toString("base64")}`;
|
|
265
|
+
} else {
|
|
266
|
+
qrCodeDataUri = authRequestURI;
|
|
201
267
|
}
|
|
202
268
|
const authRequestBody = {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
authStatusURI: `${uriWithBase(opts?.webappAuthStatusPath ?? "/webapp/auth-status", {
|
|
269
|
+
query_id: queryId,
|
|
270
|
+
correlation_id: correlationId,
|
|
271
|
+
request_uri: authRequestURI,
|
|
272
|
+
status_uri: `${uriWithBase(opts?.webappAuthStatusPath ?? `/backend/auth/status/${correlationId}`, {
|
|
208
273
|
baseURI: opts?.webappBaseURI
|
|
209
274
|
})}`,
|
|
210
275
|
...qrCodeDataUri && {
|
|
211
|
-
qrCodeDataUri
|
|
276
|
+
qr_uri: qrCodeDataUri
|
|
212
277
|
}
|
|
213
278
|
};
|
|
214
279
|
console.log(`Auth Request URI data to send back: ${JSON.stringify(authRequestBody)}`);
|
|
215
|
-
return response.json(authRequestBody);
|
|
280
|
+
return response.status(201).json(authRequestBody);
|
|
216
281
|
} catch (error) {
|
|
217
|
-
return sendErrorResponse2(response, 500,
|
|
282
|
+
return sendErrorResponse2(response, 500, {
|
|
283
|
+
status: 500,
|
|
284
|
+
message: "Could not create an authorization request URI"
|
|
285
|
+
}, error);
|
|
218
286
|
}
|
|
219
287
|
});
|
|
220
288
|
}
|
|
221
|
-
__name(
|
|
222
|
-
function
|
|
289
|
+
__name(createAuthRequestUniversalOID4VPEndpoint, "createAuthRequestUniversalOID4VPEndpoint");
|
|
290
|
+
function removeAuthRequestStateUniversalOID4VPEndpoint(router, context, opts) {
|
|
223
291
|
if (opts?.enabled === false) {
|
|
224
|
-
console.log(`
|
|
292
|
+
console.log(`removeAuthStatus universal OID4VP endpoint is disabled`);
|
|
225
293
|
return;
|
|
226
294
|
}
|
|
227
|
-
const path = opts?.path ?? "/
|
|
228
|
-
router.
|
|
295
|
+
const path = opts?.path ?? "/backend/auth/requests/:correlationId";
|
|
296
|
+
router.delete(path, checkAuth2(opts?.endpoint), async (request, response) => {
|
|
229
297
|
try {
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
const definitionId = request.body.definitionId;
|
|
233
|
-
const requestState = correlationId && definitionId ? await context.agent.siopGetAuthRequestState({
|
|
298
|
+
const correlationId = request.params.correlationId;
|
|
299
|
+
const authRequestState = await context.agent.siopGetAuthRequestState({
|
|
234
300
|
correlationId,
|
|
235
|
-
definitionId,
|
|
236
301
|
errorOnNotFound: false
|
|
237
|
-
})
|
|
238
|
-
if (!
|
|
239
|
-
console.log(`No
|
|
240
|
-
response
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
correlationId,
|
|
245
|
-
definitionId,
|
|
246
|
-
lastUpdated: requestState ? requestState.lastUpdated : Date.now()
|
|
247
|
-
};
|
|
248
|
-
return response.json(statusBody2);
|
|
302
|
+
});
|
|
303
|
+
if (!authRequestState) {
|
|
304
|
+
console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`);
|
|
305
|
+
return sendErrorResponse2(response, 404, {
|
|
306
|
+
status: 404,
|
|
307
|
+
message: "No authorization request could be found"
|
|
308
|
+
});
|
|
249
309
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
310
|
+
await context.agent.siopDeleteAuthState({
|
|
311
|
+
correlationId
|
|
312
|
+
});
|
|
313
|
+
return response.status(204).json();
|
|
314
|
+
} catch (error) {
|
|
315
|
+
return sendErrorResponse2(response, 500, {
|
|
316
|
+
status: 500,
|
|
317
|
+
message: error.message
|
|
318
|
+
}, error);
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
__name(removeAuthRequestStateUniversalOID4VPEndpoint, "removeAuthRequestStateUniversalOID4VPEndpoint");
|
|
323
|
+
function authStatusUniversalOID4VPEndpoint(router, context, opts) {
|
|
324
|
+
if (opts?.enabled === false) {
|
|
325
|
+
console.log(`authStatus universal OID4VP endpoint is disabled`);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const path = opts?.path ?? "/backend/auth/status/:correlationId";
|
|
329
|
+
router.get(path, checkAuth2(opts?.endpoint), async (request, response) => {
|
|
330
|
+
try {
|
|
331
|
+
console.log("Received auth-status request...");
|
|
332
|
+
const correlationId = request.params.correlationId;
|
|
333
|
+
const requestState = await context.agent.siopGetAuthRequestState({
|
|
334
|
+
correlationId,
|
|
335
|
+
errorOnNotFound: false
|
|
336
|
+
});
|
|
337
|
+
if (!requestState) {
|
|
338
|
+
console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`);
|
|
339
|
+
return sendErrorResponse2(response, 404, {
|
|
340
|
+
status: 404,
|
|
341
|
+
message: "No authorization request could be found"
|
|
342
|
+
});
|
|
253
343
|
}
|
|
254
344
|
let responseState;
|
|
255
|
-
if (requestState.status ===
|
|
345
|
+
if (requestState.status === AuthorizationRequestStateStatus.RETRIEVED) {
|
|
256
346
|
responseState = await context.agent.siopGetAuthResponseState({
|
|
257
347
|
correlationId,
|
|
258
|
-
definitionId,
|
|
259
|
-
includeVerifiedData,
|
|
260
348
|
errorOnNotFound: false
|
|
261
349
|
});
|
|
262
350
|
}
|
|
263
351
|
const overallState = responseState ?? requestState;
|
|
264
352
|
const statusBody = {
|
|
265
353
|
status: overallState.status,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
...
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}),
|
|
276
|
-
verifiedData: responseState.verifiedData
|
|
277
|
-
} : {}
|
|
354
|
+
correlation_id: overallState.correlationId,
|
|
355
|
+
query_id: overallState.queryId,
|
|
356
|
+
last_updated: overallState.lastUpdated,
|
|
357
|
+
..."verifiedData" in overallState && {
|
|
358
|
+
verified_data: overallState.verifiedData
|
|
359
|
+
},
|
|
360
|
+
...overallState.error && {
|
|
361
|
+
message: overallState.error.message
|
|
362
|
+
}
|
|
278
363
|
};
|
|
279
364
|
console.debug(`Will send auth status: ${JSON.stringify(statusBody)}`);
|
|
280
365
|
if (overallState.status === "error") {
|
|
281
|
-
response.
|
|
282
|
-
return response.json(statusBody);
|
|
366
|
+
return response.status(500).json(statusBody);
|
|
283
367
|
}
|
|
284
|
-
response.
|
|
285
|
-
return response.json(statusBody);
|
|
286
|
-
} catch (error) {
|
|
287
|
-
return sendErrorResponse2(response, 500, error.message, error);
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
__name(authStatusWebappEndpoint, "authStatusWebappEndpoint");
|
|
292
|
-
function removeAuthRequestStateWebappEndpoint(router, context, opts) {
|
|
293
|
-
if (opts?.enabled === false) {
|
|
294
|
-
console.log(`removeAuthStatus Webapp endpoint is disabled`);
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
const path = opts?.path ?? "/webapp/definitions/:definitionId/auth-requests/:correlationId";
|
|
298
|
-
router.delete(path, checkAuth2(opts?.endpoint), async (request, response) => {
|
|
299
|
-
try {
|
|
300
|
-
const correlationId = request.params.correlationId;
|
|
301
|
-
const definitionId = request.params.definitionId;
|
|
302
|
-
if (!correlationId || !definitionId) {
|
|
303
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`);
|
|
304
|
-
return sendErrorResponse2(response, 404, "No authorization request could be found");
|
|
305
|
-
}
|
|
306
|
-
response.statusCode = 200;
|
|
307
|
-
return response.json(await context.agent.siopDeleteAuthState({
|
|
308
|
-
definitionId,
|
|
309
|
-
correlationId
|
|
310
|
-
}));
|
|
368
|
+
return response.status(200).json(statusBody);
|
|
311
369
|
} catch (error) {
|
|
312
|
-
return sendErrorResponse2(response, 500,
|
|
370
|
+
return sendErrorResponse2(response, 500, {
|
|
371
|
+
status: 500,
|
|
372
|
+
message: error.message
|
|
373
|
+
}, error);
|
|
313
374
|
}
|
|
314
375
|
});
|
|
315
376
|
}
|
|
316
|
-
__name(
|
|
377
|
+
__name(authStatusUniversalOID4VPEndpoint, "authStatusUniversalOID4VPEndpoint");
|
|
317
378
|
function getDefinitionsEndpoint(router, context, opts) {
|
|
318
379
|
if (opts?.enabled === false) {
|
|
319
|
-
console.log(`getDefinitions
|
|
380
|
+
console.log(`getDefinitions universal OID4VP endpoint is disabled`);
|
|
320
381
|
return;
|
|
321
382
|
}
|
|
322
|
-
const path = opts?.path ?? "/
|
|
383
|
+
const path = opts?.path ?? "/backend/definitions";
|
|
323
384
|
router.get(path, checkAuth2(opts?.endpoint), async (request, response) => {
|
|
324
385
|
try {
|
|
325
386
|
const definitions = await context.agent.pdmGetDefinitions();
|
|
326
387
|
response.statusCode = 200;
|
|
327
388
|
return response.json(definitions);
|
|
328
389
|
} catch (error) {
|
|
329
|
-
return sendErrorResponse2(response, 500,
|
|
390
|
+
return sendErrorResponse2(response, 500, {
|
|
391
|
+
status: 500,
|
|
392
|
+
message: error.message
|
|
393
|
+
}, error);
|
|
330
394
|
}
|
|
331
395
|
});
|
|
332
396
|
}
|
|
@@ -377,9 +441,9 @@ var SIOPv2RPApiServer = class {
|
|
|
377
441
|
];
|
|
378
442
|
console.log(`SIOPv2 API enabled, with features: ${JSON.stringify(features)}}`);
|
|
379
443
|
if (features.includes("rp-status")) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
444
|
+
createAuthRequestUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappCreateAuthRequest);
|
|
445
|
+
authStatusUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappAuthStatus);
|
|
446
|
+
removeAuthRequestStateUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappDeleteAuthRequest);
|
|
383
447
|
getDefinitionsEndpoint(this._router, context, opts?.endpointOpts?.webappGetDefinitions);
|
|
384
448
|
}
|
|
385
449
|
if (features.includes("siop")) {
|
|
@@ -426,11 +490,12 @@ var SIOPv2RPApiServer = class {
|
|
|
426
490
|
};
|
|
427
491
|
export {
|
|
428
492
|
SIOPv2RPApiServer,
|
|
429
|
-
|
|
430
|
-
|
|
493
|
+
authStatusUniversalOID4VPEndpoint,
|
|
494
|
+
buildQueryIdFilter,
|
|
495
|
+
createAuthRequestUniversalOID4VPEndpoint,
|
|
431
496
|
getAuthRequestSIOPv2Endpoint,
|
|
432
497
|
getDefinitionsEndpoint,
|
|
433
|
-
|
|
498
|
+
removeAuthRequestStateUniversalOID4VPEndpoint,
|
|
434
499
|
verifyAuthResponseSIOPv2Endpoint
|
|
435
500
|
};
|
|
436
501
|
//# sourceMappingURL=index.js.map
|