mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-04 13:48:56 +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:
parent
addda5b022
commit
1dc7dd646d
@ -118,12 +118,16 @@ export default async function getApp(
|
|||||||
}
|
}
|
||||||
case IAuthType.ENTERPRISE: {
|
case IAuthType.ENTERPRISE: {
|
||||||
app.use(baseUriPath, apiTokenMiddleware(config, services));
|
app.use(baseUriPath, apiTokenMiddleware(config, services));
|
||||||
config.authentication.customAuthHandler(app, config, services);
|
if (config.authentication.customAuthHandler) {
|
||||||
|
config.authentication.customAuthHandler(app, config, services);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IAuthType.HOSTED: {
|
case IAuthType.HOSTED: {
|
||||||
app.use(baseUriPath, apiTokenMiddleware(config, services));
|
app.use(baseUriPath, apiTokenMiddleware(config, services));
|
||||||
config.authentication.customAuthHandler(app, config, services);
|
if (config.authentication.customAuthHandler) {
|
||||||
|
config.authentication.customAuthHandler(app, config, services);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IAuthType.DEMO: {
|
case IAuthType.DEMO: {
|
||||||
@ -138,7 +142,9 @@ export default async function getApp(
|
|||||||
}
|
}
|
||||||
case IAuthType.CUSTOM: {
|
case IAuthType.CUSTOM: {
|
||||||
app.use(baseUriPath, apiTokenMiddleware(config, services));
|
app.use(baseUriPath, apiTokenMiddleware(config, services));
|
||||||
config.authentication.customAuthHandler(app, config, services);
|
if (config.authentication.customAuthHandler) {
|
||||||
|
config.authentication.customAuthHandler(app, config, services);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IAuthType.NONE: {
|
case IAuthType.NONE: {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
|
import { Express } from 'express';
|
||||||
import { IUnleashConfig } from './types/option';
|
import { IUnleashConfig } from './types/option';
|
||||||
|
|
||||||
const customAuthWarning =
|
const customAuthWarning =
|
||||||
'You have to configure a custom authentication middleware. Read https://docs.getunleash.io/docs/reference/deploy/configuring-unleash for more details';
|
'You have to configure a custom authentication middleware. Read https://docs.getunleash.io/docs/reference/deploy/configuring-unleash for more details';
|
||||||
|
|
||||||
export function defaultCustomAuthDenyAll(
|
export function defaultCustomAuthDenyAll(
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
app: Express,
|
||||||
app: any,
|
|
||||||
config: IUnleashConfig,
|
config: IUnleashConfig,
|
||||||
): void {
|
): void {
|
||||||
const logger = config.getLogger('src/lib/app/customAuthHandler');
|
const logger = config.getLogger('src/lib/app/customAuthHandler');
|
||||||
|
@ -18,6 +18,7 @@ import {
|
|||||||
IUnleashOptions,
|
IUnleashOptions,
|
||||||
IUnleashServices,
|
IUnleashServices,
|
||||||
RoleName,
|
RoleName,
|
||||||
|
CustomAuthHandler,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
import User, { IUser } from './types/user';
|
import User, { IUser } from './types/user';
|
||||||
@ -212,4 +213,5 @@ export type {
|
|||||||
IAuthRequest,
|
IAuthRequest,
|
||||||
IApiRequest,
|
IApiRequest,
|
||||||
SimpleAuthSettings,
|
SimpleAuthSettings,
|
||||||
|
CustomAuthHandler,
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
import { Express } from 'express';
|
||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
import { LogLevel, LogProvider } from '../logger';
|
import { LogLevel, LogProvider } from '../logger';
|
||||||
import { ILegacyApiTokenCreate } from './models/api-token';
|
import { ILegacyApiTokenCreate } from './models/api-token';
|
||||||
import { IFlagResolver, IExperimentalOptions, IFlags } from './experimental';
|
import { IFlagResolver, IExperimentalOptions, IFlags } from './experimental';
|
||||||
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
||||||
|
import { IUnleashServices } from './services';
|
||||||
|
|
||||||
export interface ISSLOption {
|
export interface ISSLOption {
|
||||||
rejectUnauthorized: boolean;
|
rejectUnauthorized: boolean;
|
||||||
@ -53,10 +55,16 @@ export enum IAuthType {
|
|||||||
NONE = 'none',
|
NONE = 'none',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type CustomAuthHandler = (
|
||||||
|
app: Express,
|
||||||
|
config: Partial<IUnleashConfig>,
|
||||||
|
services?: IUnleashServices,
|
||||||
|
) => void;
|
||||||
|
|
||||||
export interface IAuthOption {
|
export interface IAuthOption {
|
||||||
enableApiToken: boolean;
|
enableApiToken: boolean;
|
||||||
type: IAuthType;
|
type: IAuthType;
|
||||||
customAuthHandler?: Function;
|
customAuthHandler?: CustomAuthHandler;
|
||||||
createAdminUser?: boolean;
|
createAdminUser?: boolean;
|
||||||
initialAdminUser?: {
|
initialAdminUser?: {
|
||||||
username: string;
|
username: string;
|
||||||
|
2
src/test/fixtures/fake-user-store.ts
vendored
2
src/test/fixtures/fake-user-store.ts
vendored
@ -47,7 +47,6 @@ class UserStoreMock implements IUserStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async insert(user: User): Promise<User> {
|
async insert(user: User): Promise<User> {
|
||||||
// eslint-disable-next-line no-param-reassign
|
|
||||||
user.id = this.idSeq;
|
user.id = this.idSeq;
|
||||||
this.idSeq += 1;
|
this.idSeq += 1;
|
||||||
this.data.push(user);
|
this.data.push(user);
|
||||||
@ -55,7 +54,6 @@ class UserStoreMock implements IUserStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async update(id: number, user: User): Promise<User> {
|
async update(id: number, user: User): Promise<User> {
|
||||||
// eslint-disable-next-line no-param-reassign
|
|
||||||
this.data = this.data.map((o) => {
|
this.data = this.data.map((o) => {
|
||||||
if (o.id === id) return { ...o, name: user.name };
|
if (o.id === id) return { ...o, name: user.name };
|
||||||
return o;
|
return o;
|
||||||
|
Loading…
Reference in New Issue
Block a user