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