我正在使用 @UseGuards 来验证标头中的两个 api 密钥。
@Injectable()
export class AuthGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
// check two api keys('some' and 'thing') in header at once
}
Run Code Online (Sandbox Code Playgroud)
另外,我在控制器中使用 @ApiHeader 来大肆展示。
@ApiOperation({ summary: 'blah blah' })
@ApiHeader({ name: 'some'}, {name: 'thing'})
@UseGuards(AuthGuard)
@Get('/hello')
async adminableCollections() {
// do something
}
Run Code Online (Sandbox Code Playgroud)
我想使用 @ApiSecurity 或其他东西代替 @ApiHeader 使用授权按钮(如图中)一次性授权,而不是为每个方法输入值。

我尝试使用文档生成器添加自定义安全性,但它似乎根本不起作用。
const swaggerConfig = new DocumentBuilder()
.setTitle('My API')
.setDescription('Document for my api.')
.setVersion('0.0.1')
.addApiKey('some', { type: 'apiKey', in: 'header', name: 'some' })
.addApikey('thing', { type: …Run Code Online (Sandbox Code Playgroud)