mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: add additional supported interfaces
This includes the relevant auth headers and a simplification of several others.
This commit is contained in:
parent
f8e136cadb
commit
a4f2b3995c
6
src/authentication/Credentials.ts
Normal file
6
src/authentication/Credentials.ts
Normal file
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Credentials identifying an entity accessing or owning data.
|
||||
*/
|
||||
export interface Credentials {
|
||||
webID: string;
|
||||
}
|
15
src/authentication/CredentialsExtractor.ts
Normal file
15
src/authentication/CredentialsExtractor.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { Credentials } from './Credentials';
|
||||
import { HttpRequest } from '../server/HttpRequest';
|
||||
|
||||
/**
|
||||
* Responsible for extracting credentials.
|
||||
*/
|
||||
export interface CredentialsExtractor {
|
||||
/**
|
||||
* Extracts the credentials found in an HttpRequest.
|
||||
*
|
||||
* @param request - The incoming request.
|
||||
* @returns A promise resolving to the credentials.
|
||||
*/
|
||||
extractCredentials: (request: HttpRequest) => Promise<Credentials>;
|
||||
}
|
23
src/authorization/Authorizer.ts
Normal file
23
src/authorization/Authorizer.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { Credentials } from '../authentication/Credentials';
|
||||
import { PermissionSet } from '../ldp/permissions/PermissionSet';
|
||||
import { ResourceIdentifier } from '../ldp/http/ResourceIdentifier';
|
||||
|
||||
/**
|
||||
* Responsible for the permission verification.
|
||||
*/
|
||||
export interface Authorizer {
|
||||
/**
|
||||
* Verifies if the given credentials have access to the given permissions on the given resource.
|
||||
* @param credentials - Credentials of the entity that wants to use the resource.
|
||||
* @param identifier - Identifier of the resource that will be read/modified.
|
||||
* @param permissions - Permissions that are requested on the resource.
|
||||
*
|
||||
* @returns A promise resolving when the Authorizer is finished.
|
||||
* An {@link Error} with the necessary explanation will be thrown when permissions are not granted.
|
||||
*/
|
||||
ensurePermissions: (
|
||||
credentials: Credentials,
|
||||
identifier: ResourceIdentifier,
|
||||
permissions: PermissionSet,
|
||||
) => Promise<void>;
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
import { Representation } from './Representation';
|
||||
|
||||
/**
|
||||
* Represents the changes needed for a PATCH request.
|
||||
*/
|
||||
export interface Patch {}
|
||||
export interface Patch extends Representation {}
|
||||
|
8
src/ldp/http/RequestParser.ts
Normal file
8
src/ldp/http/RequestParser.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { AsyncHandler } from '../../util/AsyncHandler';
|
||||
import { HttpRequest } from '../../server/HttpRequest';
|
||||
import { Operation } from '../operations/Operation';
|
||||
|
||||
/**
|
||||
* Converts an incoming HttpRequest to an Operation.
|
||||
*/
|
||||
export type RequestParser = AsyncHandler<HttpRequest, Operation>;
|
@ -1,21 +1,7 @@
|
||||
import { AsyncHandler } from '../../util/AsyncHandler';
|
||||
import { Operation } from './Operation';
|
||||
|
||||
/**
|
||||
* Handler for a specific operation type.
|
||||
*/
|
||||
export interface OperationHandler {
|
||||
/**
|
||||
* Checks if the handler supports the given operation.
|
||||
* @param operation - The input operation.
|
||||
*
|
||||
* @returns A promise resolving to a boolean indicating if this handler supports the operation.
|
||||
*/
|
||||
canHandle: (operation: Operation) => Promise<boolean>;
|
||||
/**
|
||||
* Handles the given operation.
|
||||
* @param operation - The input operation.
|
||||
*
|
||||
* @returns A promise resolving when the operation is handled.
|
||||
*/
|
||||
handle: (operation: Operation) => Promise<void>;
|
||||
}
|
||||
export type OperationHandler = AsyncHandler<Operation>;
|
||||
|
9
src/ldp/permissions/PermissionSet.ts
Normal file
9
src/ldp/permissions/PermissionSet.ts
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* A data interface indicating which permissions are allowed (based on the context).
|
||||
*/
|
||||
export interface PermissionSet {
|
||||
read: boolean;
|
||||
append: boolean;
|
||||
write: boolean;
|
||||
delete: boolean;
|
||||
}
|
8
src/ldp/permissions/PermissionsExtractor.ts
Normal file
8
src/ldp/permissions/PermissionsExtractor.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { AsyncHandler } from '../../util/AsyncHandler';
|
||||
import { Operation } from '../operations/Operation';
|
||||
import { PermissionSet } from './PermissionSet';
|
||||
|
||||
/**
|
||||
* Verifies which permissions are requested on a given {@link Operation}.
|
||||
*/
|
||||
export type PermissionsExtractor = AsyncHandler<Operation, PermissionSet>;
|
@ -1,22 +1,8 @@
|
||||
import { IncomingMessage, ServerResponse } from 'http';
|
||||
import { AsyncHandler } from '../util/AsyncHandler';
|
||||
import { HttpRequest } from './HttpRequest';
|
||||
import { HttpResponse } from './HttpResponse';
|
||||
|
||||
/**
|
||||
* An HTTP request handler.
|
||||
*/
|
||||
export interface HttpHandler {
|
||||
/**
|
||||
* Checks whether this handler supports the given request.
|
||||
* @param req - The input request.
|
||||
*
|
||||
* @returns A promise that indicates if this request is supported after resolving.
|
||||
*/
|
||||
canHandle: (req: Request) => Promise<boolean>;
|
||||
/**
|
||||
* Handles the given request.
|
||||
* @param req - The input request.
|
||||
* @param res - The response needed for responding to the request.
|
||||
*
|
||||
* @returns A promise resolving when the handling is finished.
|
||||
*/
|
||||
handle: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
||||
}
|
||||
export type HttpHandler = AsyncHandler<{ request: HttpRequest; response: HttpResponse }>;
|
||||
|
6
src/server/HttpRequest.ts
Normal file
6
src/server/HttpRequest.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { IncomingMessage } from 'http';
|
||||
|
||||
/**
|
||||
* An incoming HTTP request;
|
||||
*/
|
||||
export type HttpRequest = IncomingMessage;
|
6
src/server/HttpResponse.ts
Normal file
6
src/server/HttpResponse.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { OutgoingMessage } from 'http';
|
||||
|
||||
/**
|
||||
* An outgoing HTTP response;
|
||||
*/
|
||||
export type HttpResponse = OutgoingMessage;
|
17
src/util/AsyncHandler.ts
Normal file
17
src/util/AsyncHandler.ts
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Simple interface for classes that can potentially handle a specific kind of data asynchronously.
|
||||
*/
|
||||
export interface AsyncHandler<TInput, TOutput = void> {
|
||||
/**
|
||||
* Checks if the input data can be handled by this class.
|
||||
* @param input - Input data that would be handled potentially.
|
||||
* @returns A promise resolving to if this input can be handled.
|
||||
*/
|
||||
canHandle: (input: TInput) => Promise<boolean>;
|
||||
/**
|
||||
* Handles the given input. This should only be done if the {@link canHandle} function returned `true`.
|
||||
* @param input - Input data that needs to be handled.
|
||||
* @returns A promise resolving when the handling is finished. Return value depends on the given type.
|
||||
*/
|
||||
handle: (input: TInput) => Promise<TOutput>;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user