From 39c304ae239ee2e183256036d0fad9b2722bdde4 Mon Sep 17 00:00:00 2001 From: "Ruben D." Date: Thu, 4 Apr 2024 17:03:04 +0200 Subject: [PATCH] feat: added routes for contract and vc endpoints --- packages/uma/config/default.json | 6 ++- packages/uma/config/routes/contract.json | 23 +++++++++++ packages/uma/config/routes/vc.json | 23 +++++++++++ packages/uma/src/index.ts | 2 + packages/uma/src/routes/Contract.ts | 46 ++++++++++++++++++++++ packages/uma/src/routes/VC.ts | 49 ++++++++++++++++++++++++ 6 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 packages/uma/config/routes/contract.json create mode 100644 packages/uma/config/routes/vc.json create mode 100644 packages/uma/src/routes/Contract.ts create mode 100644 packages/uma/src/routes/VC.ts diff --git a/packages/uma/config/default.json b/packages/uma/config/default.json index f86f0ab..fce059b 100644 --- a/packages/uma/config/default.json +++ b/packages/uma/config/default.json @@ -14,6 +14,8 @@ "sai-uma:config/routes/tickets.json", "sai-uma:config/routes/tokens.json", "sai-uma:config/routes/log.json", + "sai-uma:config/routes/vc.json", + "sai-uma:config/routes/contract.json", "sai-uma:config/tickets/storage/default.json", "sai-uma:config/tickets/strategy/claim-elimination.json", "sai-uma:config/tokens/factory/default.json", @@ -52,7 +54,9 @@ { "@id": "urn:uma:default:ResourceRegistrationRoute" }, { "@id": "urn:uma:default:ResourceRegistrationOpsRoute" }, { "@id": "urn:uma:default:IntrospectionRoute" }, - { "@id": "urn:uma:default:LogRoute" } + { "@id": "urn:uma:default:LogRoute" }, + { "@id": "urn:uma:default:VCRoute" }, + { "@id": "urn:uma:default:ContractRoute" } ] } ], diff --git a/packages/uma/config/routes/contract.json b/packages/uma/config/routes/contract.json new file mode 100644 index 0000000..f019a94 --- /dev/null +++ b/packages/uma/config/routes/contract.json @@ -0,0 +1,23 @@ +{ + "@context": [ + "https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma/^0.0.0/components/context.jsonld" + ], + "@graph": [ + { + "@id": "urn:uma:default:ContractRoute", + "@type": "HttpHandlerRoute", + "operations": [ + { + "@type": "HttpHandlerOperation", + "method": "GET", + "publish": true + } + ], + "handler": { + "@type": "ContractRequestHandler", + "baseUrl": { "@id": "urn:uma:variables:baseUrl" } + }, + "path": "/uma/contract" + } + ] +} \ No newline at end of file diff --git a/packages/uma/config/routes/vc.json b/packages/uma/config/routes/vc.json new file mode 100644 index 0000000..c310186 --- /dev/null +++ b/packages/uma/config/routes/vc.json @@ -0,0 +1,23 @@ +{ + "@context": [ + "https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma/^0.0.0/components/context.jsonld" + ], + "@graph": [ + { + "@id": "urn:uma:default:VCRoute", + "@type": "HttpHandlerRoute", + "operations": [ + { + "@type": "HttpHandlerOperation", + "method": "GET", + "publish": true + } + ], + "handler": { + "@type": "VCRequestHandler", + "baseUrl": { "@id": "urn:uma:variables:baseUrl" } + }, + "path": "/uma/vc" + } + ] + } \ No newline at end of file diff --git a/packages/uma/src/index.ts b/packages/uma/src/index.ts index ced0243..e49c4ec 100644 --- a/packages/uma/src/index.ts +++ b/packages/uma/src/index.ts @@ -34,6 +34,8 @@ export * from './routes/ResourceRegistration'; export * from './routes/Token'; export * from './routes/Config'; export * from './routes/Log'; +export * from './routes/VC'; +export * from './routes/Contract'; // Tickets export * from './ticketing/Ticket'; diff --git a/packages/uma/src/routes/Contract.ts b/packages/uma/src/routes/Contract.ts new file mode 100644 index 0000000..0d79f38 --- /dev/null +++ b/packages/uma/src/routes/Contract.ts @@ -0,0 +1,46 @@ +import { ASYMMETRIC_CRYPTOGRAPHIC_ALGORITHM } + from '@solid/access-token-verifier/dist/constant/ASYMMETRIC_CRYPTOGRAPHIC_ALGORITHM'; +import { HttpHandler } from '../util/http/models/HttpHandler'; +import { HttpHandlerContext } from '../util/http/models/HttpHandlerContext'; +import { HttpHandlerResponse } from '../util/http/models/HttpHandlerResponse'; +import { Logger } from '../util/logging/Logger'; +import { getLoggerFor } from '../util/logging/LoggerUtils'; +import { getOperationLogger } from '../logging/OperationLogger'; + +/** + * An HttpHandler used for returning the logs + * stored in the UMA Authorization Service. + */ +export class ContractRequestHandler extends HttpHandler { + protected readonly logger: Logger = getLoggerFor(this); + + operationLogger = getOperationLogger() + + /** + * An HttpHandler used for returning the configuration + * of the UMA Authorization Service. + * @param {string} baseUrl - Base URL of the AS + */ + constructor(protected readonly baseUrl: string) { + super(); + } + + /** + * Returns the endpoint's UMA configuration + * + * @param {HttpHandlerContext} context - an irrelevant incoming context + * @return {Observable} - the mock response + */ + async handle(context: HttpHandlerContext): Promise { + this.logger.info(`Received contract retrieval request at '${context.request.url}'`); + + return { + body: ' "the contract endpoint".', + headers: {'content-type': 'application/trig'}, + status: 200, + }; + } + +} + + diff --git a/packages/uma/src/routes/VC.ts b/packages/uma/src/routes/VC.ts new file mode 100644 index 0000000..d6357ed --- /dev/null +++ b/packages/uma/src/routes/VC.ts @@ -0,0 +1,49 @@ +import { ASYMMETRIC_CRYPTOGRAPHIC_ALGORITHM } + from '@solid/access-token-verifier/dist/constant/ASYMMETRIC_CRYPTOGRAPHIC_ALGORITHM'; +import { HttpHandler } from '../util/http/models/HttpHandler'; +import { HttpHandlerContext } from '../util/http/models/HttpHandlerContext'; +import { HttpHandlerResponse } from '../util/http/models/HttpHandlerResponse'; +import { Logger } from '../util/logging/Logger'; +import { getLoggerFor } from '../util/logging/LoggerUtils'; +import { getOperationLogger } from '../logging/OperationLogger'; +import { Quad } from 'n3'; +import { serializeQuads } from '@solid/community-server'; + + +/** + * An HttpHandler used for returning the logs + * stored in the UMA Authorization Service. + */ +export class VCRequestHandler extends HttpHandler { + protected readonly logger: Logger = getLoggerFor(this); + + operationLogger = getOperationLogger() + + /** + * An HttpHandler used for returning the configuration + * of the UMA Authorization Service. + * @param {string} baseUrl - Base URL of the AS + */ + constructor(protected readonly baseUrl: string) { + super(); + } + + /** + * Returns the endpoint's UMA configuration + * + * @param {HttpHandlerContext} context - an irrelevant incoming context + * @return {Observable} - the mock response + */ + async handle(context: HttpHandlerContext): Promise { + this.logger.info(`Received VC endpoint request at '${context.request.url}'`); + + return { + body: ' "the vc endpoint".', + headers: {'content-type': 'application/trig'}, + status: 200, + }; + } + +} + +