mirror of
https://github.com/Unleash/unleash.git
synced 2025-03-04 00:18:40 +01:00
18 lines
597 B
TypeScript
18 lines
597 B
TypeScript
import type { Request, Response, NextFunction } from 'express';
|
|
import type { IUnleashConfig } from '../types';
|
|
|
|
export const bearerTokenMiddleware = ({
|
|
getLogger,
|
|
}: Pick<IUnleashConfig, 'getLogger'>) => {
|
|
const logger = getLogger('/middleware/bearer-token-middleware.ts');
|
|
logger.debug('Enabling bearer token middleware');
|
|
return (req: Request, _: Response, next: NextFunction) => {
|
|
const authHeader = req.headers.authorization;
|
|
|
|
if (authHeader) {
|
|
req.headers.authorization = authHeader.replace(/^Bearer\s+/i, '');
|
|
}
|
|
next();
|
|
};
|
|
};
|