@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api 0.34.1-fix.79 → 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.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,45 +27,67 @@ 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);
|
|
60
58
|
console.log(`URI: ${JSON.stringify(authorizationResponse)}`);
|
|
61
59
|
const definitionItem = definitionItems[0];
|
|
62
|
-
await context.agent.siopVerifyAuthResponse({
|
|
60
|
+
const verifiedResponse = await context.agent.siopVerifyAuthResponse({
|
|
63
61
|
authorizationResponse,
|
|
64
62
|
correlationId,
|
|
65
|
-
|
|
66
|
-
dcqlQuery: definitionItem.dcqlPayload
|
|
63
|
+
dcqlQuery: definitionItem.query
|
|
67
64
|
});
|
|
65
|
+
const presentation = verifiedResponse?.oid4vpSubmission?.presentation;
|
|
66
|
+
if (presentation && validatePresentationSubmission(definitionItem.query, presentation)) {
|
|
67
|
+
console.log("PRESENTATIONS:" + JSON.stringify(presentation, null, 2));
|
|
68
|
+
response.statusCode = 200;
|
|
69
|
+
const authorizationChallengeValidationResponse = {
|
|
70
|
+
presentation_during_issuance_session: verifiedResponse.correlationId
|
|
71
|
+
};
|
|
72
|
+
if (authorizationResponse.is_first_party) {
|
|
73
|
+
response.setHeader("Content-Type", "application/json");
|
|
74
|
+
return response.send(JSON.stringify(authorizationChallengeValidationResponse));
|
|
75
|
+
}
|
|
76
|
+
const responseRedirectURI = await context.agent.siopGetRedirectURI({
|
|
77
|
+
correlationId,
|
|
78
|
+
state: verifiedResponse.state
|
|
79
|
+
});
|
|
80
|
+
if (responseRedirectURI) {
|
|
81
|
+
response.setHeader("Content-Type", "application/json");
|
|
82
|
+
return response.send(JSON.stringify({
|
|
83
|
+
redirect_uri: responseRedirectURI
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
console.log("Missing Presentation (Verifiable Credentials)");
|
|
88
|
+
response.statusCode = 500;
|
|
89
|
+
response.statusMessage = "Missing Presentation (Verifiable Credentials)";
|
|
90
|
+
}
|
|
68
91
|
return response.send();
|
|
69
92
|
} catch (error) {
|
|
70
93
|
console.error(error);
|
|
@@ -78,24 +101,34 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
78
101
|
console.log(`getAuthRequest SIOP endpoint is disabled`);
|
|
79
102
|
return;
|
|
80
103
|
}
|
|
81
|
-
const path = opts?.path ?? "/siop/
|
|
104
|
+
const path = opts?.path ?? "/siop/queries/:queryId/auth-requests/:correlationId";
|
|
82
105
|
router.get(path, checkAuth(opts?.endpoint), async (request, response) => {
|
|
83
106
|
try {
|
|
84
107
|
const correlationId = request.params.correlationId;
|
|
85
|
-
const
|
|
86
|
-
if (!correlationId || !
|
|
87
|
-
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}`);
|
|
88
111
|
return sendErrorResponse(response, 404, "No authorization request could be found");
|
|
89
112
|
}
|
|
90
113
|
const requestState = await context.agent.siopGetAuthRequestState({
|
|
91
114
|
correlationId,
|
|
92
|
-
definitionId,
|
|
93
115
|
errorOnNotFound: false
|
|
94
116
|
});
|
|
95
117
|
if (!requestState) {
|
|
96
|
-
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}`);
|
|
97
119
|
return sendErrorResponse(response, 404, `No authorization request could be found`);
|
|
98
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;
|
|
99
132
|
const requestObject = await requestState.request?.requestObject?.toJwt();
|
|
100
133
|
console.log("JWT Request object:");
|
|
101
134
|
console.log(requestObject);
|
|
@@ -110,8 +143,7 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
110
143
|
} finally {
|
|
111
144
|
await context.agent.siopUpdateAuthRequestState({
|
|
112
145
|
correlationId,
|
|
113
|
-
|
|
114
|
-
state: "sent",
|
|
146
|
+
state: "authorization_request_created",
|
|
115
147
|
error
|
|
116
148
|
});
|
|
117
149
|
}
|
|
@@ -121,185 +153,244 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
121
153
|
});
|
|
122
154
|
}
|
|
123
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");
|
|
124
176
|
|
|
125
|
-
// src/
|
|
126
|
-
import {
|
|
177
|
+
// src/universal-oid4vp-api-functions.ts
|
|
178
|
+
import { AuthorizationRequestStateStatus, createAuthorizationRequestFromPayload, CreateAuthorizationRequestPayloadSchema } from "@sphereon/did-auth-siop";
|
|
127
179
|
import { checkAuth as checkAuth2, sendErrorResponse as sendErrorResponse2 } from "@sphereon/ssi-express-support";
|
|
128
180
|
import { uriWithBase } from "@sphereon/ssi-sdk.siopv2-oid4vp-common";
|
|
129
|
-
import { VerifiedDataMode } from "@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth";
|
|
130
181
|
import uuid from "short-uuid";
|
|
131
|
-
|
|
132
|
-
|
|
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) {
|
|
133
212
|
if (opts?.enabled === false) {
|
|
134
|
-
console.log(`createAuthRequest
|
|
213
|
+
console.log(`createAuthRequest universal OID4VP endpoint is disabled`);
|
|
135
214
|
return;
|
|
136
215
|
}
|
|
137
|
-
const path = opts?.path ?? "/
|
|
138
|
-
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) => {
|
|
139
218
|
try {
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
});
|
|
143
234
|
}
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
const qrCodeOpts = request.body.qrCodeOpts ?? opts?.qrCodeOpts;
|
|
147
|
-
const requestByReferenceURI = uriWithBase(`/siop/definitions/${definitionId}/auth-requests/${state}`, {
|
|
148
|
-
baseURI: opts?.siopBaseURI
|
|
235
|
+
const requestByReferenceURI = uriWithBase(`/siop/queries/${queryId}/auth-requests/${correlationId}`, {
|
|
236
|
+
baseURI: authRequest.requestUriBase ?? opts?.siopBaseURI
|
|
149
237
|
});
|
|
150
|
-
const responseURI = uriWithBase(`/siop/
|
|
238
|
+
const responseURI = uriWithBase(`/siop/queries/${queryId}/auth-responses/${correlationId}`, {
|
|
151
239
|
baseURI: opts?.siopBaseURI
|
|
152
240
|
});
|
|
153
|
-
const responseRedirectURI = ("response_redirect_uri" in request.body && request.body.response_redirect_uri) ?? ("responseRedirectURI" in request.body && request.body.responseRedirectURI);
|
|
154
241
|
const authRequestURI = await context.agent.siopCreateAuthRequestURI({
|
|
155
|
-
|
|
242
|
+
queryId,
|
|
156
243
|
correlationId,
|
|
157
|
-
state,
|
|
158
244
|
nonce: uuid.uuid(),
|
|
159
245
|
requestByReferenceURI,
|
|
160
246
|
responseURIType: "response_uri",
|
|
161
247
|
responseURI,
|
|
162
|
-
...
|
|
163
|
-
responseRedirectURI
|
|
248
|
+
...authRequest.directPostResponseRedirectUri && {
|
|
249
|
+
responseRedirectURI: authRequest.directPostResponseRedirectUri
|
|
250
|
+
},
|
|
251
|
+
...authRequest.callback && {
|
|
252
|
+
callback: authRequest.callback
|
|
164
253
|
}
|
|
165
254
|
});
|
|
166
255
|
let qrCodeDataUri;
|
|
167
256
|
if (qrCodeOpts) {
|
|
168
257
|
const { AwesomeQR } = await import("awesome-qr");
|
|
169
258
|
const qrCode = new AwesomeQR({
|
|
170
|
-
|
|
171
|
-
|
|
259
|
+
text: authRequestURI,
|
|
260
|
+
size: qrCodeOpts.size ?? 250,
|
|
261
|
+
colorDark: qrCodeOpts.colorDark ?? "#000000",
|
|
262
|
+
colorLight: qrCodeOpts.colorLight ?? "#FFFFFF"
|
|
172
263
|
});
|
|
173
264
|
qrCodeDataUri = `data:image/png;base64,${(await qrCode.draw()).toString("base64")}`;
|
|
265
|
+
} else {
|
|
266
|
+
qrCodeDataUri = authRequestURI;
|
|
174
267
|
}
|
|
175
268
|
const authRequestBody = {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
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}`, {
|
|
181
273
|
baseURI: opts?.webappBaseURI
|
|
182
274
|
})}`,
|
|
183
275
|
...qrCodeDataUri && {
|
|
184
|
-
qrCodeDataUri
|
|
276
|
+
qr_uri: qrCodeDataUri
|
|
185
277
|
}
|
|
186
278
|
};
|
|
187
279
|
console.log(`Auth Request URI data to send back: ${JSON.stringify(authRequestBody)}`);
|
|
188
|
-
return response.json(authRequestBody);
|
|
280
|
+
return response.status(201).json(authRequestBody);
|
|
189
281
|
} catch (error) {
|
|
190
|
-
return sendErrorResponse2(response, 500,
|
|
282
|
+
return sendErrorResponse2(response, 500, {
|
|
283
|
+
status: 500,
|
|
284
|
+
message: "Could not create an authorization request URI"
|
|
285
|
+
}, error);
|
|
191
286
|
}
|
|
192
287
|
});
|
|
193
288
|
}
|
|
194
|
-
__name(
|
|
195
|
-
function
|
|
289
|
+
__name(createAuthRequestUniversalOID4VPEndpoint, "createAuthRequestUniversalOID4VPEndpoint");
|
|
290
|
+
function removeAuthRequestStateUniversalOID4VPEndpoint(router, context, opts) {
|
|
196
291
|
if (opts?.enabled === false) {
|
|
197
|
-
console.log(`
|
|
292
|
+
console.log(`removeAuthStatus universal OID4VP endpoint is disabled`);
|
|
198
293
|
return;
|
|
199
294
|
}
|
|
200
|
-
const path = opts?.path ?? "/
|
|
201
|
-
router.
|
|
295
|
+
const path = opts?.path ?? "/backend/auth/requests/:correlationId";
|
|
296
|
+
router.delete(path, checkAuth2(opts?.endpoint), async (request, response) => {
|
|
202
297
|
try {
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
const definitionId = request.body.definitionId;
|
|
206
|
-
const requestState = correlationId && definitionId ? await context.agent.siopGetAuthRequestState({
|
|
298
|
+
const correlationId = request.params.correlationId;
|
|
299
|
+
const authRequestState = await context.agent.siopGetAuthRequestState({
|
|
207
300
|
correlationId,
|
|
208
|
-
definitionId,
|
|
209
301
|
errorOnNotFound: false
|
|
210
|
-
})
|
|
211
|
-
if (!
|
|
212
|
-
console.log(`No
|
|
213
|
-
response
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
correlationId,
|
|
218
|
-
definitionId,
|
|
219
|
-
lastUpdated: requestState ? requestState.lastUpdated : Date.now()
|
|
220
|
-
};
|
|
221
|
-
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
|
+
});
|
|
222
309
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
+
});
|
|
226
343
|
}
|
|
227
344
|
let responseState;
|
|
228
|
-
if (requestState.status ===
|
|
345
|
+
if (requestState.status === AuthorizationRequestStateStatus.RETRIEVED) {
|
|
229
346
|
responseState = await context.agent.siopGetAuthResponseState({
|
|
230
347
|
correlationId,
|
|
231
|
-
definitionId,
|
|
232
|
-
includeVerifiedData,
|
|
233
348
|
errorOnNotFound: false
|
|
234
349
|
});
|
|
235
350
|
}
|
|
236
351
|
const overallState = responseState ?? requestState;
|
|
237
352
|
const statusBody = {
|
|
238
353
|
status: overallState.status,
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
...
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}),
|
|
249
|
-
verifiedData: responseState.verifiedData
|
|
250
|
-
} : {}
|
|
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
|
+
}
|
|
251
363
|
};
|
|
252
364
|
console.debug(`Will send auth status: ${JSON.stringify(statusBody)}`);
|
|
253
365
|
if (overallState.status === "error") {
|
|
254
|
-
response.
|
|
255
|
-
return response.json(statusBody);
|
|
366
|
+
return response.status(500).json(statusBody);
|
|
256
367
|
}
|
|
257
|
-
response.
|
|
258
|
-
return response.json(statusBody);
|
|
259
|
-
} catch (error) {
|
|
260
|
-
return sendErrorResponse2(response, 500, error.message, error);
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
__name(authStatusWebappEndpoint, "authStatusWebappEndpoint");
|
|
265
|
-
function removeAuthRequestStateWebappEndpoint(router, context, opts) {
|
|
266
|
-
if (opts?.enabled === false) {
|
|
267
|
-
console.log(`removeAuthStatus Webapp endpoint is disabled`);
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
const path = opts?.path ?? "/webapp/definitions/:definitionId/auth-requests/:correlationId";
|
|
271
|
-
router.delete(path, checkAuth2(opts?.endpoint), async (request, response) => {
|
|
272
|
-
try {
|
|
273
|
-
const correlationId = request.params.correlationId;
|
|
274
|
-
const definitionId = request.params.definitionId;
|
|
275
|
-
if (!correlationId || !definitionId) {
|
|
276
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`);
|
|
277
|
-
return sendErrorResponse2(response, 404, "No authorization request could be found");
|
|
278
|
-
}
|
|
279
|
-
response.statusCode = 200;
|
|
280
|
-
return response.json(await context.agent.siopDeleteAuthState({
|
|
281
|
-
definitionId,
|
|
282
|
-
correlationId
|
|
283
|
-
}));
|
|
368
|
+
return response.status(200).json(statusBody);
|
|
284
369
|
} catch (error) {
|
|
285
|
-
return sendErrorResponse2(response, 500,
|
|
370
|
+
return sendErrorResponse2(response, 500, {
|
|
371
|
+
status: 500,
|
|
372
|
+
message: error.message
|
|
373
|
+
}, error);
|
|
286
374
|
}
|
|
287
375
|
});
|
|
288
376
|
}
|
|
289
|
-
__name(
|
|
377
|
+
__name(authStatusUniversalOID4VPEndpoint, "authStatusUniversalOID4VPEndpoint");
|
|
290
378
|
function getDefinitionsEndpoint(router, context, opts) {
|
|
291
379
|
if (opts?.enabled === false) {
|
|
292
|
-
console.log(`getDefinitions
|
|
380
|
+
console.log(`getDefinitions universal OID4VP endpoint is disabled`);
|
|
293
381
|
return;
|
|
294
382
|
}
|
|
295
|
-
const path = opts?.path ?? "/
|
|
383
|
+
const path = opts?.path ?? "/backend/definitions";
|
|
296
384
|
router.get(path, checkAuth2(opts?.endpoint), async (request, response) => {
|
|
297
385
|
try {
|
|
298
386
|
const definitions = await context.agent.pdmGetDefinitions();
|
|
299
387
|
response.statusCode = 200;
|
|
300
388
|
return response.json(definitions);
|
|
301
389
|
} catch (error) {
|
|
302
|
-
return sendErrorResponse2(response, 500,
|
|
390
|
+
return sendErrorResponse2(response, 500, {
|
|
391
|
+
status: 500,
|
|
392
|
+
message: error.message
|
|
393
|
+
}, error);
|
|
303
394
|
}
|
|
304
395
|
});
|
|
305
396
|
}
|
|
@@ -350,9 +441,9 @@ var SIOPv2RPApiServer = class {
|
|
|
350
441
|
];
|
|
351
442
|
console.log(`SIOPv2 API enabled, with features: ${JSON.stringify(features)}}`);
|
|
352
443
|
if (features.includes("rp-status")) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
444
|
+
createAuthRequestUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappCreateAuthRequest);
|
|
445
|
+
authStatusUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappAuthStatus);
|
|
446
|
+
removeAuthRequestStateUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappDeleteAuthRequest);
|
|
356
447
|
getDefinitionsEndpoint(this._router, context, opts?.endpointOpts?.webappGetDefinitions);
|
|
357
448
|
}
|
|
358
449
|
if (features.includes("siop")) {
|
|
@@ -399,11 +490,12 @@ var SIOPv2RPApiServer = class {
|
|
|
399
490
|
};
|
|
400
491
|
export {
|
|
401
492
|
SIOPv2RPApiServer,
|
|
402
|
-
|
|
403
|
-
|
|
493
|
+
authStatusUniversalOID4VPEndpoint,
|
|
494
|
+
buildQueryIdFilter,
|
|
495
|
+
createAuthRequestUniversalOID4VPEndpoint,
|
|
404
496
|
getAuthRequestSIOPv2Endpoint,
|
|
405
497
|
getDefinitionsEndpoint,
|
|
406
|
-
|
|
498
|
+
removeAuthRequestStateUniversalOID4VPEndpoint,
|
|
407
499
|
verifyAuthResponseSIOPv2Endpoint
|
|
408
500
|
};
|
|
409
501
|
//# sourceMappingURL=index.js.map
|