@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api 0.34.1-fix.226 → 0.34.1-fix.254
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 +30 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +30 -30
- package/dist/index.js.map +1 -1
- package/package.json +21 -19
- package/src/siop-api-functions.ts +22 -16
- package/src/universal-oid4vp-api-functions.ts +4 -6
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ var index_exports = {};
|
|
|
33
33
|
__export(index_exports, {
|
|
34
34
|
SIOPv2RPApiServer: () => SIOPv2RPApiServer,
|
|
35
35
|
authStatusUniversalOID4VPEndpoint: () => authStatusUniversalOID4VPEndpoint,
|
|
36
|
+
buildQueryIdFilter: () => buildQueryIdFilter,
|
|
36
37
|
createAuthRequestUniversalOID4VPEndpoint: () => createAuthRequestUniversalOID4VPEndpoint,
|
|
37
38
|
getAuthRequestSIOPv2Endpoint: () => getAuthRequestSIOPv2Endpoint,
|
|
38
39
|
getDefinitionsEndpoint: () => getDefinitionsEndpoint,
|
|
@@ -44,6 +45,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
44
45
|
// src/siop-api-functions.ts
|
|
45
46
|
var import_ssi_express_support = require("@sphereon/ssi-express-support");
|
|
46
47
|
var import_ssi_types = require("@sphereon/ssi-types");
|
|
48
|
+
var import_uuid = require("uuid");
|
|
47
49
|
var parseAuthorizationResponse = /* @__PURE__ */ __name((request) => {
|
|
48
50
|
const contentType = request.header("content-type");
|
|
49
51
|
if (contentType === "application/json") {
|
|
@@ -66,6 +68,9 @@ var parseAuthorizationResponse = /* @__PURE__ */ __name((request) => {
|
|
|
66
68
|
}
|
|
67
69
|
throw new Error(`Unsupported content type: ${contentType}. Currently only application/x-www-form-urlencoded and application/json (for direct_post) are supported`);
|
|
68
70
|
}, "parseAuthorizationResponse");
|
|
71
|
+
var validatePresentationSubmission = /* @__PURE__ */ __name((query, submission) => {
|
|
72
|
+
return query.credentials.every((credential) => credential.id in submission);
|
|
73
|
+
}, "validatePresentationSubmission");
|
|
69
74
|
function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
70
75
|
if (opts?.enabled === false) {
|
|
71
76
|
console.log(`verifyAuthResponse SIOP endpoint is disabled`);
|
|
@@ -82,20 +87,7 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
82
87
|
console.debug("Authorization Response (siop-sessions");
|
|
83
88
|
console.debug(JSON.stringify(request.body, null, 2));
|
|
84
89
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
85
|
-
filter:
|
|
86
|
-
{
|
|
87
|
-
queryId,
|
|
88
|
-
...tenantId && {
|
|
89
|
-
tenantId
|
|
90
|
-
},
|
|
91
|
-
...version && {
|
|
92
|
-
version
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
id: queryId
|
|
97
|
-
}
|
|
98
|
-
]
|
|
90
|
+
filter: buildQueryIdFilter(queryId, tenantId, version)
|
|
99
91
|
});
|
|
100
92
|
if (definitionItems.length === 0) {
|
|
101
93
|
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`);
|
|
@@ -112,8 +104,8 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
112
104
|
dcqlQuery: definitionItem.query
|
|
113
105
|
});
|
|
114
106
|
const presentation = verifiedResponse?.oid4vpSubmission?.presentation;
|
|
115
|
-
if (presentation &&
|
|
116
|
-
console.log("PRESENTATIONS:" + JSON.stringify(
|
|
107
|
+
if (presentation && validatePresentationSubmission(definitionItem.query, presentation)) {
|
|
108
|
+
console.log("PRESENTATIONS:" + JSON.stringify(presentation, null, 2));
|
|
117
109
|
response.statusCode = 200;
|
|
118
110
|
const authorizationChallengeValidationResponse = {
|
|
119
111
|
presentation_during_issuance_session: verifiedResponse.correlationId
|
|
@@ -124,7 +116,6 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
124
116
|
}
|
|
125
117
|
const responseRedirectURI = await context.agent.siopGetRedirectURI({
|
|
126
118
|
correlationId,
|
|
127
|
-
queryId,
|
|
128
119
|
state: verifiedResponse.state
|
|
129
120
|
});
|
|
130
121
|
if (responseRedirectURI) {
|
|
@@ -169,11 +160,7 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
169
160
|
return (0, import_ssi_express_support.sendErrorResponse)(response, 404, `No authorization request could be found`);
|
|
170
161
|
}
|
|
171
162
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
172
|
-
filter:
|
|
173
|
-
{
|
|
174
|
-
queryId
|
|
175
|
-
}
|
|
176
|
-
]
|
|
163
|
+
filter: buildQueryIdFilter(queryId)
|
|
177
164
|
});
|
|
178
165
|
if (definitionItems.length === 0) {
|
|
179
166
|
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`);
|
|
@@ -207,6 +194,26 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
207
194
|
});
|
|
208
195
|
}
|
|
209
196
|
__name(getAuthRequestSIOPv2Endpoint, "getAuthRequestSIOPv2Endpoint");
|
|
197
|
+
function buildQueryIdFilter(queryId, tenantId, version) {
|
|
198
|
+
const queryFilter = {
|
|
199
|
+
queryId,
|
|
200
|
+
...tenantId ? {
|
|
201
|
+
tenantId
|
|
202
|
+
} : {},
|
|
203
|
+
...version ? {
|
|
204
|
+
version
|
|
205
|
+
} : {}
|
|
206
|
+
};
|
|
207
|
+
return [
|
|
208
|
+
queryFilter,
|
|
209
|
+
...(0, import_uuid.validate)(queryId) ? [
|
|
210
|
+
{
|
|
211
|
+
id: queryId
|
|
212
|
+
}
|
|
213
|
+
] : []
|
|
214
|
+
];
|
|
215
|
+
}
|
|
216
|
+
__name(buildQueryIdFilter, "buildQueryIdFilter");
|
|
210
217
|
|
|
211
218
|
// src/universal-oid4vp-api-functions.ts
|
|
212
219
|
var import_did_auth_siop = require("@sphereon/did-auth-siop");
|
|
@@ -257,14 +264,7 @@ function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
|
257
264
|
} : opts?.qrCodeOpts;
|
|
258
265
|
const queryId = authRequest.queryId;
|
|
259
266
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
260
|
-
filter:
|
|
261
|
-
{
|
|
262
|
-
id: queryId
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
queryId
|
|
266
|
-
}
|
|
267
|
-
]
|
|
267
|
+
filter: buildQueryIdFilter(queryId)
|
|
268
268
|
});
|
|
269
269
|
if (definitionItems.length === 0) {
|
|
270
270
|
console.log(`No query could be found for the given id. Query id: ${queryId}`);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/siop-api-functions.ts","../src/universal-oid4vp-api-functions.ts","../src/middleware/validationMiddleware.ts","../src/siopv2-rp-api-server.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './siop-api-functions'\nexport * from './universal-oid4vp-api-functions'\nexport * from './types'\nexport * from './siopv2-rp-api-server'\n","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;ACCA,iCAAkE;AAElE,uBAAiC;AAIjC,IAAMA,6BAA6B,wBAACC,YAAAA;AAClC,QAAMC,cAAcD,QAAQE,OAAO,cAAA;AAEnC,MAAID,gBAAgB,oB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,eAAc;EACrB;EAEQA,iBAAiB;AACvBC,UAAM,KAAKvC,kBAAkB,EAC1BwC,KAAK,CAACC,QAAQA,IAAIC,KAAI,CAAA,EACtBF,KAAK,CAACG,YAAAA;AACL,YAAMC,UAAU,GAAG,KAAK7C,SAAS;AACjCiB,cAAQC,IAAI,iCAAiC2B,OAAAA,EAAS;AAEtD,WAAKhD,QAAQsC,IACX,aACA,CAACW,KAAcJ,KAAeK,SAAAA;AAC5B,cAAMC,QAAQ,GAAGH,QAAQI,QAAQ,MAAM,GAAA,CAAA,GAAQA,QAAQ,WAAW,EAAA,EAAIA,QAAQ,gBAAgB,EAAA;AAC9FL,gBAAQM,UAAU;UAAC;YAAEC,KAAK,GAAGL,IAAIM,QAAQ,MAAMN,IAAIO,IAAI,MAAA,CAAA,GAAUL,KAAAA;YAASM,aAAa;UAAc;;AAErGR,YAAIS,aAAaX;AACjBG,aAAAA;MACF,GACAS,0BAAAA,QAAUC,WAAWb,SAASc,OAAAA,GAC9BF,0BAAAA,QAAUG,MAAK,CAAA;IAEnB,CAAA,EACCC,MAAM,CAACC,QAAAA;AACN5C,cAAQC,IAAI,8CAA8C2C,GAAAA,2CAA8C;IAC1G,CAAA;AACF,UAAMH,UAAU,CAEhB;EACF;EACA,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":["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","import_ssi_express_support","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","import_ssi_sdk","import_ssi_express_support","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/index.ts","../src/siop-api-functions.ts","../src/universal-oid4vp-api-functions.ts","../src/middleware/validationMiddleware.ts","../src/siopv2-rp-api-server.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './siop-api-functions'\nexport * from './universal-oid4vp-api-functions'\nexport * from './types'\nexport * from './siopv2-rp-api-server'\n","import { AuthorizationResponsePayload, PresentationSubmission } 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 { validate as isValidUUID } from 'uuid'\nimport { IRequiredContext } from './types'\nimport { DcqlQuery } from 'dcql'\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\nconst validatePresentationSubmission = (query: DcqlQuery, submission: PresentationSubmission): boolean => {\n return query.credentials.every(credential => credential.id in submission)\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: buildQueryIdFilter(queryId, tenantId, version),\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 const presentation = verifiedResponse?.oid4vpSubmission?.presentation\n if (presentation && validatePresentationSubmission(definitionItem.query, presentation)) {\n console.log('PRESENTATIONS:' + JSON.stringify(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, 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: buildQueryIdFilter(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\nexport function buildQueryIdFilter(queryId: string, tenantId?: string, version?: string) {\n const queryFilter = {\n queryId,\n ...(tenantId ? { tenantId } : {}),\n ...(version ? { version } : {}),\n }\n\n return [queryFilter, ...(isValidUUID(queryId) ? [{ id: queryId }] : [])] // Allow both PK (unique queryId + version combi) or just plain queryId which assumes the latest version\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 { buildQueryIdFilter } from './siop-api-functions'\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: buildQueryIdFilter(queryId),\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;ACCA,iCAAkE;AAElE,uBAAiC;AAEjC,kBAAwC;AAIxC,IAAMA,6BAA6B,wBAACC,YAAAA;AAClC,QAAMC,cAAcD,QAAQE,OA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AEA,IAAIM,OAAyC;AAC3C,WAAO,KAAKL;EACd;AACF;","names":["parseAuthorizationResponse","request","contentType","header","payload","body","JSON","parse","presentation_submission","console","log","vp_token","startsWith","endsWith","CredentialMapper","isJsonLdAsString","Error","validatePresentationSubmission","query","submission","credentials","every","credential","id","verifyAuthResponseSIOPv2Endpoint","router","context","opts","enabled","path","post","checkAuth","endpoint","response","correlationId","queryId","tenantId","version","params","sendErrorResponse","debug","stringify","definitionItems","agent","pdmGetDefinitions","filter","buildQueryIdFilter","length","statusCode","statusMessage","send","authorizationResponse","definitionItem","verifiedResponse","siopVerifyAuthResponse","dcqlQuery","presentation","oid4vpSubmission","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","queryFilter","isValidUUID","import_ssi_express_support","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","buildQueryIdFilter","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","import_ssi_sdk","import_ssi_express_support","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/dist/index.d.cts
CHANGED
|
@@ -262,6 +262,13 @@ interface AuthStatusResponse {
|
|
|
262
262
|
|
|
263
263
|
declare function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
264
264
|
declare function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
265
|
+
declare function buildQueryIdFilter(queryId: string, tenantId?: string, version?: string): ({
|
|
266
|
+
version?: string | undefined;
|
|
267
|
+
tenantId?: string | undefined;
|
|
268
|
+
queryId: string;
|
|
269
|
+
} | {
|
|
270
|
+
id: string;
|
|
271
|
+
})[];
|
|
265
272
|
|
|
266
273
|
declare function createAuthRequestUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ICreateAuthRequestWebappEndpointOpts): void;
|
|
267
274
|
declare function removeAuthRequestStateUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
@@ -287,4 +294,4 @@ declare class SIOPv2RPApiServer {
|
|
|
287
294
|
get opts(): ISIOPv2RPRestAPIOpts | undefined;
|
|
288
295
|
}
|
|
289
296
|
|
|
290
|
-
export { type AuthStatusResponse, type ComponentOptions, type CreateAuthorizationRequestPayloadRequest, type CreateAuthorizationResponsePayloadResponse, type DeleteAuthorizationRequest, type DeleteAuthorizationRequestPathParameters, type GetAuthorizationRequestStatus, type GetAuthorizationRequestStatusPathParameters, type ICreateAuthRequestWebappEndpointOpts, type IRequiredContext, type IRequiredPlugins, type ISIOPv2RPRestAPIOpts, type QRCodeOpts, type RequestError, SIOPv2RPApiServer, type SiopFeatures, authStatusUniversalOID4VPEndpoint, createAuthRequestUniversalOID4VPEndpoint, getAuthRequestSIOPv2Endpoint, getDefinitionsEndpoint, removeAuthRequestStateUniversalOID4VPEndpoint, verifyAuthResponseSIOPv2Endpoint };
|
|
297
|
+
export { type AuthStatusResponse, type ComponentOptions, type CreateAuthorizationRequestPayloadRequest, type CreateAuthorizationResponsePayloadResponse, type DeleteAuthorizationRequest, type DeleteAuthorizationRequestPathParameters, type GetAuthorizationRequestStatus, type GetAuthorizationRequestStatusPathParameters, type ICreateAuthRequestWebappEndpointOpts, type IRequiredContext, type IRequiredPlugins, type ISIOPv2RPRestAPIOpts, type QRCodeOpts, type RequestError, SIOPv2RPApiServer, type SiopFeatures, authStatusUniversalOID4VPEndpoint, buildQueryIdFilter, createAuthRequestUniversalOID4VPEndpoint, getAuthRequestSIOPv2Endpoint, getDefinitionsEndpoint, removeAuthRequestStateUniversalOID4VPEndpoint, verifyAuthResponseSIOPv2Endpoint };
|
package/dist/index.d.ts
CHANGED
|
@@ -262,6 +262,13 @@ interface AuthStatusResponse {
|
|
|
262
262
|
|
|
263
263
|
declare function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
264
264
|
declare function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
265
|
+
declare function buildQueryIdFilter(queryId: string, tenantId?: string, version?: string): ({
|
|
266
|
+
version?: string | undefined;
|
|
267
|
+
tenantId?: string | undefined;
|
|
268
|
+
queryId: string;
|
|
269
|
+
} | {
|
|
270
|
+
id: string;
|
|
271
|
+
})[];
|
|
265
272
|
|
|
266
273
|
declare function createAuthRequestUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ICreateAuthRequestWebappEndpointOpts): void;
|
|
267
274
|
declare function removeAuthRequestStateUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
@@ -287,4 +294,4 @@ declare class SIOPv2RPApiServer {
|
|
|
287
294
|
get opts(): ISIOPv2RPRestAPIOpts | undefined;
|
|
288
295
|
}
|
|
289
296
|
|
|
290
|
-
export { type AuthStatusResponse, type ComponentOptions, type CreateAuthorizationRequestPayloadRequest, type CreateAuthorizationResponsePayloadResponse, type DeleteAuthorizationRequest, type DeleteAuthorizationRequestPathParameters, type GetAuthorizationRequestStatus, type GetAuthorizationRequestStatusPathParameters, type ICreateAuthRequestWebappEndpointOpts, type IRequiredContext, type IRequiredPlugins, type ISIOPv2RPRestAPIOpts, type QRCodeOpts, type RequestError, SIOPv2RPApiServer, type SiopFeatures, authStatusUniversalOID4VPEndpoint, createAuthRequestUniversalOID4VPEndpoint, getAuthRequestSIOPv2Endpoint, getDefinitionsEndpoint, removeAuthRequestStateUniversalOID4VPEndpoint, verifyAuthResponseSIOPv2Endpoint };
|
|
297
|
+
export { type AuthStatusResponse, type ComponentOptions, type CreateAuthorizationRequestPayloadRequest, type CreateAuthorizationResponsePayloadResponse, type DeleteAuthorizationRequest, type DeleteAuthorizationRequestPathParameters, type GetAuthorizationRequestStatus, type GetAuthorizationRequestStatusPathParameters, type ICreateAuthRequestWebappEndpointOpts, type IRequiredContext, type IRequiredPlugins, type ISIOPv2RPRestAPIOpts, type QRCodeOpts, type RequestError, SIOPv2RPApiServer, type SiopFeatures, authStatusUniversalOID4VPEndpoint, buildQueryIdFilter, createAuthRequestUniversalOID4VPEndpoint, getAuthRequestSIOPv2Endpoint, getDefinitionsEndpoint, removeAuthRequestStateUniversalOID4VPEndpoint, verifyAuthResponseSIOPv2Endpoint };
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/siop-api-functions.ts
|
|
5
5
|
import { checkAuth, sendErrorResponse } from "@sphereon/ssi-express-support";
|
|
6
6
|
import { CredentialMapper } from "@sphereon/ssi-types";
|
|
7
|
+
import { validate as isValidUUID } from "uuid";
|
|
7
8
|
var parseAuthorizationResponse = /* @__PURE__ */ __name((request) => {
|
|
8
9
|
const contentType = request.header("content-type");
|
|
9
10
|
if (contentType === "application/json") {
|
|
@@ -26,6 +27,9 @@ var parseAuthorizationResponse = /* @__PURE__ */ __name((request) => {
|
|
|
26
27
|
}
|
|
27
28
|
throw new Error(`Unsupported content type: ${contentType}. Currently only application/x-www-form-urlencoded and application/json (for direct_post) are supported`);
|
|
28
29
|
}, "parseAuthorizationResponse");
|
|
30
|
+
var validatePresentationSubmission = /* @__PURE__ */ __name((query, submission) => {
|
|
31
|
+
return query.credentials.every((credential) => credential.id in submission);
|
|
32
|
+
}, "validatePresentationSubmission");
|
|
29
33
|
function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
30
34
|
if (opts?.enabled === false) {
|
|
31
35
|
console.log(`verifyAuthResponse SIOP endpoint is disabled`);
|
|
@@ -42,20 +46,7 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
42
46
|
console.debug("Authorization Response (siop-sessions");
|
|
43
47
|
console.debug(JSON.stringify(request.body, null, 2));
|
|
44
48
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
45
|
-
filter:
|
|
46
|
-
{
|
|
47
|
-
queryId,
|
|
48
|
-
...tenantId && {
|
|
49
|
-
tenantId
|
|
50
|
-
},
|
|
51
|
-
...version && {
|
|
52
|
-
version
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
id: queryId
|
|
57
|
-
}
|
|
58
|
-
]
|
|
49
|
+
filter: buildQueryIdFilter(queryId, tenantId, version)
|
|
59
50
|
});
|
|
60
51
|
if (definitionItems.length === 0) {
|
|
61
52
|
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`);
|
|
@@ -72,8 +63,8 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
72
63
|
dcqlQuery: definitionItem.query
|
|
73
64
|
});
|
|
74
65
|
const presentation = verifiedResponse?.oid4vpSubmission?.presentation;
|
|
75
|
-
if (presentation &&
|
|
76
|
-
console.log("PRESENTATIONS:" + JSON.stringify(
|
|
66
|
+
if (presentation && validatePresentationSubmission(definitionItem.query, presentation)) {
|
|
67
|
+
console.log("PRESENTATIONS:" + JSON.stringify(presentation, null, 2));
|
|
77
68
|
response.statusCode = 200;
|
|
78
69
|
const authorizationChallengeValidationResponse = {
|
|
79
70
|
presentation_during_issuance_session: verifiedResponse.correlationId
|
|
@@ -84,7 +75,6 @@ function verifyAuthResponseSIOPv2Endpoint(router, context, opts) {
|
|
|
84
75
|
}
|
|
85
76
|
const responseRedirectURI = await context.agent.siopGetRedirectURI({
|
|
86
77
|
correlationId,
|
|
87
|
-
queryId,
|
|
88
78
|
state: verifiedResponse.state
|
|
89
79
|
});
|
|
90
80
|
if (responseRedirectURI) {
|
|
@@ -129,11 +119,7 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
129
119
|
return sendErrorResponse(response, 404, `No authorization request could be found`);
|
|
130
120
|
}
|
|
131
121
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
132
|
-
filter:
|
|
133
|
-
{
|
|
134
|
-
queryId
|
|
135
|
-
}
|
|
136
|
-
]
|
|
122
|
+
filter: buildQueryIdFilter(queryId)
|
|
137
123
|
});
|
|
138
124
|
if (definitionItems.length === 0) {
|
|
139
125
|
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`);
|
|
@@ -167,6 +153,26 @@ function getAuthRequestSIOPv2Endpoint(router, context, opts) {
|
|
|
167
153
|
});
|
|
168
154
|
}
|
|
169
155
|
__name(getAuthRequestSIOPv2Endpoint, "getAuthRequestSIOPv2Endpoint");
|
|
156
|
+
function buildQueryIdFilter(queryId, tenantId, version) {
|
|
157
|
+
const queryFilter = {
|
|
158
|
+
queryId,
|
|
159
|
+
...tenantId ? {
|
|
160
|
+
tenantId
|
|
161
|
+
} : {},
|
|
162
|
+
...version ? {
|
|
163
|
+
version
|
|
164
|
+
} : {}
|
|
165
|
+
};
|
|
166
|
+
return [
|
|
167
|
+
queryFilter,
|
|
168
|
+
...isValidUUID(queryId) ? [
|
|
169
|
+
{
|
|
170
|
+
id: queryId
|
|
171
|
+
}
|
|
172
|
+
] : []
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
__name(buildQueryIdFilter, "buildQueryIdFilter");
|
|
170
176
|
|
|
171
177
|
// src/universal-oid4vp-api-functions.ts
|
|
172
178
|
import { AuthorizationRequestStateStatus, createAuthorizationRequestFromPayload, CreateAuthorizationRequestPayloadSchema } from "@sphereon/did-auth-siop";
|
|
@@ -217,14 +223,7 @@ function createAuthRequestUniversalOID4VPEndpoint(router, context, opts) {
|
|
|
217
223
|
} : opts?.qrCodeOpts;
|
|
218
224
|
const queryId = authRequest.queryId;
|
|
219
225
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
220
|
-
filter:
|
|
221
|
-
{
|
|
222
|
-
id: queryId
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
queryId
|
|
226
|
-
}
|
|
227
|
-
]
|
|
226
|
+
filter: buildQueryIdFilter(queryId)
|
|
228
227
|
});
|
|
229
228
|
if (definitionItems.length === 0) {
|
|
230
229
|
console.log(`No query could be found for the given id. Query id: ${queryId}`);
|
|
@@ -490,6 +489,7 @@ var SIOPv2RPApiServer = class {
|
|
|
490
489
|
export {
|
|
491
490
|
SIOPv2RPApiServer,
|
|
492
491
|
authStatusUniversalOID4VPEndpoint,
|
|
492
|
+
buildQueryIdFilter,
|
|
493
493
|
createAuthRequestUniversalOID4VPEndpoint,
|
|
494
494
|
getAuthRequestSIOPv2Endpoint,
|
|
495
495
|
getDefinitionsEndpoint,
|
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/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,YAA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AAA,GAAQA,QAAQ,WAAW,EAAA,EAAIA,QAAQ,gBAAgB,EAAA;AAC9FL,gBAAQM,UAAU;UAAC;YAAEC,KAAK,GAAGL,IAAIM,QAAQ,MAAMN,IAAIO,IAAI,MAAA,CAAA,GAAUL,KAAAA;YAASM,aAAa;UAAc;;AAErGR,YAAIS,aAAaX;AACjBG,aAAAA;MACF,GACAS,UAAUC,WAAWb,SAASc,OAAAA,GAC9BF,UAAUG,MAAK,CAAA;IAEnB,CAAA,EACCC,MAAM,CAACC,QAAAA;AACN5C,cAAQC,IAAI,8CAA8C2C,GAAAA,2CAA8C;IAC1G,CAAA;AACF,UAAMH,UAAU,CAEhB;EACF;EACA,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"]}
|
|
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, PresentationSubmission } 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 { validate as isValidUUID } from 'uuid'\nimport { IRequiredContext } from './types'\nimport { DcqlQuery } from 'dcql'\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\nconst validatePresentationSubmission = (query: DcqlQuery, submission: PresentationSubmission): boolean => {\n return query.credentials.every(credential => credential.id in submission)\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: buildQueryIdFilter(queryId, tenantId, version),\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 const presentation = verifiedResponse?.oid4vpSubmission?.presentation\n if (presentation && validatePresentationSubmission(definitionItem.query, presentation)) {\n console.log('PRESENTATIONS:' + JSON.stringify(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, 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: buildQueryIdFilter(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\nexport function buildQueryIdFilter(queryId: string, tenantId?: string, version?: string) {\n const queryFilter = {\n queryId,\n ...(tenantId ? { tenantId } : {}),\n ...(version ? { version } : {}),\n }\n\n return [queryFilter, ...(isValidUUID(queryId) ? [{ id: queryId }] : [])] // Allow both PK (unique queryId + version combi) or just plain queryId which assumes the latest version\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 { buildQueryIdFilter } from './siop-api-functions'\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: buildQueryIdFilter(queryId),\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;AAEjC,SAASC,YAAYC,mBAAmB;AAIxC,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,OA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AiB;AACvBC,UAAM,KAAKvC,kBAAkB,EAC1BwC,KAAK,CAACC,QAAQA,IAAIC,KAAI,CAAA,EACtBF,KAAK,CAACG,YAAAA;AACL,YAAMC,UAAU,GAAG,KAAK7C,SAAS;AACjCiB,cAAQC,IAAI,iCAAiC2B,OAAAA,EAAS;AAEtD,WAAKhD,QAAQsC,IACX,aACA,CAACW,KAAcJ,KAAeK,SAAAA;AAC5B,cAAMC,QAAQ,GAAGH,QAAQI,QAAQ,MAAM,GAAA,CAAA,GAAQA,QAAQ,WAAW,EAAA,EAAIA,QAAQ,gBAAgB,EAAA;AAC9FL,gBAAQM,UAAU;UAAC;YAAEC,KAAK,GAAGL,IAAIM,QAAQ,MAAMN,IAAIO,IAAI,MAAA,CAAA,GAAUL,KAAAA;YAASM,aAAa;UAAc;;AAErGR,YAAIS,aAAaX;AACjBG,aAAAA;MACF,GACAS,UAAUC,WAAWb,SAASc,OAAAA,GAC9BF,UAAUG,MAAK,CAAA;IAEnB,CAAA,EACCC,MAAM,CAACC,QAAAA;AACN5C,cAAQC,IAAI,8CAA8C2C,GAAAA,2CAA8C;IAC1G,CAAA;AACF,UAAMH,UAAU,CAEhB;EACF;EACA,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","validate","isValidUUID","parseAuthorizationResponse","request","contentType","header","payload","body","JSON","parse","presentation_submission","console","log","vp_token","startsWith","endsWith","CredentialMapper","isJsonLdAsString","Error","validatePresentationSubmission","query","submission","credentials","every","credential","id","verifyAuthResponseSIOPv2Endpoint","router","context","opts","enabled","path","post","checkAuth","endpoint","response","correlationId","queryId","tenantId","version","params","sendErrorResponse","debug","stringify","definitionItems","agent","pdmGetDefinitions","filter","buildQueryIdFilter","length","statusCode","statusMessage","send","authorizationResponse","definitionItem","verifiedResponse","siopVerifyAuthResponse","dcqlQuery","presentation","oid4vpSubmission","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","queryFilter","isValidUUID","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","buildQueryIdFilter","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.254+c3fdd3d0",
|
|
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-feature.DIIPv4.
|
|
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.184",
|
|
27
|
+
"@sphereon/ssi-express-support": "0.34.1-fix.254+c3fdd3d0",
|
|
28
|
+
"@sphereon/ssi-sdk.core": "0.34.1-fix.254+c3fdd3d0",
|
|
29
|
+
"@sphereon/ssi-sdk.credential-validation": "0.34.1-fix.254+c3fdd3d0",
|
|
30
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.34.1-fix.254+c3fdd3d0",
|
|
31
|
+
"@sphereon/ssi-sdk.pd-manager": "0.34.1-fix.254+c3fdd3d0",
|
|
32
|
+
"@sphereon/ssi-sdk.presentation-exchange": "0.34.1-fix.254+c3fdd3d0",
|
|
33
|
+
"@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-fix.254+c3fdd3d0",
|
|
34
|
+
"@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth": "0.34.1-fix.254+c3fdd3d0",
|
|
35
|
+
"@sphereon/ssi-types": "0.34.1-fix.254+c3fdd3d0",
|
|
36
36
|
"@veramo/core": "4.2.0",
|
|
37
37
|
"@veramo/credential-w3c": "4.2.0",
|
|
38
38
|
"awesome-qr": "^2.1.5-rc.0",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"cookie-parser": "^1.4.6",
|
|
41
41
|
"cors": "^2.8.5",
|
|
42
42
|
"cross-fetch": "^4.1.0",
|
|
43
|
+
"dcql": "1.0.1",
|
|
43
44
|
"dotenv-flow": "^3.3.0",
|
|
44
45
|
"express": "^4.19.2",
|
|
45
46
|
"short-uuid": "^4.2.2",
|
|
@@ -49,16 +50,17 @@
|
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@decentralized-identity/ion-sdk": "^0.6.0",
|
|
52
|
-
"@sphereon/did-auth-siop-adapter": "0.19.1-feature.DIIPv4.
|
|
53
|
+
"@sphereon/did-auth-siop-adapter": "0.19.1-feature.DIIPv4.184",
|
|
53
54
|
"@sphereon/did-uni-client": "^0.6.3",
|
|
54
55
|
"@sphereon/pex": "5.0.0-unstable.28",
|
|
55
56
|
"@sphereon/pex-models": "^2.3.2",
|
|
56
|
-
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.34.1-fix.
|
|
57
|
-
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.34.1-fix.
|
|
58
|
-
"@sphereon/ssi-sdk-ext.jwt-service": "0.34.1-fix.
|
|
59
|
-
"@sphereon/ssi-sdk.credential-vcdm": "0.34.1-fix.
|
|
60
|
-
"@sphereon/ssi-sdk.credential-vcdm-jsonld-provider": "0.34.1-fix.
|
|
61
|
-
"@sphereon/ssi-sdk.data-store": "0.34.1-fix.
|
|
57
|
+
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.34.1-fix.254+c3fdd3d0",
|
|
58
|
+
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.34.1-fix.254+c3fdd3d0",
|
|
59
|
+
"@sphereon/ssi-sdk-ext.jwt-service": "0.34.1-fix.254+c3fdd3d0",
|
|
60
|
+
"@sphereon/ssi-sdk.credential-vcdm": "0.34.1-fix.254+c3fdd3d0",
|
|
61
|
+
"@sphereon/ssi-sdk.credential-vcdm-jsonld-provider": "0.34.1-fix.254+c3fdd3d0",
|
|
62
|
+
"@sphereon/ssi-sdk.data-store": "0.34.1-fix.254+c3fdd3d0",
|
|
63
|
+
"@sphereon/ssi-sdk.data-store-types": "0.34.1-fix.254+c3fdd3d0",
|
|
62
64
|
"@types/body-parser": "^1.19.5",
|
|
63
65
|
"@types/cookie-parser": "^1.4.7",
|
|
64
66
|
"@types/cors": "^2.8.17",
|
|
@@ -117,5 +119,5 @@
|
|
|
117
119
|
"OpenID Connect",
|
|
118
120
|
"Authenticator"
|
|
119
121
|
],
|
|
120
|
-
"gitHead": "
|
|
122
|
+
"gitHead": "c3fdd3d0d7e4124484f87a611792c9201a01256b"
|
|
121
123
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { AuthorizationResponsePayload } from '@sphereon/did-auth-siop'
|
|
1
|
+
import { AuthorizationResponsePayload, PresentationSubmission } from '@sphereon/did-auth-siop'
|
|
2
2
|
import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'
|
|
3
3
|
import { AuthorizationChallengeValidationResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
4
4
|
import { CredentialMapper } from '@sphereon/ssi-types'
|
|
5
5
|
import { Request, Response, Router } from 'express'
|
|
6
|
+
import { validate as isValidUUID } from 'uuid'
|
|
6
7
|
import { IRequiredContext } from './types'
|
|
8
|
+
import { DcqlQuery } from 'dcql'
|
|
7
9
|
|
|
8
10
|
const parseAuthorizationResponse = (request: Request): AuthorizationResponsePayload => {
|
|
9
11
|
const contentType = request.header('content-type')
|
|
@@ -41,6 +43,10 @@ const parseAuthorizationResponse = (request: Request): AuthorizationResponsePayl
|
|
|
41
43
|
)
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
const validatePresentationSubmission = (query: DcqlQuery, submission: PresentationSubmission): boolean => {
|
|
47
|
+
return query.credentials.every(credential => credential.id in submission)
|
|
48
|
+
}
|
|
49
|
+
|
|
44
50
|
export function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
45
51
|
if (opts?.enabled === false) {
|
|
46
52
|
console.log(`verifyAuthResponse SIOP endpoint is disabled`)
|
|
@@ -57,16 +63,7 @@ export function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequi
|
|
|
57
63
|
console.debug('Authorization Response (siop-sessions') // TODO use logger
|
|
58
64
|
console.debug(JSON.stringify(request.body, null, 2))
|
|
59
65
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
60
|
-
filter:
|
|
61
|
-
{
|
|
62
|
-
queryId,
|
|
63
|
-
...(tenantId && { tenantId }),
|
|
64
|
-
...(version && { version }),
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
id: queryId,
|
|
68
|
-
},
|
|
69
|
-
],
|
|
66
|
+
filter: buildQueryIdFilter(queryId, tenantId, version),
|
|
70
67
|
})
|
|
71
68
|
if (definitionItems.length === 0) {
|
|
72
69
|
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`)
|
|
@@ -85,10 +82,9 @@ export function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequi
|
|
|
85
82
|
dcqlQuery: definitionItem.query,
|
|
86
83
|
})
|
|
87
84
|
|
|
88
|
-
// FIXME SSISDK-55 add proper support for checking for DCQL presentations
|
|
89
85
|
const presentation = verifiedResponse?.oid4vpSubmission?.presentation
|
|
90
|
-
if (presentation &&
|
|
91
|
-
console.log('PRESENTATIONS:' + JSON.stringify(
|
|
86
|
+
if (presentation && validatePresentationSubmission(definitionItem.query, presentation)) {
|
|
87
|
+
console.log('PRESENTATIONS:' + JSON.stringify(presentation, null, 2))
|
|
92
88
|
response.statusCode = 200
|
|
93
89
|
|
|
94
90
|
const authorizationChallengeValidationResponse: AuthorizationChallengeValidationResponse = {
|
|
@@ -99,7 +95,7 @@ export function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequi
|
|
|
99
95
|
return response.send(JSON.stringify(authorizationChallengeValidationResponse))
|
|
100
96
|
}
|
|
101
97
|
|
|
102
|
-
const responseRedirectURI = await context.agent.siopGetRedirectURI({ correlationId,
|
|
98
|
+
const responseRedirectURI = await context.agent.siopGetRedirectURI({ correlationId, state: verifiedResponse.state })
|
|
103
99
|
if (responseRedirectURI) {
|
|
104
100
|
response.setHeader('Content-Type', 'application/json')
|
|
105
101
|
return response.send(JSON.stringify({ redirect_uri: responseRedirectURI }))
|
|
@@ -143,7 +139,7 @@ export function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredC
|
|
|
143
139
|
return sendErrorResponse(response, 404, `No authorization request could be found`)
|
|
144
140
|
}
|
|
145
141
|
|
|
146
|
-
const definitionItems = await context.agent.pdmGetDefinitions({ filter:
|
|
142
|
+
const definitionItems = await context.agent.pdmGetDefinitions({ filter: buildQueryIdFilter(queryId) })
|
|
147
143
|
if (definitionItems.length === 0) {
|
|
148
144
|
console.log(`Could not get dcql query with id ${queryId} from agent. Will return 404`)
|
|
149
145
|
response.statusCode = 404
|
|
@@ -176,3 +172,13 @@ export function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredC
|
|
|
176
172
|
}
|
|
177
173
|
})
|
|
178
174
|
}
|
|
175
|
+
|
|
176
|
+
export function buildQueryIdFilter(queryId: string, tenantId?: string, version?: string) {
|
|
177
|
+
const queryFilter = {
|
|
178
|
+
queryId,
|
|
179
|
+
...(tenantId ? { tenantId } : {}),
|
|
180
|
+
...(version ? { version } : {}),
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return [queryFilter, ...(isValidUUID(queryId) ? [{ id: queryId }] : [])] // Allow both PK (unique queryId + version combi) or just plain queryId which assumes the latest version
|
|
184
|
+
}
|
|
@@ -10,6 +10,7 @@ import { uriWithBase } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
|
10
10
|
import { Request, Response, Router } from 'express'
|
|
11
11
|
import uuid from 'short-uuid'
|
|
12
12
|
import { validateData } from './middleware/validationMiddleware'
|
|
13
|
+
import { buildQueryIdFilter } from './siop-api-functions'
|
|
13
14
|
import {
|
|
14
15
|
AuthStatusResponse,
|
|
15
16
|
CreateAuthorizationRequestPayloadRequest,
|
|
@@ -40,10 +41,7 @@ export function createAuthRequestUniversalOID4VPEndpoint(router: Router, context
|
|
|
40
41
|
const queryId = authRequest.queryId
|
|
41
42
|
|
|
42
43
|
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
43
|
-
filter:
|
|
44
|
-
{ id: queryId }, // Allow both PK (unique queryId + version combi) or just plain queryId which assumes the latest version
|
|
45
|
-
{ queryId },
|
|
46
|
-
],
|
|
44
|
+
filter: buildQueryIdFilter(queryId),
|
|
47
45
|
})
|
|
48
46
|
if (definitionItems.length === 0) {
|
|
49
47
|
console.log(`No query could be found for the given id. Query id: ${queryId}`)
|
|
@@ -147,7 +145,7 @@ export function authStatusUniversalOID4VPEndpoint(router: Router, context: IRequ
|
|
|
147
145
|
if (requestState.status === AuthorizationRequestStateStatus.RETRIEVED) {
|
|
148
146
|
responseState = await context.agent.siopGetAuthResponseState({
|
|
149
147
|
correlationId,
|
|
150
|
-
errorOnNotFound: false
|
|
148
|
+
errorOnNotFound: false,
|
|
151
149
|
})
|
|
152
150
|
}
|
|
153
151
|
const overallState = responseState ?? requestState
|
|
@@ -158,7 +156,7 @@ export function authStatusUniversalOID4VPEndpoint(router: Router, context: IRequ
|
|
|
158
156
|
query_id: overallState.queryId,
|
|
159
157
|
last_updated: overallState.lastUpdated,
|
|
160
158
|
...('verifiedData' in overallState && { verified_data: overallState.verifiedData }),
|
|
161
|
-
...(overallState.error && { message: overallState.error.message })
|
|
159
|
+
...(overallState.error && { message: overallState.error.message }),
|
|
162
160
|
} satisfies AuthStatusResponse
|
|
163
161
|
console.debug(`Will send auth status: ${JSON.stringify(statusBody)}`)
|
|
164
162
|
|