1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-04 01:18:20 +02:00

chore: expose custom-handler-auth type (#5287)

This will help us get type checking on the auth handler function
This commit is contained in:
Gastón Fournier 2023-11-07 10:37:09 +01:00 committed by GitHub
parent addda5b022
commit 1dc7dd646d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 8 deletions

View File

@ -118,12 +118,16 @@ export default async function getApp(
}
case IAuthType.ENTERPRISE: {
app.use(baseUriPath, apiTokenMiddleware(config, services));
config.authentication.customAuthHandler(app, config, services);
if (config.authentication.customAuthHandler) {
config.authentication.customAuthHandler(app, config, services);
}
break;
}
case IAuthType.HOSTED: {
app.use(baseUriPath, apiTokenMiddleware(config, services));
config.authentication.customAuthHandler(app, config, services);
if (config.authentication.customAuthHandler) {
config.authentication.customAuthHandler(app, config, services);
}
break;
}
case IAuthType.DEMO: {
@ -138,7 +142,9 @@ export default async function getApp(
}
case IAuthType.CUSTOM: {
app.use(baseUriPath, apiTokenMiddleware(config, services));
config.authentication.customAuthHandler(app, config, services);
if (config.authentication.customAuthHandler) {
config.authentication.customAuthHandler(app, config, services);
}
break;
}
case IAuthType.NONE: {

View File

@ -1,11 +1,11 @@
import { Express } from 'express';
import { IUnleashConfig } from './types/option';
const customAuthWarning =
'You have to configure a custom authentication middleware. Read https://docs.getunleash.io/docs/reference/deploy/configuring-unleash for more details';
export function defaultCustomAuthDenyAll(
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
app: any,
app: Express,
config: IUnleashConfig,
): void {
const logger = config.getLogger('src/lib/app/customAuthHandler');

View File

@ -18,6 +18,7 @@ import {
IUnleashOptions,
IUnleashServices,
RoleName,
CustomAuthHandler,
} from './types';
import User, { IUser } from './types/user';
@ -212,4 +213,5 @@ export type {
IAuthRequest,
IApiRequest,
SimpleAuthSettings,
CustomAuthHandler,
};

View File

@ -1,8 +1,10 @@
import { Express } from 'express';
import EventEmitter from 'events';
import { LogLevel, LogProvider } from '../logger';
import { ILegacyApiTokenCreate } from './models/api-token';
import { IFlagResolver, IExperimentalOptions, IFlags } from './experimental';
import SMTPTransport from 'nodemailer/lib/smtp-transport';
import { IUnleashServices } from './services';
export interface ISSLOption {
rejectUnauthorized: boolean;
@ -53,10 +55,16 @@ export enum IAuthType {
NONE = 'none',
}
export type CustomAuthHandler = (
app: Express,
config: Partial<IUnleashConfig>,
services?: IUnleashServices,
) => void;
export interface IAuthOption {
enableApiToken: boolean;
type: IAuthType;
customAuthHandler?: Function;
customAuthHandler?: CustomAuthHandler;
createAdminUser?: boolean;
initialAdminUser?: {
username: string;

View File

@ -47,7 +47,6 @@ class UserStoreMock implements IUserStore {
}
async insert(user: User): Promise<User> {
// eslint-disable-next-line no-param-reassign
user.id = this.idSeq;
this.idSeq += 1;
this.data.push(user);
@ -55,7 +54,6 @@ class UserStoreMock implements IUserStore {
}
async update(id: number, user: User): Promise<User> {
// eslint-disable-next-line no-param-reassign
this.data = this.data.map((o) => {
if (o.id === id) return { ...o, name: user.name };
return o;