@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api 0.34.1-fix.171 → 0.34.1-fix.223
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 +56 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -58
- package/dist/index.d.ts +6 -58
- package/dist/index.js +56 -79
- package/dist/index.js.map +1 -1
- package/package.json +21 -19
- package/src/siop-api-functions.ts +35 -27
- package/src/types/types.ts +7 -38
- package/src/universal-oid4vp-api-functions.ts +78 -60
- package/src/schemas/index.ts +0 -42
package/dist/index.js
CHANGED
|
@@ -31,29 +31,36 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
31
31
|
console.log(`verifyAuthResponse SIOP endpoint is disabled`);
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
const path = opts?.path ?? "/siop/
|
|
34
|
+
const path = opts?.path ?? "/siop/queries/:queryId/auth-responses/:correlationId";
|
|
35
35
|
router.post(path, checkAuth(opts?.endpoint), async (request, response) => {
|
|
36
36
|
try {
|
|
37
|
-
const { correlationId,
|
|
38
|
-
if (!correlationId
|
|
39
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}
|
|
37
|
+
const { correlationId, queryId, tenantId, version } = request.params;
|
|
38
|
+
if (!correlationId) {
|
|
39
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}`);
|
|
40
40
|
return sendErrorResponse(response, 404, "No authorization request could be found");
|
|
41
41
|
}
|
|
42
|
-
console.
|
|
43
|
-
console.
|
|
42
|
+
console.debug("Authorization Response (siop-sessions");
|
|
43
|
+
console.debug(JSON.stringify(request.body, null, 2));
|
|
44
44
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
45
45
|
filter: [
|
|
46
46
|
{
|
|
47
|
-
|
|
48
|
-
tenantId
|
|
49
|
-
|
|
47
|
+
queryId,
|
|
48
|
+
...tenantId && {
|
|
49
|
+
tenantId
|
|
50
|
+
},
|
|
51
|
+
...version && {
|
|
52
|
+
version
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: queryId
|
|
50
57
|
}
|
|
51
58
|
]
|
|
52
59
|
});
|
|
53
60
|
if (definitionItems.length === 0) {
|
|
54
|
-
console.log(`Could not get
|
|
61
|
+
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`);
|
|
55
62
|
response.statusCode = 404;
|
|
56
|
-
response.statusMessage = `No definition ${
|
|
63
|
+
response.statusMessage = `No definition ${queryId}`;
|
|
57
64
|
return response.send();
|
|
58
65
|
}
|
|
59
66
|
const authorizationResponse = parseAuthorizationResponse(request);
|
|
@@ -62,7 +69,7 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
62
69
|
const verifiedResponse = await context.agent.siopVerifyAuthResponse({
|
|
63
70
|
authorizationResponse,
|
|
64
71
|
correlationId,
|
|
65
|
-
|
|
72
|
+
dcqlQuery: definitionItem.query
|
|
66
73
|
});
|
|
67
74
|
const presentation = verifiedResponse?.oid4vpSubmission?.presentation;
|
|
68
75
|
if (presentation && Object.keys(presentation).length > 0) {
|
|
@@ -77,7 +84,7 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
77
84
|
}
|
|
78
85
|
const responseRedirectURI = await context.agent.siopGetRedirectURI({
|
|
79
86
|
correlationId,
|
|
80
|
-
queryId
|
|
87
|
+
queryId,
|
|
81
88
|
state: verifiedResponse.state
|
|
82
89
|
});
|
|
83
90
|
if (responseRedirectURI) {
|
|
@@ -104,33 +111,38 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
104
111
|
console.log(`getAuthRequest SIOP endpoint is disabled`);
|
|
105
112
|
return;
|
|
106
113
|
}
|
|
107
|
-
const path = opts?.path ?? "/siop/
|
|
114
|
+
const path = opts?.path ?? "/siop/queries/:queryId/auth-requests/:correlationId";
|
|
108
115
|
router.get(path, checkAuth(opts?.endpoint), async (request, response) => {
|
|
109
116
|
try {
|
|
110
117
|
const correlationId = request.params.correlationId;
|
|
111
|
-
const
|
|
112
|
-
if (!correlationId || !
|
|
113
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId},
|
|
118
|
+
const queryId = request.params.queryId;
|
|
119
|
+
if (!correlationId || !queryId) {
|
|
120
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, queryId: ${queryId}`);
|
|
114
121
|
return sendErrorResponse(response, 404, "No authorization request could be found");
|
|
115
122
|
}
|
|
116
123
|
const requestState = await context.agent.siopGetAuthRequestState({
|
|
117
124
|
correlationId,
|
|
118
|
-
//queryId: definitionId,
|
|
119
125
|
errorOnNotFound: false
|
|
120
126
|
});
|
|
121
127
|
if (!requestState) {
|
|
122
|
-
console.log(`No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${
|
|
128
|
+
console.log(`No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${queryId}`);
|
|
123
129
|
return sendErrorResponse(response, 404, `No authorization request could be found`);
|
|
124
130
|
}
|
|
125
131
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
126
132
|
filter: [
|
|
127
133
|
{
|
|
128
|
-
|
|
134
|
+
queryId
|
|
129
135
|
}
|
|
130
136
|
]
|
|
131
137
|
});
|
|
138
|
+
if (definitionItems.length === 0) {
|
|
139
|
+
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`);
|
|
140
|
+
response.statusCode = 404;
|
|
141
|
+
response.statusMessage = `No definition ${queryId}`;
|
|
142
|
+
return response.send();
|
|
143
|
+
}
|
|
132
144
|
const payload = requestState.request?.requestObject?.getPayload();
|
|
133
|
-
payload.dcql_query = definitionItems[0].
|
|
145
|
+
payload.dcql_query = definitionItems[0].query;
|
|
134
146
|
const requestObject = await requestState.request?.requestObject?.toJwt();
|
|
135
147
|
console.log("JWT Request object:");
|
|
136
148
|
console.log(requestObject);
|
|
@@ -145,7 +157,6 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
145
157
|
} finally {
|
|
146
158
|
await context.agent.siopUpdateAuthRequestState({
|
|
147
159
|
correlationId,
|
|
148
|
-
//queryId: definitionId,
|
|
149
160
|
state: "authorization_request_created",
|
|
150
161
|
error
|
|
151
162
|
});
|
|
@@ -158,6 +169,7 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
158
169
|
__name(getAuthRequestSIOPv2Endpoint, "getAuthRequestSIOPv2Endpoint");
|
|
159
170
|
|
|
160
171
|
// src/universal-oid4vp-api-functions.ts
|
|
172
|
+
import { AuthorizationRequestStateStatus, createAuthorizationRequestFromPayload, CreateAuthorizationRequestPayloadSchema } from "@sphereon/did-auth-siop";
|
|
161
173
|
import { checkAuth as checkAuth2, sendErrorResponse as sendErrorResponse2 } from "@sphereon/ssi-express-support";
|
|
162
174
|
import { uriWithBase } from "@sphereon/ssi-sdk.siopv2-oid4vp-common";
|
|
163
175
|
import uuid from "short-uuid";
|
|
@@ -189,47 +201,6 @@ var validateData = /* @__PURE__ */ __name((schema) => {
|
|
|
189
201
|
};
|
|
190
202
|
}, "validateData");
|
|
191
203
|
|
|
192
|
-
// src/schemas/index.ts
|
|
193
|
-
import { CallbackOptsSchema, ResponseMode, ResponseType } from "@sphereon/did-auth-siop";
|
|
194
|
-
import { z } from "zod";
|
|
195
|
-
var ResponseTypeSchema = z.enum([
|
|
196
|
-
ResponseType.VP_TOKEN
|
|
197
|
-
]);
|
|
198
|
-
var ResponseModeSchema = z.enum([
|
|
199
|
-
ResponseMode.DIRECT_POST,
|
|
200
|
-
ResponseMode.DIRECT_POST_JWT
|
|
201
|
-
]);
|
|
202
|
-
var requestUriMethods = [
|
|
203
|
-
"get",
|
|
204
|
-
"post"
|
|
205
|
-
];
|
|
206
|
-
var RequestUriMethodSchema = z.enum(requestUriMethods);
|
|
207
|
-
var QRCodeOptsSchema = z.object({
|
|
208
|
-
size: z.number().optional(),
|
|
209
|
-
color_dark: z.string().optional(),
|
|
210
|
-
color_light: z.string().optional()
|
|
211
|
-
});
|
|
212
|
-
var CreateAuthorizationRequestBodySchema = z.object({
|
|
213
|
-
query_id: z.string(),
|
|
214
|
-
client_id: z.string().optional(),
|
|
215
|
-
request_uri_base: z.string().optional(),
|
|
216
|
-
correlation_id: z.string().optional(),
|
|
217
|
-
request_uri_method: RequestUriMethodSchema.optional(),
|
|
218
|
-
response_type: ResponseTypeSchema.optional(),
|
|
219
|
-
response_mode: ResponseModeSchema.optional(),
|
|
220
|
-
transaction_data: z.array(z.string()).optional(),
|
|
221
|
-
qr_code: QRCodeOptsSchema.optional(),
|
|
222
|
-
direct_post_response_redirect_uri: z.string().optional(),
|
|
223
|
-
callback: CallbackOptsSchema.optional()
|
|
224
|
-
});
|
|
225
|
-
var CreateAuthorizationResponseSchema = z.object({
|
|
226
|
-
correlation_id: z.string(),
|
|
227
|
-
query_id: z.string(),
|
|
228
|
-
request_uri: z.string(),
|
|
229
|
-
status_uri: z.string(),
|
|
230
|
-
qr_uri: z.string().optional()
|
|
231
|
-
});
|
|
232
|
-
|
|
233
204
|
// src/universal-oid4vp-api-functions.ts
|
|
234
205
|
function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
235
206
|
if (opts?.enabled === false) {
|
|
@@ -237,18 +208,21 @@ function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
|
237
208
|
return;
|
|
238
209
|
}
|
|
239
210
|
const path = opts?.path ?? "/backend/auth/requests";
|
|
240
|
-
router.post(path, checkAuth2(opts?.endpoint), validateData(
|
|
211
|
+
router.post(path, checkAuth2(opts?.endpoint), validateData(CreateAuthorizationRequestPayloadSchema), async (request, response) => {
|
|
241
212
|
try {
|
|
242
|
-
const
|
|
243
|
-
const
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const
|
|
213
|
+
const authRequest = createAuthorizationRequestFromPayload(request.body);
|
|
214
|
+
const correlationId = authRequest.correlationId ?? uuid.uuid();
|
|
215
|
+
const qrCodeOpts = authRequest.qrCode ? {
|
|
216
|
+
...authRequest.qrCode
|
|
217
|
+
} : opts?.qrCodeOpts;
|
|
218
|
+
const queryId = authRequest.queryId;
|
|
248
219
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
249
220
|
filter: [
|
|
250
221
|
{
|
|
251
|
-
|
|
222
|
+
id: queryId
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
queryId
|
|
252
226
|
}
|
|
253
227
|
]
|
|
254
228
|
});
|
|
@@ -259,10 +233,10 @@ function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
|
259
233
|
message: "No query could be found"
|
|
260
234
|
});
|
|
261
235
|
}
|
|
262
|
-
const requestByReferenceURI = uriWithBase(`/siop/
|
|
263
|
-
baseURI: requestUriBase ?? opts?.siopBaseURI
|
|
236
|
+
const requestByReferenceURI = uriWithBase(`/siop/queries/${queryId}/auth-requests/${correlationId}`, {
|
|
237
|
+
baseURI: authRequest.requestUriBase ?? opts?.siopBaseURI
|
|
264
238
|
});
|
|
265
|
-
const responseURI = uriWithBase(`/siop/
|
|
239
|
+
const responseURI = uriWithBase(`/siop/queries/${queryId}/auth-responses/${correlationId}`, {
|
|
266
240
|
baseURI: opts?.siopBaseURI
|
|
267
241
|
});
|
|
268
242
|
const authRequestURI = await context.agent.siopCreateAuthRequestURI({
|
|
@@ -272,10 +246,12 @@ function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
|
272
246
|
requestByReferenceURI,
|
|
273
247
|
responseURIType: "response_uri",
|
|
274
248
|
responseURI,
|
|
275
|
-
...directPostResponseRedirectUri && {
|
|
276
|
-
responseRedirectURI: directPostResponseRedirectUri
|
|
249
|
+
...authRequest.directPostResponseRedirectUri && {
|
|
250
|
+
responseRedirectURI: authRequest.directPostResponseRedirectUri
|
|
277
251
|
},
|
|
278
|
-
callback
|
|
252
|
+
...authRequest.callback && {
|
|
253
|
+
callback: authRequest.callback
|
|
254
|
+
}
|
|
279
255
|
});
|
|
280
256
|
let qrCodeDataUri;
|
|
281
257
|
if (qrCodeOpts) {
|
|
@@ -285,6 +261,8 @@ function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
|
285
261
|
text: authRequestURI
|
|
286
262
|
});
|
|
287
263
|
qrCodeDataUri = `data:image/png;base64,${(await qrCode.draw()).toString("base64")}`;
|
|
264
|
+
} else {
|
|
265
|
+
qrCodeDataUri = authRequestURI;
|
|
288
266
|
}
|
|
289
267
|
const authRequestBody = {
|
|
290
268
|
query_id: queryId,
|
|
@@ -363,7 +341,7 @@ function authStatusUniversalOID4VPEndpoint(router, context, opts) {
|
|
|
363
341
|
});
|
|
364
342
|
}
|
|
365
343
|
let responseState;
|
|
366
|
-
if (requestState.status ===
|
|
344
|
+
if (requestState.status === AuthorizationRequestStateStatus.RETRIEVED) {
|
|
367
345
|
responseState = await context.agent.siopGetAuthResponseState({
|
|
368
346
|
correlationId,
|
|
369
347
|
errorOnNotFound: false
|
|
@@ -378,7 +356,6 @@ function authStatusUniversalOID4VPEndpoint(router, context, opts) {
|
|
|
378
356
|
..."verifiedData" in overallState && {
|
|
379
357
|
verified_data: overallState.verifiedData
|
|
380
358
|
},
|
|
381
|
-
//...((responseState?.status === AuthorizationResponseStateStatus.VERIFIED && responseState.verifiedData !== undefined) && { verified_data: responseState.verifiedData }),
|
|
382
359
|
...overallState.error && {
|
|
383
360
|
message: overallState.error.message
|
|
384
361
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/siop-api-functions.ts","../src/universal-oid4vp-api-functions.ts","../src/middleware/validationMiddleware.ts","../src/schemas/index.ts","../src/siopv2-rp-api-server.ts"],"sourcesContent":["import { AuthorizationResponsePayload } from '@sphereon/did-auth-siop'\nimport { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { AuthorizationChallengeValidationResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'\nimport { CredentialMapper } from '@sphereon/ssi-types'\nimport { Request, Response, Router } from 'express'\nimport { IRequiredContext } from './types'\n\nconst parseAuthorizationResponse = (request: Request): AuthorizationResponsePayload => {\n const contentType = request.header('content-type')\n\n if (contentType === 'application/json') {\n const payload = typeof request.body === 'string' ? JSON.parse(request.body) : request.body\n return payload as AuthorizationResponsePayload\n }\n\n if (contentType === 'application/x-www-form-urlencoded') {\n const payload = request.body as AuthorizationResponsePayload\n\n // Parse presentation_submission if it's a string\n if (typeof payload.presentation_submission === 'string') {\n console.log(`Supplied presentation_submission was a string instead of JSON. Correcting, but external party should fix their implementation!`)\n payload.presentation_submission = JSON.parse(payload.presentation_submission)\n }\n\n // when using FORM_URL_ENCODED, vp_token comes back as string not matter whether the input was string, object or array. Handled below.\n if (typeof payload.vp_token === 'string') {\n const { vp_token } = payload\n\n // The only use case where vp_object is an object is JsonLdAsString atm. For arrays, any objects will be parsed along with the array\n // (Leaving the vp_token JsonLdAsString causes problems because the original credential will remain string and will be interpreted as JWT in some parts of the code)\n if ((vp_token.startsWith('[') && vp_token.endsWith(']')) || CredentialMapper.isJsonLdAsString(vp_token)) {\n payload.vp_token = JSON.parse(vp_token)\n }\n }\n\n return payload\n }\n\n throw new Error(\n `Unsupported content type: ${contentType}. Currently only application/x-www-form-urlencoded and application/json (for direct_post) are supported`,\n )\n}\n\nexport function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`verifyAuthResponse SIOP endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/siop/definitions/:definitionId/auth-responses/:correlationId'\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const { correlationId, definitionId, tenantId, version } = request.params\n if (!correlationId || !definitionId) {\n console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)\n return sendErrorResponse(response, 404, 'No authorization request could be found')\n }\n console.log('Authorization Response (siop-sessions')\n console.log(JSON.stringify(request.body, null, 2))\n const definitionItems = await context.agent.pdmGetDefinitions({ filter: [{ definitionId, tenantId, version }] })\n if (definitionItems.length === 0) {\n console.log(`Could not get definition ${definitionId} from agent. Will return 404`)\n response.statusCode = 404\n response.statusMessage = `No definition ${definitionId}`\n return response.send()\n }\n\n const authorizationResponse = parseAuthorizationResponse(request)\n console.log(`URI: ${JSON.stringify(authorizationResponse)}`)\n\n const definitionItem = definitionItems[0]\n const verifiedResponse = await context.agent.siopVerifyAuthResponse({\n authorizationResponse,\n correlationId,\n dcqlQueryPayload: definitionItem.dcqlPayload,\n })\n\n // FIXME SSISDK-55 add proper support for checking for DCQL presentations\n const presentation = verifiedResponse?.oid4vpSubmission?.presentation\n if (presentation && Object.keys(presentation).length > 0) {\n console.log('PRESENTATIONS:' + JSON.stringify(verifiedResponse?.oid4vpSubmission?.presentation, null, 2))\n response.statusCode = 200\n\n const authorizationChallengeValidationResponse: AuthorizationChallengeValidationResponse = {\n presentation_during_issuance_session: verifiedResponse.correlationId,\n }\n if (authorizationResponse.is_first_party) {\n response.setHeader('Content-Type', 'application/json')\n return response.send(JSON.stringify(authorizationChallengeValidationResponse))\n }\n\n const responseRedirectURI = await context.agent.siopGetRedirectURI({ correlationId, queryId: definitionId, state: verifiedResponse.state })\n if (responseRedirectURI) {\n response.setHeader('Content-Type', 'application/json')\n return response.send(JSON.stringify({ redirect_uri: responseRedirectURI }))\n }\n // todo: delete session\n } else {\n console.log('Missing Presentation (Verifiable Credentials)')\n response.statusCode = 500\n response.statusMessage = 'Missing Presentation (Verifiable Credentials)'\n }\n return response.send()\n } catch (error) {\n console.error(error)\n return sendErrorResponse(response, 500, 'Could not verify auth status', error)\n }\n })\n}\n\nexport function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`getAuthRequest SIOP endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/siop/definitions/:definitionId/auth-requests/:correlationId'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const correlationId = request.params.correlationId\n const definitionId = request.params.definitionId\n if (!correlationId || !definitionId) {\n console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)\n return sendErrorResponse(response, 404, 'No authorization request could be found')\n }\n const requestState = await context.agent.siopGetAuthRequestState({\n correlationId,\n //queryId: definitionId,\n errorOnNotFound: false,\n })\n if (!requestState) {\n console.log(\n `No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${definitionId}`,\n )\n return sendErrorResponse(response, 404, `No authorization request could be found`)\n }\n\n const definitionItems = await context.agent.pdmGetDefinitions({\n filter: [\n {\n definitionId: definitionId\n }\n ]\n });\n const payload = requestState.request?.requestObject?.getPayload()!\n payload.dcql_query = definitionItems[0].dcqlPayload!.dcqlQuery\n\n const requestObject = await requestState.request?.requestObject?.toJwt()\n console.log('JWT Request object:')\n console.log(requestObject)\n\n let error: string | undefined\n try {\n response.statusCode = 200\n response.setHeader('Content-Type', 'application/jwt')\n return response.send(requestObject)\n } catch (e) {\n error = typeof e === 'string' ? e : e instanceof Error ? e.message : undefined\n return sendErrorResponse(response, 500, 'Could not get authorization request', e)\n } finally {\n await context.agent.siopUpdateAuthRequestState({\n correlationId,\n //queryId: definitionId,\n state: 'authorization_request_created',\n error,\n })\n }\n } catch (error) {\n return sendErrorResponse(response, 500, 'Could not get authorization request', error)\n }\n })\n}\n","import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { uriWithBase } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'\nimport { Request, Response, Router } from 'express'\nimport uuid from 'short-uuid'\nimport { validateData } from './middleware/validationMiddleware'\nimport { CreateAuthorizationRequestBodySchema } from './schemas'\nimport {\n CreateAuthorizationRequest,\n CreateAuthorizationRequestResponse,\n CreateAuthorizationResponse,\n DeleteAuthorizationRequest,\n GetAuthorizationRequestStatus,\n AuthStatusResponse,\n ICreateAuthRequestWebappEndpointOpts,\n IRequiredContext\n} from './types'\n\nexport function createAuthRequestUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ICreateAuthRequestWebappEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`createAuthRequest universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/auth/requests'\n router.post(path, checkAuth(opts?.endpoint), validateData(CreateAuthorizationRequestBodySchema), async (request: CreateAuthorizationRequest, response: CreateAuthorizationResponse) => {\n try {\n const correlationId = request.body.correlation_id ?? uuid.uuid()\n const qrCodeOpts = request.body.qr_code ?? opts?.qrCodeOpts\n const queryId = request.body.query_id\n const directPostResponseRedirectUri = request.body.direct_post_response_redirect_uri // TODO Uri not URI\n const requestUriBase = request.body.request_uri_base\n const callback = request.body.callback\n\n const definitionItems = await context.agent.pdmGetDefinitions({ filter: [{ definitionId: queryId }] })\n if (definitionItems.length === 0) {\n console.log(`No query could be found for the given id. Query id: ${queryId}`)\n return sendErrorResponse(response, 404, { status: 404, message: 'No query could be found' })\n }\n\n const requestByReferenceURI = uriWithBase(`/siop/definitions/${queryId}/auth-requests/${correlationId}`, {\n baseURI: requestUriBase ?? opts?.siopBaseURI,\n })\n const responseURI = uriWithBase(`/siop/definitions/${queryId}/auth-responses/${correlationId}`, { baseURI: opts?.siopBaseURI })\n\n const authRequestURI = await context.agent.siopCreateAuthRequestURI({\n queryId,\n correlationId,\n nonce: uuid.uuid(),\n requestByReferenceURI,\n responseURIType: 'response_uri',\n responseURI,\n ...(directPostResponseRedirectUri && { responseRedirectURI: directPostResponseRedirectUri }),\n callback\n })\n\n let qrCodeDataUri: string | undefined\n if (qrCodeOpts) {\n const { AwesomeQR } = await import('awesome-qr')\n const qrCode = new AwesomeQR({ ...qrCodeOpts, text: authRequestURI })\n qrCodeDataUri = `data:image/png;base64,${(await qrCode.draw())!.toString('base64')}`\n }\n\n const authRequestBody = {\n query_id: queryId,\n correlation_id: correlationId,\n request_uri: authRequestURI,\n status_uri: `${uriWithBase(opts?.webappAuthStatusPath ?? `/backend/auth/status/${correlationId}`, { baseURI: opts?.webappBaseURI })}`,\n ...(qrCodeDataUri && { qr_uri: qrCodeDataUri }),\n } satisfies CreateAuthorizationRequestResponse\n console.log(`Auth Request URI data to send back: ${JSON.stringify(authRequestBody)}`)\n\n return response.status(201).json(authRequestBody)\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: 'Could not create an authorization request URI' }, error)\n }\n })\n}\n\nexport function removeAuthRequestStateUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`removeAuthStatus universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/auth/requests/:correlationId'\n router.delete(path, checkAuth(opts?.endpoint), async (request: DeleteAuthorizationRequest, response: Response) => {\n try {\n const correlationId: string = request.params.correlationId\n\n const authRequestState = await context.agent.siopGetAuthRequestState({\n correlationId,\n errorOnNotFound: false\n })\n if (!authRequestState) {\n console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`)\n return sendErrorResponse(response, 404, { status: 404, message: 'No authorization request could be found' })\n }\n\n await context.agent.siopDeleteAuthState({ correlationId })\n\n return response.status(204).json()\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: error.message }, error)\n }\n })\n}\n\nexport function authStatusUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`authStatus universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/auth/status/:correlationId'\n router.get(path, checkAuth(opts?.endpoint), async (request: GetAuthorizationRequestStatus, response: Response) => {\n try {\n console.log('Received auth-status request...')\n const correlationId: string = request.params.correlationId\n\n const requestState = await context.agent.siopGetAuthRequestState({\n correlationId,\n errorOnNotFound: false\n })\n\n if (!requestState) {\n console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`)\n return sendErrorResponse(response, 404, { status: 404, message: 'No authorization request could be found' })\n }\n\n let responseState\n if (requestState.status === \"authorization_request_retrieved\") {\n responseState = (await context.agent.siopGetAuthResponseState({ correlationId, errorOnNotFound: false }))\n }\n const overallState = responseState ?? requestState\n\n const statusBody = {\n status: overallState.status,\n correlation_id: overallState.correlationId,\n query_id: overallState.queryId,\n last_updated: overallState.lastUpdated,\n ...('verifiedData' in overallState && { verified_data: overallState.verifiedData }),\n //...((responseState?.status === AuthorizationResponseStateStatus.VERIFIED && responseState.verifiedData !== undefined) && { verified_data: responseState.verifiedData }),\n ...(overallState.error && { message: overallState.error.message })\n } satisfies AuthStatusResponse\n console.debug(`Will send auth status: ${JSON.stringify(statusBody)}`)\n\n if (overallState.status === 'error') {\n return response.status(500).json(statusBody)\n }\n return response.status(200).json(statusBody)\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: error.message }, error)\n }\n })\n}\n\nexport function getDefinitionsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`getDefinitions universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/definitions'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const definitions = await context.agent.pdmGetDefinitions()\n response.statusCode = 200\n return response.json(definitions)\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: error.message }, error)\n }\n })\n}\n","import { Request, Response, NextFunction } from 'express';\nimport { z, ZodError } from 'zod';\n\nexport const validateData = (schema: z.ZodObject<any, any>) => {\n return (req: Request, res: Response, next: NextFunction) => {\n try {\n schema.parse(req.body);\n next();\n } catch (error) {\n if (error instanceof ZodError) {\n const errorMessages = error.issues.map((issue: any) => ({\n message: `${issue.path.join('.')} is ${issue.message}`,\n }))\n res.status(400).json({ status: 400, message: 'Invalid data', error_details: errorMessages[0].message });\n } else {\n res.status(500).json({ status: 500, message: 'Internal Server Error' });\n }\n }\n };\n}\n","import {\n CallbackOptsSchema,\n RequestUriMethod,\n ResponseMode,\n ResponseType\n} from '@sphereon/did-auth-siop'\nimport { z } from 'zod'\n\nexport const ResponseTypeSchema = z.enum([ResponseType.VP_TOKEN]);\n\nexport const ResponseModeSchema = z.enum([ResponseMode.DIRECT_POST, ResponseMode.DIRECT_POST_JWT]);\n\nconst requestUriMethods = ['get', 'post'] as const satisfies Array<RequestUriMethod>;\nexport const RequestUriMethodSchema = z.enum(requestUriMethods);\n\nexport const QRCodeOptsSchema = z.object({\n size: z.number().optional(),\n color_dark: z.string().optional(),\n color_light: z.string().optional(),\n});\n\nexport const CreateAuthorizationRequestBodySchema = z.object({\n query_id: z.string(),\n client_id: z.string().optional(),\n request_uri_base: z.string().optional(),\n correlation_id: z.string().optional(),\n request_uri_method: RequestUriMethodSchema.optional(),\n response_type: ResponseTypeSchema.optional(),\n response_mode: ResponseModeSchema.optional(),\n transaction_data: z.array(z.string()).optional(),\n qr_code: QRCodeOptsSchema.optional(),\n direct_post_response_redirect_uri: z.string().optional(),\n callback: CallbackOptsSchema.optional(),\n});\n\nexport const CreateAuthorizationResponseSchema = z.object({\n correlation_id: z.string(),\n query_id: z.string(),\n request_uri: z.string(),\n status_uri: z.string(),\n qr_uri: z.string().optional(),\n});\n","import { agentContext } from '@sphereon/ssi-sdk.core'\nimport { copyGlobalAuthToEndpoints, ExpressSupport } from '@sphereon/ssi-express-support'\nimport { ISIOPv2RP } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth'\nimport { TAgent } from '@veramo/core'\nimport express, { Express, Request, Response, Router } from 'express'\nimport { getAuthRequestSIOPv2Endpoint, verifyAuthResponseSIOPv2Endpoint } from './siop-api-functions'\nimport { IRequiredPlugins, ISIOPv2RPRestAPIOpts } from './types'\nimport {\n authStatusUniversalOID4VPEndpoint,\n createAuthRequestUniversalOID4VPEndpoint,\n getDefinitionsEndpoint,\n removeAuthRequestStateUniversalOID4VPEndpoint,\n} from './universal-oid4vp-api-functions'\nimport swaggerUi from 'swagger-ui-express'\n\nexport class SIOPv2RPApiServer {\n private readonly _express: Express\n private readonly _router: Router\n private readonly _agent: TAgent<ISIOPv2RP>\n private readonly _opts?: ISIOPv2RPRestAPIOpts\n private readonly _basePath: string\n\n private readonly OID4VP_SWAGGER_URL = 'https://api.swaggerhub.com/apis/SphereonInt/OID4VP/0.1.0'\n constructor(args: { agent: TAgent<IRequiredPlugins>; expressSupport: ExpressSupport; opts?: ISIOPv2RPRestAPIOpts }) {\n const { agent, opts } = args\n this._agent = agent\n copyGlobalAuthToEndpoints({ opts, keys: ['webappCreateAuthRequest', 'webappAuthStatus', 'webappDeleteAuthRequest'] })\n if (opts?.endpointOpts?.globalAuth?.secureSiopEndpoints) {\n copyGlobalAuthToEndpoints({ opts, keys: ['siopGetAuthRequest', 'siopVerifyAuthResponse'] })\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n const context = agentContext(agent)\n\n const features = opts?.enableFeatures ?? ['rp-status', 'siop']\n console.log(`SIOPv2 API enabled, with features: ${JSON.stringify(features)}}`)\n\n // Webapp endpoints\n if (features.includes('rp-status')) {\n createAuthRequestUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappCreateAuthRequest)\n authStatusUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappAuthStatus)\n removeAuthRequestStateUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappDeleteAuthRequest)\n getDefinitionsEndpoint(this._router, context, opts?.endpointOpts?.webappGetDefinitions)\n }\n\n // SIOPv2 endpoints\n if (features.includes('siop')) {\n getAuthRequestSIOPv2Endpoint(this._router, context, opts?.endpointOpts?.siopGetAuthRequest)\n verifyAuthResponseSIOPv2Endpoint(this._router, context, opts?.endpointOpts?.siopVerifyAuthResponse)\n }\n this._basePath = opts?.endpointOpts?.basePath ?? ''\n this._express.use(this._basePath, this.router)\n this._express.set('trust proxy', opts?.endpointOpts?.trustProxy ?? true)\n this.setupSwaggerUi()\n }\n\n private setupSwaggerUi() {\n fetch(this.OID4VP_SWAGGER_URL)\n .then((res) => res.json())\n .then((swagger: any) => {\n const apiDocs = `${this._basePath}/api-docs`\n console.log(`[OID4P] API docs available at ${apiDocs}`)\n\n this._router.use(\n '/api-docs',\n (req: Request, res: Response, next: any) => {\n const regex = `${apiDocs.replace(/\\//, '\\/')}`.replace('/oid4vp', '').replace(/\\/api-docs.*/, '')\n swagger.servers = [{ url: `${req.protocol}://${req.get('host')}${regex}`, description: 'This server' }]\n // @ts-ignore\n req.swaggerDoc = swagger\n next()\n },\n swaggerUi.serveFiles(swagger, options),\n swaggerUi.setup(),\n )\n })\n .catch((err) => {\n console.log(`[OID4VP] Unable to fetch swagger document: ${err}. Will not host api-docs on this instance`)\n })\n const options = {\n // customCss: '.swagger-ui .topbar { display: none }',\n }\n }\n get express(): Express {\n return this._express\n }\n\n get router(): Router {\n return this._router\n }\n\n get agent(): TAgent<ISIOPv2RP> {\n return this._agent\n }\n\n get opts(): ISIOPv2RPRestAPIOpts | undefined {\n return this._opts\n }\n}\n"],"mappings":";;;;AACA,SAASA,WAAgCC,yBAAyB;AAElE,SAASC,wBAAwB;AAIjC,IAAMC,6BAA6B,wBAACC,YAAAA;AAClC,QAAMC,cAAcD,QAAQE,OAAO,cAAA;AAEnC,MAAID,gBAAgB,oBAAoB;AACtC,UAAME,UAAU,OAAOH,QAAQI,SAAS,WAAWC,KAAKC,MAAMN,QAAQI,IAAI,IAAIJ,QAAQI;AACtF,WAAOD;EACT;AAEA,MAAIF,gBAAgB,qCAAqC;AACvD,UAAME,UAAUH,QAAQI;AAGxB,QAAI,OAAOD,QAAQI,4BAA4B,UAAU;AACvDC,cAAQC,IAAI,gIAAgI;AAC5IN,cAAQI,0BAA0BF,KAAKC,MAAMH,QAAQI,uBAAuB;IAC9E;AAGA,QAAI,OAAOJ,QAAQO,aAAa,UAAU;AACxC,YAAM,EAAEA,SAAQ,IAAKP;AAIr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A,IAAI/C,UAAmB;AACrB,WAAO,KAAKf;EACd;EAEA,IAAIwC,SAAiB;AACnB,WAAO,KAAKvC;EACd;EAEA,IAAIM,QAA2B;AAC7B,WAAO,KAAKL;EACd;EAEA,IAAIM,OAAyC;AAC3C,WAAO,KAAKL;EACd;AACF;","names":["checkAuth","sendErrorResponse","CredentialMapper","parseAuthorizationResponse","request","contentType","header","payload","body","JSON","parse","presentation_submission","console","log","vp_token","startsWith","endsWith","CredentialMapper","isJsonLdAsString","Error","verifyAuthResponseSIOPv2Endpoint","router","context","opts","enabled","path","post","checkAuth","endpoint","response","correlationId","definitionId","tenantId","version","params","sendErrorResponse","stringify","definitionItems","agent","pdmGetDefinitions","filter","length","statusCode","statusMessage","send","authorizationResponse","definitionItem","verifiedResponse","siopVerifyAuthResponse","dcqlQueryPayload","dcqlPayload","presentation","oid4vpSubmission","Object","keys","authorizationChallengeValidationResponse","presentation_during_issuance_session","is_first_party","setHeader","responseRedirectURI","siopGetRedirectURI","queryId","state","redirect_uri","error","getAuthRequestSIOPv2Endpoint","get","requestState","siopGetAuthRequestState","errorOnNotFound","requestObject","getPayload","dcql_query","dcqlQuery","toJwt","e","message","undefined","siopUpdateAuthRequestState","checkAuth","sendErrorResponse","uriWithBase","uuid","ZodError","validateData","schema","req","res","next","parse","body","error","ZodError","errorMessages","issues","map","issue","message","path","join","status","json","error_details","CallbackOptsSchema","ResponseMode","ResponseType","z","ResponseTypeSchema","enum","VP_TOKEN","ResponseModeSchema","DIRECT_POST","DIRECT_POST_JWT","requestUriMethods","RequestUriMethodSchema","QRCodeOptsSchema","object","size","number","optional","color_dark","string","color_light","CreateAuthorizationRequestBodySchema","query_id","client_id","request_uri_base","correlation_id","request_uri_method","response_type","response_mode","transaction_data","array","qr_code","direct_post_response_redirect_uri","callback","CreateAuthorizationResponseSchema","request_uri","status_uri","qr_uri","createAuthRequestUniversalOID4VPEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","validateData","CreateAuthorizationRequestBodySchema","request","response","correlationId","body","correlation_id","uuid","qrCodeOpts","qr_code","queryId","query_id","directPostResponseRedirectUri","direct_post_response_redirect_uri","requestUriBase","request_uri_base","callback","definitionItems","agent","pdmGetDefinitions","filter","definitionId","length","sendErrorResponse","status","message","requestByReferenceURI","uriWithBase","baseURI","siopBaseURI","responseURI","authRequestURI","siopCreateAuthRequestURI","nonce","responseURIType","responseRedirectURI","qrCodeDataUri","AwesomeQR","qrCode","text","draw","toString","authRequestBody","request_uri","status_uri","webappAuthStatusPath","webappBaseURI","qr_uri","JSON","stringify","json","error","removeAuthRequestStateUniversalOID4VPEndpoint","delete","params","authRequestState","siopGetAuthRequestState","errorOnNotFound","siopDeleteAuthState","authStatusUniversalOID4VPEndpoint","get","requestState","responseState","siopGetAuthResponseState","overallState","statusBody","last_updated","lastUpdated","verified_data","verifiedData","debug","getDefinitionsEndpoint","definitions","statusCode","agentContext","copyGlobalAuthToEndpoints","express","swaggerUi","SIOPv2RPApiServer","_express","_router","_agent","_opts","_basePath","OID4VP_SWAGGER_URL","args","agent","opts","copyGlobalAuthToEndpoints","keys","endpointOpts","globalAuth","secureSiopEndpoints","expressSupport","express","Router","context","agentContext","features","enableFeatures","console","log","JSON","stringify","includes","createAuthRequestUniversalOID4VPEndpoint","webappCreateAuthRequest","authStatusUniversalOID4VPEndpoint","webappAuthStatus","removeAuthRequestStateUniversalOID4VPEndpoint","webappDeleteAuthRequest","getDefinitionsEndpoint","webappGetDefinitions","getAuthRequestSIOPv2Endpoint","siopGetAuthRequest","verifyAuthResponseSIOPv2Endpoint","siopVerifyAuthResponse","basePath","use","router","set","trustProxy","setupSwaggerUi","fetch","then","res","json","swagger","apiDocs","req","next","regex","replace","servers","url","protocol","get","description","swaggerDoc","swaggerUi","serveFiles","options","setup","catch","err"]}
|
|
1
|
+
{"version":3,"sources":["../src/siop-api-functions.ts","../src/universal-oid4vp-api-functions.ts","../src/middleware/validationMiddleware.ts","../src/siopv2-rp-api-server.ts"],"sourcesContent":["import { AuthorizationResponsePayload } from '@sphereon/did-auth-siop'\nimport { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { AuthorizationChallengeValidationResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'\nimport { CredentialMapper } from '@sphereon/ssi-types'\nimport { Request, Response, Router } from 'express'\nimport { IRequiredContext } from './types'\n\nconst parseAuthorizationResponse = (request: Request): AuthorizationResponsePayload => {\n const contentType = request.header('content-type')\n\n if (contentType === 'application/json') {\n const payload = typeof request.body === 'string' ? JSON.parse(request.body) : request.body\n return payload as AuthorizationResponsePayload\n }\n\n if (contentType === 'application/x-www-form-urlencoded') {\n const payload = request.body as AuthorizationResponsePayload\n\n // Parse presentation_submission if it's a string\n if (typeof payload.presentation_submission === 'string') {\n console.log(`Supplied presentation_submission was a string instead of JSON. Correcting, but external party should fix their implementation!`)\n payload.presentation_submission = JSON.parse(payload.presentation_submission)\n }\n\n // when using FORM_URL_ENCODED, vp_token comes back as string not matter whether the input was string, object or array. Handled below.\n if (typeof payload.vp_token === 'string') {\n const { vp_token } = payload\n\n // The only use case where vp_object is an object is JsonLdAsString atm. For arrays, any objects will be parsed along with the array\n // (Leaving the vp_token JsonLdAsString causes problems because the original credential will remain string and will be interpreted as JWT in some parts of the code)\n if ((vp_token.startsWith('[') && vp_token.endsWith(']')) || CredentialMapper.isJsonLdAsString(vp_token)) {\n payload.vp_token = JSON.parse(vp_token)\n }\n }\n\n return payload\n }\n\n throw new Error(\n `Unsupported content type: ${contentType}. Currently only application/x-www-form-urlencoded and application/json (for direct_post) are supported`,\n )\n}\n\nexport function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`verifyAuthResponse SIOP endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/siop/queries/:queryId/auth-responses/:correlationId'\n router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const { correlationId, queryId, tenantId, version } = request.params\n if (!correlationId) {\n console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}`)\n return sendErrorResponse(response, 404, 'No authorization request could be found')\n }\n console.debug('Authorization Response (siop-sessions') // TODO use logger\n console.debug(JSON.stringify(request.body, null, 2))\n const definitionItems = await context.agent.pdmGetDefinitions({\n filter: [\n {\n queryId,\n ...(tenantId && { tenantId }),\n ...(version && { version }),\n },\n {\n id: queryId,\n },\n ],\n })\n if (definitionItems.length === 0) {\n console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`)\n response.statusCode = 404\n response.statusMessage = `No definition ${queryId}`\n return response.send()\n }\n\n const authorizationResponse = parseAuthorizationResponse(request)\n console.log(`URI: ${JSON.stringify(authorizationResponse)}`)\n\n const definitionItem = definitionItems[0]\n const verifiedResponse = await context.agent.siopVerifyAuthResponse({\n authorizationResponse,\n correlationId,\n dcqlQuery: definitionItem.query,\n })\n\n // FIXME SSISDK-55 add proper support for checking for DCQL presentations\n const presentation = verifiedResponse?.oid4vpSubmission?.presentation\n if (presentation && Object.keys(presentation).length > 0) {\n console.log('PRESENTATIONS:' + JSON.stringify(verifiedResponse?.oid4vpSubmission?.presentation, null, 2))\n response.statusCode = 200\n\n const authorizationChallengeValidationResponse: AuthorizationChallengeValidationResponse = {\n presentation_during_issuance_session: verifiedResponse.correlationId,\n }\n if (authorizationResponse.is_first_party) {\n response.setHeader('Content-Type', 'application/json')\n return response.send(JSON.stringify(authorizationChallengeValidationResponse))\n }\n\n const responseRedirectURI = await context.agent.siopGetRedirectURI({ correlationId, queryId, state: verifiedResponse.state })\n if (responseRedirectURI) {\n response.setHeader('Content-Type', 'application/json')\n return response.send(JSON.stringify({ redirect_uri: responseRedirectURI }))\n }\n // todo: delete session\n } else {\n console.log('Missing Presentation (Verifiable Credentials)')\n response.statusCode = 500\n response.statusMessage = 'Missing Presentation (Verifiable Credentials)'\n }\n return response.send()\n } catch (error) {\n console.error(error)\n return sendErrorResponse(response, 500, 'Could not verify auth status', error)\n }\n })\n}\n\nexport function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`getAuthRequest SIOP endpoint is disabled`)\n return\n }\n const path = opts?.path ?? '/siop/queries/:queryId/auth-requests/:correlationId'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const correlationId = request.params.correlationId\n const queryId = request.params.queryId\n if (!correlationId || !queryId) {\n console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, queryId: ${queryId}`)\n return sendErrorResponse(response, 404, 'No authorization request could be found')\n }\n const requestState = await context.agent.siopGetAuthRequestState({\n correlationId,\n errorOnNotFound: false,\n })\n if (!requestState) {\n console.log(\n `No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${queryId}`,\n )\n return sendErrorResponse(response, 404, `No authorization request could be found`)\n }\n\n const definitionItems = await context.agent.pdmGetDefinitions({ filter: [{ queryId }] });\n if (definitionItems.length === 0) {\n console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`)\n response.statusCode = 404\n response.statusMessage = `No definition ${queryId}`\n return response.send()\n }\n const payload = requestState.request?.requestObject?.getPayload()!\n payload.dcql_query = definitionItems[0].query\n const requestObject = await requestState.request?.requestObject?.toJwt()\n console.log('JWT Request object:')\n console.log(requestObject)\n\n let error: string | undefined\n try {\n response.statusCode = 200\n response.setHeader('Content-Type', 'application/jwt')\n return response.send(requestObject)\n } catch (e) {\n error = typeof e === 'string' ? e : e instanceof Error ? e.message : undefined\n return sendErrorResponse(response, 500, 'Could not get authorization request', e)\n } finally {\n await context.agent.siopUpdateAuthRequestState({\n correlationId,\n state: 'authorization_request_created',\n error,\n })\n }\n } catch (error) {\n return sendErrorResponse(response, 500, 'Could not get authorization request', error)\n }\n })\n}\n","import {\n AuthorizationRequestStateStatus,\n CreateAuthorizationRequest,\n createAuthorizationRequestFromPayload,\n CreateAuthorizationRequestPayloadSchema,\n CreateAuthorizationResponsePayload,\n} from '@sphereon/did-auth-siop'\nimport { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'\nimport { uriWithBase } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'\nimport { Request, Response, Router } from 'express'\nimport uuid from 'short-uuid'\nimport { validateData } from './middleware/validationMiddleware'\nimport {\n AuthStatusResponse,\n CreateAuthorizationRequestPayloadRequest,\n CreateAuthorizationResponsePayloadResponse,\n DeleteAuthorizationRequest,\n GetAuthorizationRequestStatus,\n ICreateAuthRequestWebappEndpointOpts,\n IRequiredContext,\n QRCodeOpts,\n} from './types'\n\nexport function createAuthRequestUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ICreateAuthRequestWebappEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`createAuthRequest universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/auth/requests'\n router.post(\n path,\n checkAuth(opts?.endpoint),\n validateData(CreateAuthorizationRequestPayloadSchema),\n async (request: CreateAuthorizationRequestPayloadRequest, response: CreateAuthorizationResponsePayloadResponse) => {\n try {\n const authRequest: CreateAuthorizationRequest = createAuthorizationRequestFromPayload(request.body)\n const correlationId = authRequest.correlationId ?? uuid.uuid()\n const qrCodeOpts = authRequest.qrCode ? ({ ...authRequest.qrCode } satisfies QRCodeOpts) : opts?.qrCodeOpts\n const queryId = authRequest.queryId\n\n const definitionItems = await context.agent.pdmGetDefinitions({\n filter: [\n { id: queryId }, // Allow both PK (unique queryId + version combi) or just plain queryId which assumes the latest version\n { queryId },\n ],\n })\n if (definitionItems.length === 0) {\n console.log(`No query could be found for the given id. Query id: ${queryId}`)\n return sendErrorResponse(response, 404, { status: 404, message: 'No query could be found' })\n }\n\n const requestByReferenceURI = uriWithBase(`/siop/queries/${queryId}/auth-requests/${correlationId}`, {\n baseURI: authRequest.requestUriBase ?? opts?.siopBaseURI,\n })\n const responseURI = uriWithBase(`/siop/queries/${queryId}/auth-responses/${correlationId}`, { baseURI: opts?.siopBaseURI })\n\n const authRequestURI = await context.agent.siopCreateAuthRequestURI({\n queryId,\n correlationId,\n nonce: uuid.uuid(),\n requestByReferenceURI,\n responseURIType: 'response_uri',\n responseURI,\n ...(authRequest.directPostResponseRedirectUri && { responseRedirectURI: authRequest.directPostResponseRedirectUri }),\n ...(authRequest.callback && { callback: authRequest.callback }),\n })\n\n let qrCodeDataUri: string | undefined\n if (qrCodeOpts) {\n const { AwesomeQR } = await import('awesome-qr')\n const qrCode = new AwesomeQR({ ...qrCodeOpts, text: authRequestURI })\n qrCodeDataUri = `data:image/png;base64,${(await qrCode.draw())!.toString('base64')}`\n } else {\n qrCodeDataUri = authRequestURI\n }\n\n const authRequestBody = {\n query_id: queryId,\n correlation_id: correlationId,\n request_uri: authRequestURI,\n status_uri: `${uriWithBase(opts?.webappAuthStatusPath ?? `/backend/auth/status/${correlationId}`, { baseURI: opts?.webappBaseURI })}`,\n ...(qrCodeDataUri && { qr_uri: qrCodeDataUri }),\n } satisfies CreateAuthorizationResponsePayload\n console.log(`Auth Request URI data to send back: ${JSON.stringify(authRequestBody)}`)\n\n return response.status(201).json(authRequestBody)\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: 'Could not create an authorization request URI' }, error)\n }\n },\n )\n}\n\nexport function removeAuthRequestStateUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`removeAuthStatus universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/auth/requests/:correlationId'\n router.delete(path, checkAuth(opts?.endpoint), async (request: DeleteAuthorizationRequest, response: Response) => {\n try {\n const correlationId: string = request.params.correlationId\n\n const authRequestState = await context.agent.siopGetAuthRequestState({\n correlationId,\n errorOnNotFound: false,\n })\n if (!authRequestState) {\n console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`)\n return sendErrorResponse(response, 404, { status: 404, message: 'No authorization request could be found' })\n }\n\n await context.agent.siopDeleteAuthState({ correlationId })\n\n return response.status(204).json()\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: error.message }, error)\n }\n })\n}\n\nexport function authStatusUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`authStatus universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/auth/status/:correlationId'\n router.get(path, checkAuth(opts?.endpoint), async (request: GetAuthorizationRequestStatus, response: Response) => {\n try {\n console.log('Received auth-status request...')\n const correlationId: string = request.params.correlationId\n\n const requestState = await context.agent.siopGetAuthRequestState({\n correlationId,\n errorOnNotFound: false,\n })\n\n if (!requestState) {\n console.log(`No authorization request could be found for the given correlationId. correlationId: ${correlationId}`)\n return sendErrorResponse(response, 404, { status: 404, message: 'No authorization request could be found' })\n }\n\n let responseState\n if (requestState.status === AuthorizationRequestStateStatus.RETRIEVED) {\n responseState = await context.agent.siopGetAuthResponseState({\n correlationId,\n errorOnNotFound: false\n })\n }\n const overallState = responseState ?? requestState\n\n const statusBody = {\n status: overallState.status,\n correlation_id: overallState.correlationId,\n query_id: overallState.queryId,\n last_updated: overallState.lastUpdated,\n ...('verifiedData' in overallState && { verified_data: overallState.verifiedData }),\n ...(overallState.error && { message: overallState.error.message })\n } satisfies AuthStatusResponse\n console.debug(`Will send auth status: ${JSON.stringify(statusBody)}`)\n\n if (overallState.status === 'error') {\n return response.status(500).json(statusBody)\n }\n return response.status(200).json(statusBody)\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: error.message }, error)\n }\n })\n}\n\nexport function getDefinitionsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {\n if (opts?.enabled === false) {\n console.log(`getDefinitions universal OID4VP endpoint is disabled`)\n return\n }\n\n const path = opts?.path ?? '/backend/definitions'\n router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {\n try {\n const definitions = await context.agent.pdmGetDefinitions()\n response.statusCode = 200\n return response.json(definitions)\n } catch (error) {\n return sendErrorResponse(response, 500, { status: 500, message: error.message }, error)\n }\n })\n}\n","import { Request, Response, NextFunction } from 'express';\nimport { z, ZodError } from 'zod';\n\nexport const validateData = (schema: z.ZodObject<any, any>) => {\n return (req: Request, res: Response, next: NextFunction) => {\n try {\n schema.parse(req.body);\n next();\n } catch (error) {\n if (error instanceof ZodError) {\n const errorMessages = error.issues.map((issue: any) => ({\n message: `${issue.path.join('.')} is ${issue.message}`,\n }))\n res.status(400).json({ status: 400, message: 'Invalid data', error_details: errorMessages[0].message });\n } else {\n res.status(500).json({ status: 500, message: 'Internal Server Error' });\n }\n }\n };\n}\n","import { agentContext } from '@sphereon/ssi-sdk.core'\nimport { copyGlobalAuthToEndpoints, ExpressSupport } from '@sphereon/ssi-express-support'\nimport { ISIOPv2RP } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth'\nimport { TAgent } from '@veramo/core'\nimport express, { Express, Request, Response, Router } from 'express'\nimport { getAuthRequestSIOPv2Endpoint, verifyAuthResponseSIOPv2Endpoint } from './siop-api-functions'\nimport { IRequiredPlugins, ISIOPv2RPRestAPIOpts } from './types'\nimport {\n authStatusUniversalOID4VPEndpoint,\n createAuthRequestUniversalOID4VPEndpoint,\n getDefinitionsEndpoint,\n removeAuthRequestStateUniversalOID4VPEndpoint,\n} from './universal-oid4vp-api-functions'\nimport swaggerUi from 'swagger-ui-express'\n\nexport class SIOPv2RPApiServer {\n private readonly _express: Express\n private readonly _router: Router\n private readonly _agent: TAgent<ISIOPv2RP>\n private readonly _opts?: ISIOPv2RPRestAPIOpts\n private readonly _basePath: string\n\n private readonly OID4VP_SWAGGER_URL = 'https://api.swaggerhub.com/apis/SphereonInt/OID4VP/0.1.0'\n constructor(args: { agent: TAgent<IRequiredPlugins>; expressSupport: ExpressSupport; opts?: ISIOPv2RPRestAPIOpts }) {\n const { agent, opts } = args\n this._agent = agent\n copyGlobalAuthToEndpoints({ opts, keys: ['webappCreateAuthRequest', 'webappAuthStatus', 'webappDeleteAuthRequest'] })\n if (opts?.endpointOpts?.globalAuth?.secureSiopEndpoints) {\n copyGlobalAuthToEndpoints({ opts, keys: ['siopGetAuthRequest', 'siopVerifyAuthResponse'] })\n }\n\n this._opts = opts\n this._express = args.expressSupport.express\n this._router = express.Router()\n const context = agentContext(agent)\n\n const features = opts?.enableFeatures ?? ['rp-status', 'siop']\n console.log(`SIOPv2 API enabled, with features: ${JSON.stringify(features)}}`)\n\n // Webapp endpoints\n if (features.includes('rp-status')) {\n createAuthRequestUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappCreateAuthRequest)\n authStatusUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappAuthStatus)\n removeAuthRequestStateUniversalOID4VPEndpoint(this._router, context, opts?.endpointOpts?.webappDeleteAuthRequest)\n getDefinitionsEndpoint(this._router, context, opts?.endpointOpts?.webappGetDefinitions)\n }\n\n // SIOPv2 endpoints\n if (features.includes('siop')) {\n getAuthRequestSIOPv2Endpoint(this._router, context, opts?.endpointOpts?.siopGetAuthRequest)\n verifyAuthResponseSIOPv2Endpoint(this._router, context, opts?.endpointOpts?.siopVerifyAuthResponse)\n }\n this._basePath = opts?.endpointOpts?.basePath ?? ''\n this._express.use(this._basePath, this.router)\n this._express.set('trust proxy', opts?.endpointOpts?.trustProxy ?? true)\n this.setupSwaggerUi()\n }\n\n private setupSwaggerUi() {\n fetch(this.OID4VP_SWAGGER_URL)\n .then((res) => res.json())\n .then((swagger: any) => {\n const apiDocs = `${this._basePath}/api-docs`\n console.log(`[OID4P] API docs available at ${apiDocs}`)\n\n this._router.use(\n '/api-docs',\n (req: Request, res: Response, next: any) => {\n const regex = `${apiDocs.replace(/\\//, '\\/')}`.replace('/oid4vp', '').replace(/\\/api-docs.*/, '')\n swagger.servers = [{ url: `${req.protocol}://${req.get('host')}${regex}`, description: 'This server' }]\n // @ts-ignore\n req.swaggerDoc = swagger\n next()\n },\n swaggerUi.serveFiles(swagger, options),\n swaggerUi.setup(),\n )\n })\n .catch((err) => {\n console.log(`[OID4VP] Unable to fetch swagger document: ${err}. Will not host api-docs on this instance`)\n })\n const options = {\n // customCss: '.swagger-ui .topbar { display: none }',\n }\n }\n get express(): Express {\n return this._express\n }\n\n get router(): Router {\n return this._router\n }\n\n get agent(): TAgent<ISIOPv2RP> {\n return this._agent\n }\n\n get opts(): ISIOPv2RPRestAPIOpts | undefined {\n return this._opts\n }\n}\n"],"mappings":";;;;AACA,SAASA,WAAgCC,yBAAyB;AAElE,SAASC,wBAAwB;AAIjC,IAAMC,6BAA6B,wBAACC,YAAAA;AAClC,QAAMC,cAAcD,QAAQE,OAAO,cAAA;AAEnC,MAAID,gBAAgB,oBAAoB;AACtC,UAAME,UAAU,OAAOH,QAAQI,SAAS,WAAWC,KAAKC,MAAMN,QAAQI,IAAI,IAAIJ,QAAQI;AACtF,WAAOD;EACT;AAEA,MAAIF,gBAAgB,qCAAqC;AACvD,UAAME,UAAUH,QAAQI;AAGxB,QAAI,OAAOD,QAAQI,4BAA4B,UAAU;AACvDC,cAAQC,IAAI,gIAAgI;AAC5IN,cAAQI,0BAA0BF,KAAKC,MAAMH,QAAQI,uBAAuB;IAC9E;AAGA,QAAI,OAAOJ,QAAQO,aAAa,UAAU;AACxC,YAAM,EAAEA,SAAQ,IAAKP;AAIrB,UAAKO,SAASC,WAAW,GAAA,KAAQD,SAASE,SAAS,GAAA,KAASC,iBAAiBC,iBAAiBJ,QAAAA,GAAW;AACvGP,gBAAQO,WAAWL,KAAKC,MAAMI,QAAAA;MAChC;IACF;AAEA,WAAOP;EACT;AAEA,QAAM,IAAIY,MACR,6BAA6Bd,WAAAA,yGAAoH;AAErJ,GAlCmC;AAoC5B,SAASe,iCAAiCC,QAAgBC,SAA2BC,MAA0B;AACpH,MAAIA,MAAMC,YAAY,OAAO;AAC3BZ,YAAQC,IAAI,8CAA8C;AAC1D;EACF;AACA,QAAMY,OAAOF,MAAME,QAAQ;AAC3BJ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,IAAI/C,UAAmB;AACrB,WAAO,KAAKf;EACd;EAEA,IAAIwC,SAAiB;AACnB,WAAO,KAAKvC;EACd;EAEA,IAAIM,QAA2B;AAC7B,WAAO,KAAKL;EACd;EAEA,IAAIM,OAAyC;AAC3C,WAAO,KAAKL;EACd;AACF;","names":["checkAuth","sendErrorResponse","CredentialMapper","parseAuthorizationResponse","request","contentType","header","payload","body","JSON","parse","presentation_submission","console","log","vp_token","startsWith","endsWith","CredentialMapper","isJsonLdAsString","Error","verifyAuthResponseSIOPv2Endpoint","router","context","opts","enabled","path","post","checkAuth","endpoint","response","correlationId","queryId","tenantId","version","params","sendErrorResponse","debug","stringify","definitionItems","agent","pdmGetDefinitions","filter","id","length","statusCode","statusMessage","send","authorizationResponse","definitionItem","verifiedResponse","siopVerifyAuthResponse","dcqlQuery","query","presentation","oid4vpSubmission","Object","keys","authorizationChallengeValidationResponse","presentation_during_issuance_session","is_first_party","setHeader","responseRedirectURI","siopGetRedirectURI","state","redirect_uri","error","getAuthRequestSIOPv2Endpoint","get","requestState","siopGetAuthRequestState","errorOnNotFound","requestObject","getPayload","dcql_query","toJwt","e","message","undefined","siopUpdateAuthRequestState","AuthorizationRequestStateStatus","createAuthorizationRequestFromPayload","CreateAuthorizationRequestPayloadSchema","checkAuth","sendErrorResponse","uriWithBase","uuid","ZodError","validateData","schema","req","res","next","parse","body","error","ZodError","errorMessages","issues","map","issue","message","path","join","status","json","error_details","createAuthRequestUniversalOID4VPEndpoint","router","context","opts","enabled","console","log","path","post","checkAuth","endpoint","validateData","CreateAuthorizationRequestPayloadSchema","request","response","authRequest","createAuthorizationRequestFromPayload","body","correlationId","uuid","qrCodeOpts","qrCode","queryId","definitionItems","agent","pdmGetDefinitions","filter","id","length","sendErrorResponse","status","message","requestByReferenceURI","uriWithBase","baseURI","requestUriBase","siopBaseURI","responseURI","authRequestURI","siopCreateAuthRequestURI","nonce","responseURIType","directPostResponseRedirectUri","responseRedirectURI","callback","qrCodeDataUri","AwesomeQR","text","draw","toString","authRequestBody","query_id","correlation_id","request_uri","status_uri","webappAuthStatusPath","webappBaseURI","qr_uri","JSON","stringify","json","error","removeAuthRequestStateUniversalOID4VPEndpoint","delete","params","authRequestState","siopGetAuthRequestState","errorOnNotFound","siopDeleteAuthState","authStatusUniversalOID4VPEndpoint","get","requestState","responseState","AuthorizationRequestStateStatus","RETRIEVED","siopGetAuthResponseState","overallState","statusBody","last_updated","lastUpdated","verified_data","verifiedData","debug","getDefinitionsEndpoint","definitions","statusCode","agentContext","copyGlobalAuthToEndpoints","express","swaggerUi","SIOPv2RPApiServer","_express","_router","_agent","_opts","_basePath","OID4VP_SWAGGER_URL","args","agent","opts","copyGlobalAuthToEndpoints","keys","endpointOpts","globalAuth","secureSiopEndpoints","expressSupport","express","Router","context","agentContext","features","enableFeatures","console","log","JSON","stringify","includes","createAuthRequestUniversalOID4VPEndpoint","webappCreateAuthRequest","authStatusUniversalOID4VPEndpoint","webappAuthStatus","removeAuthRequestStateUniversalOID4VPEndpoint","webappDeleteAuthRequest","getDefinitionsEndpoint","webappGetDefinitions","getAuthRequestSIOPv2Endpoint","siopGetAuthRequest","verifyAuthResponseSIOPv2Endpoint","siopVerifyAuthResponse","basePath","use","router","set","trustProxy","setupSwaggerUi","fetch","then","res","json","swagger","apiDocs","req","next","regex","replace","servers","url","protocol","get","description","swaggerDoc","swaggerUi","serveFiles","options","setup","catch","err"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api",
|
|
3
|
-
"version": "0.34.1-fix.
|
|
3
|
+
"version": "0.34.1-fix.223+9c86d039",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
"start:dev": "ts-node __tests__/RestAPI.ts"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@sphereon/did-auth-siop": "0.19.1-
|
|
27
|
-
"@sphereon/ssi-express-support": "0.34.1-fix.
|
|
28
|
-
"@sphereon/ssi-sdk.core": "0.34.1-fix.
|
|
29
|
-
"@sphereon/ssi-sdk.credential-validation": "0.34.1-fix.
|
|
30
|
-
"@sphereon/ssi-sdk.kv-store-temp": "0.34.1-fix.
|
|
31
|
-
"@sphereon/ssi-sdk.pd-manager": "0.34.1-fix.
|
|
32
|
-
"@sphereon/ssi-sdk.presentation-exchange": "0.34.1-fix.
|
|
33
|
-
"@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-fix.
|
|
34
|
-
"@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth": "0.34.1-fix.
|
|
35
|
-
"@sphereon/ssi-types": "0.34.1-fix.
|
|
26
|
+
"@sphereon/did-auth-siop": "0.19.1-feature.DIIPv4.170",
|
|
27
|
+
"@sphereon/ssi-express-support": "0.34.1-fix.223+9c86d039",
|
|
28
|
+
"@sphereon/ssi-sdk.core": "0.34.1-fix.223+9c86d039",
|
|
29
|
+
"@sphereon/ssi-sdk.credential-validation": "0.34.1-fix.223+9c86d039",
|
|
30
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.34.1-fix.223+9c86d039",
|
|
31
|
+
"@sphereon/ssi-sdk.pd-manager": "0.34.1-fix.223+9c86d039",
|
|
32
|
+
"@sphereon/ssi-sdk.presentation-exchange": "0.34.1-fix.223+9c86d039",
|
|
33
|
+
"@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-fix.223+9c86d039",
|
|
34
|
+
"@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth": "0.34.1-fix.223+9c86d039",
|
|
35
|
+
"@sphereon/ssi-types": "0.34.1-fix.223+9c86d039",
|
|
36
36
|
"@veramo/core": "4.2.0",
|
|
37
37
|
"@veramo/credential-w3c": "4.2.0",
|
|
38
38
|
"awesome-qr": "^2.1.5-rc.0",
|
|
@@ -49,14 +49,16 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@decentralized-identity/ion-sdk": "^0.6.0",
|
|
52
|
-
"@sphereon/did-auth-siop-adapter": "0.19.1-
|
|
52
|
+
"@sphereon/did-auth-siop-adapter": "0.19.1-feature.DIIPv4.170",
|
|
53
53
|
"@sphereon/did-uni-client": "^0.6.3",
|
|
54
|
-
"@sphereon/
|
|
55
|
-
"@sphereon/
|
|
56
|
-
"@sphereon/ssi-sdk-ext.
|
|
57
|
-
"@sphereon/ssi-sdk.
|
|
58
|
-
"@sphereon/ssi-sdk.
|
|
59
|
-
"@sphereon/ssi-sdk.
|
|
54
|
+
"@sphereon/pex": "5.0.0-unstable.28",
|
|
55
|
+
"@sphereon/pex-models": "^2.3.2",
|
|
56
|
+
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.34.1-fix.223+9c86d039",
|
|
57
|
+
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.34.1-fix.223+9c86d039",
|
|
58
|
+
"@sphereon/ssi-sdk-ext.jwt-service": "0.34.1-fix.223+9c86d039",
|
|
59
|
+
"@sphereon/ssi-sdk.credential-vcdm": "0.34.1-fix.223+9c86d039",
|
|
60
|
+
"@sphereon/ssi-sdk.credential-vcdm-jsonld-provider": "0.34.1-fix.223+9c86d039",
|
|
61
|
+
"@sphereon/ssi-sdk.data-store": "0.34.1-fix.223+9c86d039",
|
|
60
62
|
"@types/body-parser": "^1.19.5",
|
|
61
63
|
"@types/cookie-parser": "^1.4.7",
|
|
62
64
|
"@types/cors": "^2.8.17",
|
|
@@ -115,5 +117,5 @@
|
|
|
115
117
|
"OpenID Connect",
|
|
116
118
|
"Authenticator"
|
|
117
119
|
],
|
|
118
|
-
"gitHead": "
|
|
120
|
+
"gitHead": "9c86d03951f1267495e456d1fbfd9eb380f27e78"
|
|
119
121
|
}
|
|
@@ -46,21 +46,32 @@ export function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequi
|
|
|
46
46
|
console.log(`verifyAuthResponse SIOP endpoint is disabled`)
|
|
47
47
|
return
|
|
48
48
|
}
|
|
49
|
-
const path = opts?.path ?? '/siop/
|
|
49
|
+
const path = opts?.path ?? '/siop/queries/:queryId/auth-responses/:correlationId'
|
|
50
50
|
router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
51
51
|
try {
|
|
52
|
-
const { correlationId,
|
|
53
|
-
if (!correlationId
|
|
54
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}
|
|
52
|
+
const { correlationId, queryId, tenantId, version } = request.params
|
|
53
|
+
if (!correlationId) {
|
|
54
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}`)
|
|
55
55
|
return sendErrorResponse(response, 404, 'No authorization request could be found')
|
|
56
56
|
}
|
|
57
|
-
console.
|
|
58
|
-
console.
|
|
59
|
-
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
57
|
+
console.debug('Authorization Response (siop-sessions') // TODO use logger
|
|
58
|
+
console.debug(JSON.stringify(request.body, null, 2))
|
|
59
|
+
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
60
|
+
filter: [
|
|
61
|
+
{
|
|
62
|
+
queryId,
|
|
63
|
+
...(tenantId && { tenantId }),
|
|
64
|
+
...(version && { version }),
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: queryId,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
})
|
|
60
71
|
if (definitionItems.length === 0) {
|
|
61
|
-
console.log(`Could not get
|
|
72
|
+
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`)
|
|
62
73
|
response.statusCode = 404
|
|
63
|
-
response.statusMessage = `No definition ${
|
|
74
|
+
response.statusMessage = `No definition ${queryId}`
|
|
64
75
|
return response.send()
|
|
65
76
|
}
|
|
66
77
|
|
|
@@ -71,7 +82,7 @@ export function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequi
|
|
|
71
82
|
const verifiedResponse = await context.agent.siopVerifyAuthResponse({
|
|
72
83
|
authorizationResponse,
|
|
73
84
|
correlationId,
|
|
74
|
-
|
|
85
|
+
dcqlQuery: definitionItem.query,
|
|
75
86
|
})
|
|
76
87
|
|
|
77
88
|
// FIXME SSISDK-55 add proper support for checking for DCQL presentations
|
|
@@ -88,7 +99,7 @@ export function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequi
|
|
|
88
99
|
return response.send(JSON.stringify(authorizationChallengeValidationResponse))
|
|
89
100
|
}
|
|
90
101
|
|
|
91
|
-
const responseRedirectURI = await context.agent.siopGetRedirectURI({ correlationId, queryId
|
|
102
|
+
const responseRedirectURI = await context.agent.siopGetRedirectURI({ correlationId, queryId, state: verifiedResponse.state })
|
|
92
103
|
if (responseRedirectURI) {
|
|
93
104
|
response.setHeader('Content-Type', 'application/json')
|
|
94
105
|
return response.send(JSON.stringify({ redirect_uri: responseRedirectURI }))
|
|
@@ -112,37 +123,35 @@ export function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredC
|
|
|
112
123
|
console.log(`getAuthRequest SIOP endpoint is disabled`)
|
|
113
124
|
return
|
|
114
125
|
}
|
|
115
|
-
const path = opts?.path ?? '/siop/
|
|
126
|
+
const path = opts?.path ?? '/siop/queries/:queryId/auth-requests/:correlationId'
|
|
116
127
|
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
117
128
|
try {
|
|
118
129
|
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},
|
|
130
|
+
const queryId = request.params.queryId
|
|
131
|
+
if (!correlationId || !queryId) {
|
|
132
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, queryId: ${queryId}`)
|
|
122
133
|
return sendErrorResponse(response, 404, 'No authorization request could be found')
|
|
123
134
|
}
|
|
124
135
|
const requestState = await context.agent.siopGetAuthRequestState({
|
|
125
136
|
correlationId,
|
|
126
|
-
//queryId: definitionId,
|
|
127
137
|
errorOnNotFound: false,
|
|
128
138
|
})
|
|
129
139
|
if (!requestState) {
|
|
130
140
|
console.log(
|
|
131
|
-
`No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${
|
|
141
|
+
`No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${queryId}`,
|
|
132
142
|
)
|
|
133
143
|
return sendErrorResponse(response, 404, `No authorization request could be found`)
|
|
134
144
|
}
|
|
135
145
|
|
|
136
|
-
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
146
|
+
const definitionItems = await context.agent.pdmGetDefinitions({ filter: [{ queryId }] });
|
|
147
|
+
if (definitionItems.length === 0) {
|
|
148
|
+
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`)
|
|
149
|
+
response.statusCode = 404
|
|
150
|
+
response.statusMessage = `No definition ${queryId}`
|
|
151
|
+
return response.send()
|
|
152
|
+
}
|
|
143
153
|
const payload = requestState.request?.requestObject?.getPayload()!
|
|
144
|
-
payload.dcql_query = definitionItems[0].
|
|
145
|
-
|
|
154
|
+
payload.dcql_query = definitionItems[0].query
|
|
146
155
|
const requestObject = await requestState.request?.requestObject?.toJwt()
|
|
147
156
|
console.log('JWT Request object:')
|
|
148
157
|
console.log(requestObject)
|
|
@@ -158,7 +167,6 @@ export function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredC
|
|
|
158
167
|
} finally {
|
|
159
168
|
await context.agent.siopUpdateAuthRequestState({
|
|
160
169
|
correlationId,
|
|
161
|
-
//queryId: definitionId,
|
|
162
170
|
state: 'authorization_request_created',
|
|
163
171
|
error,
|
|
164
172
|
})
|