/** * This file is part of the NocoBase (R) project. * Copyright (c) 2020-2024 NocoBase Co., Ltd. * Authors: NocoBase Team. * * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. * For more information, please refer to: https://www.nocobase.com/agreement. */ import { Context, Next } from '@nocobase/actions'; import { Registry } from '@nocobase/utils'; import { Auth, AuthExtend } from './auth'; import { JwtOptions, JwtService } from './base/jwt-service'; import { ITokenBlacklistService } from './base/token-blacklist-service'; import { ITokenControlService } from './base/token-control-service'; export interface Authenticator { authType: string; options: Record; [key: string]: any; } export type BuiltInAuthenticator = Authenticator & { name: string; enabled?: boolean; }; export interface Storer { get: (name: string) => Promise; } export type AuthManagerOptions = { authKey: string; default?: string; jwt?: JwtOptions; }; type AuthConfig = { auth: AuthExtend; title?: string; hidden?: boolean; getPublicOptions?: (options: Record) => Record; }; export declare class AuthManager { /** * @internal */ jwt: JwtService; tokenController: ITokenControlService; protected options: AuthManagerOptions; protected authTypes: Registry; protected storer: Storer; protected builtInAuthenticators: Map; constructor(options: AuthManagerOptions); setStorer(storer: Storer): void; registerBuiltInAuthenticator(authenticator: BuiltInAuthenticator): void; unregisterBuiltInAuthenticator(name: string): void; getBuiltInAuthenticator(name: string): BuiltInAuthenticator; private createAuth; setTokenBlacklistService(service: ITokenBlacklistService): void; setTokenControlService(service: ITokenControlService): void; /** * registerTypes * @description Add a new authenticate type and the corresponding authenticator. * The types will show in the authenticators list of the admin panel. * * @param authType - The type of the authenticator. It is required to be unique. * @param authConfig - Configurations of the kind of authenticator. */ registerTypes(authType: string, authConfig: AuthConfig): void; listTypes(): { name: string; title: string; }[]; getAuthConfig(authType: string): AuthConfig; /** * get * @description Get authenticator instance by name. * @param name - The name of the authenticator. * @return authenticator instance. */ get(name: string, ctx: Context): Promise; /** * middleware * @description Auth middleware, used to check the user status. */ middleware(): (ctx: Context & { auth: Auth; }, next: Next) => Promise; private getDefaultJWTSecret; } export {};