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>;
};
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<AuthConfig> = new Registry();
// authenticators collection manager.
protected storer: Storer;
jwt: JwtService;
constructor(options: AuthManagerOptions) {
this.options = options;

View File

@ -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<StateT = DefaultState, ContextT = DefaultContext> exten
this._authManager = new AuthManager({
authKey: 'X-Authenticator',
default: 'basic',
...(this.options.authManager || {}),
});
this.resource({