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