Skip to content

Commit

Permalink
fix(core): Swagger stats authentication (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shashwat290199 authored May 12, 2021
1 parent 5567fe9 commit ed7d59f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ export class CoreComponent implements Component {
const swStatsMiddleware = swstats.getMiddleware({
uriPath: this.coreConfig?.obfPath ?? `/obf`,
swaggerSpec: this.coreConfig?.openapiSpec,
authentication: this.coreConfig.authentication
? this.coreConfig.authentication
: false,
onAuthenticate: this.coreConfig.swaggerAuthenticate
? this.coreConfig.swaggerAuthenticate
: (req, username, password) => {
return (
username === this.coreConfig.swaggerUsername &&
password === this.coreConfig.swaggerPassword
);
},
});
middlewares.push(swStatsMiddleware);
}
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {IncomingMessage} from 'http';

export interface IServiceConfig {
useCustomSequence: boolean;
}
Expand All @@ -7,4 +9,12 @@ export interface CoreConfig {
enableObf?: boolean;
obfPath?: string;
openapiSpec?: Record<string, unknown>;
authentication?: boolean;
swaggerUsername?: string;
swaggerPassword?: string;
swaggerAuthenticate?: (
req?: IncomingMessage,
username?: string,
password?: string,
) => boolean;
}

0 comments on commit ed7d59f

Please sign in to comment.