UNPKG

@webda/hawk

Version:

Implements Hawk on webda

108 lines (107 loc) 2.58 kB
import { CoreModelDefinition, CryptoService, RequestFilter, Service, ServiceParameters, WebContext } from "@webda/core"; import { ApiKey } from "./apikey.js"; /** * Hawk Credentials representation */ export interface HawkCredentials { id: string; key: string; algorithm: string; } /** * Contains the hawk context */ export interface HawkContext { artifacts: any; credentials: any; } /** * */ export declare class HawkServiceParameters extends ServiceParameters { /** * Key model */ keyModel?: string; /** * If specified will verify the signature match the key store in session */ dynamicSessionKey?: string; /** * redirect endpoint * @param params */ redirectUrl?: string; /** * Allowed redirection with CSRF */ redirectUris?: string[]; /** * @inheritdoc */ constructor(params: any); } /** * Verify signature and sign server * * Implementation of hawk protocol * https://github.com/mozilla/hawk#readme * * @WebdaModda Hawk */ export default class HawkService extends Service<HawkServiceParameters> implements RequestFilter { static RegistryEntry: string; /** * CryptoService */ protected cryptoService: CryptoService; /** * Model to use for apikey */ model: CoreModelDefinition<ApiKey>; /** * @inheritdoc */ loadParameters(params: any): HawkServiceParameters; /** * * @param id * @param _timestamp used to invalidate cache * @returns */ getApiKey(id: any, _timestamp?: any): Promise<HawkCredentials>; /** * Return information for hawk */ getHawkRequest(context: WebContext): Promise<{ method: import("@webda/core").HttpMethodType; url: string; host: string; port: number; authorization: string; payload: string | Buffer; contentType: string; }>; /** * Add the Request listeners */ init(): Promise<this>; /** * Redirect with a CSRF * @param context */ _redirect(context: WebContext): Promise<void>; /** * Redirect to a website with CSRF */ redirectWithCSRF(context: WebContext, url: string): Promise<void>; getOrigins(): Promise<any>; checkOPTIONS(origin: string): Promise<boolean>; /** * Stricly parse the request's attributes and then approve or reject * @param {Context} context * @returns {Promise<boolean>} */ checkRequest(context: WebContext): Promise<boolean>; } export { HawkService };