chore: expose auth manager option in application (#2894)

This commit is contained in:
ChengLei Shao 2023-10-23 15:41:35 +08:00 committed by GitHub
parent b18822aaa9
commit d751b30b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -9,7 +9,7 @@ type Storer = {
get: (name: string) => Promise<Model>; get: (name: string) => Promise<Model>;
}; };
type AuthManagerOptions = { export type AuthManagerOptions = {
authKey: string; authKey: string;
default?: string; default?: string;
jwt?: JwtOptions; jwt?: JwtOptions;
@ -21,11 +21,11 @@ type AuthConfig = {
}; };
export class AuthManager { export class AuthManager {
jwt: JwtService;
protected options: AuthManagerOptions; protected options: AuthManagerOptions;
protected authTypes: Registry<AuthConfig> = new Registry(); protected authTypes: Registry<AuthConfig> = new Registry();
// authenticators collection manager. // authenticators collection manager.
protected storer: Storer; protected storer: Storer;
jwt: JwtService;
constructor(options: AuthManagerOptions) { constructor(options: AuthManagerOptions) {
this.options = options; this.options = options;

View File

@ -1,11 +1,11 @@
import { ACL } from '@nocobase/acl'; import { ACL } from '@nocobase/acl';
import { registerActions } from '@nocobase/actions'; 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 { Cache, createCache, ICacheConfig } from '@nocobase/cache';
import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database'; import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';
import { AppLoggerOptions, createAppLogger, Logger } from '@nocobase/logger'; import { AppLoggerOptions, createAppLogger, Logger } from '@nocobase/logger';
import { ResourceOptions, Resourcer } from '@nocobase/resourcer'; 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 chalk from 'chalk';
import { Command, CommandOptions, ParseOptions } from 'commander'; import { Command, CommandOptions, ParseOptions } from 'commander';
import { IncomingMessage, Server, ServerResponse } from 'http'; import { IncomingMessage, Server, ServerResponse } from 'http';
@ -23,7 +23,6 @@ import { ApplicationVersion } from './helpers/application-version';
import { Locale } from './locale'; import { Locale } from './locale';
import { Plugin } from './plugin'; import { Plugin } from './plugin';
import { InstallOptions, PluginManager } from './plugin-manager'; import { InstallOptions, PluginManager } from './plugin-manager';
import { CronJob } from 'cron';
import { CronJobManager } from './cron/cron-job-manager'; import { CronJobManager } from './cron/cron-job-manager';
const packageJson = require('../package.json'); const packageJson = require('../package.json');
@ -49,6 +48,7 @@ export interface ApplicationOptions {
logger?: AppLoggerOptions; logger?: AppLoggerOptions;
pmSock?: string; pmSock?: string;
name?: string; name?: string;
authManager?: AuthManagerOptions;
} }
export interface DefaultState extends KoaDefaultState { export interface DefaultState extends KoaDefaultState {
@ -723,6 +723,7 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
this._authManager = new AuthManager({ this._authManager = new AuthManager({
authKey: 'X-Authenticator', authKey: 'X-Authenticator',
default: 'basic', default: 'basic',
...(this.options.authManager || {}),
}); });
this.resource({ this.resource({