UNPKG

@nephele/authenticator-custom

Version:

Custom logic authenticator for the Nephele WebDAV server.

38 lines (37 loc) 1.35 kB
import type { Request } from 'express'; import type { Authenticator as AuthenticatorInterface, AuthResponse as NepheleAuthResponse } from 'nephele'; import User from './User.js'; export type AuthenticatorConfig = { realm?: string; unauthorizedAccess?: boolean; getUser: (username: string) => Promise<User | null>; key?: string; nonceTimeout?: number; } & ({ authBasic: (user: User, password: string) => Promise<boolean>; } | { authDigest: (user: User, realm: string, algorithm: 'sha256' | 'md5') => Promise<{ password: string; } | { hash: string; } | null>; }); export type AuthResponse = NepheleAuthResponse<any, { user: User; }>; export default class Authenticator implements AuthenticatorInterface { getUser: (username: string) => Promise<User | null>; authBasic?: (user: User, password: string) => Promise<boolean>; authDigest?: (user: User, realm: string, algorithm: 'sha256' | 'md5') => Promise<{ password: string; } | { hash: string; } | null>; realm: string; unauthorizedAccess: boolean; key: string; nonceTimeout: number; constructor(config: AuthenticatorConfig); authenticate(request: Request, response: AuthResponse): Promise<User>; cleanAuthentication(_request: Request, _response: AuthResponse): Promise<void>; }