diff --git a/packages/core/auth/src/auth-manager.ts b/packages/core/auth/src/auth-manager.ts index 59a394fc4..db02fac74 100644 --- a/packages/core/auth/src/auth-manager.ts +++ b/packages/core/auth/src/auth-manager.ts @@ -9,7 +9,7 @@ type Storer = { get: (name: string) => Promise; }; -type AuthManagerOptions = { +export type AuthManagerOptions = { authKey: string; default?: string; jwt?: JwtOptions; @@ -21,11 +21,11 @@ type AuthConfig = { }; export class AuthManager { + jwt: JwtService; protected options: AuthManagerOptions; protected authTypes: Registry = new Registry(); // authenticators collection manager. protected storer: Storer; - jwt: JwtService; constructor(options: AuthManagerOptions) { this.options = options; diff --git a/packages/core/server/src/application.ts b/packages/core/server/src/application.ts index 73fd06250..5318c09e8 100644 --- a/packages/core/server/src/application.ts +++ b/packages/core/server/src/application.ts @@ -1,11 +1,11 @@ import { ACL } from '@nocobase/acl'; import { registerActions } from '@nocobase/actions'; -import { actions as authActions, AuthManager } from '@nocobase/auth'; +import { actions as authActions, AuthManager, AuthManagerOptions } from '@nocobase/auth'; import { Cache, createCache, ICacheConfig } from '@nocobase/cache'; import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database'; import { AppLoggerOptions, createAppLogger, Logger } from '@nocobase/logger'; import { ResourceOptions, Resourcer } from '@nocobase/resourcer'; -import { applyMixins, AsyncEmitter, Toposort, ToposortOptions, measureExecutionTime } from '@nocobase/utils'; +import { applyMixins, AsyncEmitter, measureExecutionTime, Toposort, ToposortOptions } from '@nocobase/utils'; import chalk from 'chalk'; import { Command, CommandOptions, ParseOptions } from 'commander'; import { IncomingMessage, Server, ServerResponse } from 'http'; @@ -23,7 +23,6 @@ import { ApplicationVersion } from './helpers/application-version'; import { Locale } from './locale'; import { Plugin } from './plugin'; import { InstallOptions, PluginManager } from './plugin-manager'; -import { CronJob } from 'cron'; import { CronJobManager } from './cron/cron-job-manager'; const packageJson = require('../package.json'); @@ -49,6 +48,7 @@ export interface ApplicationOptions { logger?: AppLoggerOptions; pmSock?: string; name?: string; + authManager?: AuthManagerOptions; } export interface DefaultState extends KoaDefaultState { @@ -723,6 +723,7 @@ export class Application exten this._authManager = new AuthManager({ authKey: 'X-Authenticator', default: 'basic', + ...(this.options.authManager || {}), }); this.resource({