gpt4 book ai didi

c# - NSwag 的 AspNetCoreOperationSecurityScopeProcessor 将所有端点标记为需要授权

转载 作者:行者123 更新时间:2023-12-04 03:58:48 27 4
gpt4 key购买 nike

我有这样设置的自定义授权方案:

services.AddAuthentication("ClientApp")
.AddScheme<ClientAppAuthenticationOptions, ClientAppAuthenticationHandler>("ClientApp", null);

然后我有以下 NSwag OpenAPI 文档配置:

services.AddOpenApiDocument((settings, provider) =>
{
settings.DocumentName = "openapi";
settings.AddSecurity("ClientApp", Enumerable.Empty<string>(), new OpenApiSecurityScheme
{
Type = OpenApiSecuritySchemeType.ApiKey,
Description = "Authentications used for client apps, such as Mmcc.Stats.TpsMonitor",
Name = "X-Auth-Token",
In = OpenApiSecurityApiKeyLocation.Header
});

settings.OperationProcessors.Add(
new AspNetCoreOperationSecurityScopeProcessor("ClientApp")
);
// ...
}

我在 Controller 中使用 [AllowAnonymous][Authorize(AuthenticationSchemes = "ClientApp")] 装饰了 Action ,但是 NSwag 将我的所有端点标记为 requring ReDoc UI 中的 ClientApp 授权,不考虑装饰器。为什么?

最佳答案

我已经通过将我的代码更改为以下内容来修复它:

settings.DocumentProcessors.Add(
new SecurityDefinitionAppender("ClientApp",
new OpenApiSecurityScheme
{
Type = OpenApiSecuritySchemeType.ApiKey,
Description = "Authentications used for client apps, such as Mmcc.Stats.TpsMonitor",
Name = "X-Auth-Token",
In = OpenApiSecurityApiKeyLocation.Header
}));
settings.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("ClientApp"));

关于c# - NSwag 的 AspNetCoreOperationSecurityScopeProcessor 将所有端点标记为需要授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63405895/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com