- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我通过 Swashbuckle V4 使用 Swagger,并使用 API key 对端点进行身份验证。
使用 Swashbuckle V4 时,以下配置完美运行(请注意,仅显示 Swagger 代码):
public void ConfigureServices(IServiceCollection services) {
services.AddSwaggerGen(c => {
c.SwaggerDoc(
"v1",
new Info {
Title = "OAPI", Version = "v1"
});
c.AddSecurityDefinition("api_key", new ApiKeyScheme {
In = "query",
Description = "Please Enter Authentication Token",
Name = "key",
Type = "apiKey"
});
c.AddSecurityRequirement(new Dictionary < string, IEnumerable < string >> {
{
"api_key",
new [] {
"readAccess",
"writeAccess"
}
}
});
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
app.UseSwagger();
app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/api/swagger/v1/swagger.json", "API V1");
c.RoutePrefix = "api/swagger";
});
}
虚张声势GitHub page ,包含“过渡到 Swashbuckle 5.0”主题,但不涵盖 API key 的使用。
我无法找到有关如何过渡到 V5 的完整示例,因此我分析了方法签名以生成相同的配置。
以下代码假装复制上述 V4 配置:
public void ConfigureServices(IServiceCollection services) {
var securityScheme = new OpenApiSecurityScheme {
In = ParameterLocation.Query,
Description = "Please Enter Authentication Token",
Name = "key",
Type = SecuritySchemeType.ApiKey
};
services.AddSwaggerGen(c => {
c.SwaggerDoc("V1", new OpenApiInfo {
Version = "V1",
Title = "API",
Description = "API"
});
c.AddSecurityDefinition("api_key", securityScheme);
c.AddSecurityRequirement(new OpenApiSecurityRequirement {
{
securityScheme,
new [] {
"readAccess",
"writeAccess"
}
}
});
c.EnableAnnotations();
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
app.UseSwagger();
app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/api/swagger/v1/swagger.json", "API V1");
c.RoutePrefix = "api/swagger";
});
}
运行 API 时,会显示 Swagger 身份验证窗口,我可以使用 API key 进行身份验证。
不幸的是,当执行任何端点时,我收到以下错误:
System.InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found.
at Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync
at Microsoft.AspNetCore.Mvc.ChallengeResult.ExecuteResultAsync
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync]
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAlwaysRunResultFilters
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke
at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.InvokeCore
我认为我遗漏了一些东西,我尝试研究 Microsoft.OpenApi.Models 类,但到目前为止我还没有运气。这可能是一个小细节,但到目前为止还无法理解......
最佳答案
使用 AddSecurityRequirement
时,您需要引用该方案,因为您是在全局应用它。此外,当使用“oauth2”以外的任何其他类型时,范围数组必须为空。
下面的示例应该可以工作。
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Id = "api_key",
Type = ReferenceType.SecurityScheme
}
},
new List<string>() }
});
关于swagger - 过渡到 Swashbuckle 5.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56980550/
我需要错误修复方面的帮助。我使用 segue 在 ViewController 之间传输。 我有 UITabBarController 和一个 UIViewController。当我单击 vc 中的按
我可以使用下面的代码转换到 Fragment 类,但是如何使用相同的代码转换到 FragmentActivity。 FragmentActivity activity = new ABC(); //
似乎我们的大多数 SAP 程序员都在使用旧版本的 ABAP,这是面向对象之前的版本。我还注意到,OO 的语言更加简洁和现代(他们显然借此机会摆脱了已弃用的东西)。 由于该系统尚未推出,因此进行任何重新
我正在尝试将现有的非 ARC 项目移动到 ARC。我已将build设置中的 Objective-C 自动引用计数标志设置为是。 这当然造成了很多有关发送显式发布/自动发布消息的错误。对于代码中的错误,
我有一条由贝塞尔曲线绘制的简单直线。挑战是改变它过渡的位置,即如果曲线的高度增加或减少,它应该在过渡中发生,而不是突然发生。所以我的问题是提供 Canvas 鼠标悬停时的过渡?如何提供曲线过渡? ca
自从我拿起一本 PHP 书籍并开始使用 PHP 编码已经过去了大约 5 个月。起初,我在没有任何组织计划或 MVC 的情况下创建了我所有的网站。我很快发现那很痛苦..然后我开始在 stackoverf
我的应用程序使用 AWS 上的 ElastiCache 进行缓存。我们当前的设置使用基本的 Redis 集群,没有分片或故障转移。我们现在需要迁移到启用了分片、故障转移等的集群 Redis 弹性缓存。
我们正在加入现代世界并从 SVN 过渡到 Mercurial 以进行源代码控制。其中大部分非常简单——只需将当前主干导入 HG 并进行克隆。一个项目有点花哨,我没有看到正确的方法来做到这一点。 有问题
我已经使用 tensorflow 一段时间了,一切正常,直到我尝试切换到 gpu 版本。 卸载了以前的tensorflow, pip 安装 tensorflow-gpu (v2.0) 下载并安装vis
我通过 Swashbuckle V4 使用 Swagger,并使用 API key 对端点进行身份验证。 使用 Swashbuckle V4 时,以下配置完美运行(请注意,仅显示 Swagger 代码
我正在努力使我的 java 应用程序更符合标准,我面临的最大问题之一是将我们的 ORM 框架从 Castor JDO 转换为 JPA 实现(考虑 Hibernate 或 DataNucleus)。我们
我希望在每次点击链接或在 EmberJS 中调用 transitionTo 时触发回调。我想这样做的原因是隐藏在进行转换时可能打开的菜单/下拉菜单。我不知道从哪里开始。我的 Google-fu 可能很
我当时使用的是 Xcode 4.6.1,并且已经创建了一个由 apple 批准并在 App Store 上的 iphone/ipad 应用程序。它是为 5.1 的最低部署目标而构建的 现在是时候让它与
我已经寻找解决方案 6 个小时了,但没有找到适合我情况的解决方案。我的 Storyboard遵循以下流程: TabBarViewController -> NavigationController -
例如,如果我有: class SpriteKitScene: SKScene { ... } 在那里我想要一个图像,当点击(按下,点击,触摸任何东西)时载入另一个文件: class UiViewcon
所以我找到了一个如何从XIB过渡到storyboard的例子 NSString * storyboardName = @"CheckoutStoryboard"; UIStoryboard *stor
如何通过点击表格 View 单元格来转换到 View Controller ?我目前的结构是: 我使用 navigation controller 作为我在我的应用程序 atm 中导航的唯一方式。 我
我正在尝试通过 segue 转换(模态)到 UINavigationController来自UIViewController .我的UIViewController和 UINavigationCont
我有一个自定义 View : class MediaPlayerView: UIView { var mediaURL: URL? { didSet {
根据语言的发明时间和语言的结构,这种转变可能意味着要走另一条路,但我对我的 Java 能力相当有信心,或者至少我在这方面足够好。但我现在正在尝试使用 C++,但我遇到了困难。 在 java 中,读取一
我是一名优秀的程序员,十分优秀!