【发布时间】:2022-04-25 12:58:18
【问题描述】:
这里是 Swagger/OpenAPI 的定义:
services.AddOpenApiDocument(document =>
{
document.DocumentProcessors.Add(new SecurityDefinitionAppender("Bearer", Enumerable.Empty<string>(),
new OpenApiSecurityScheme
{
Type = OpenApiSecuritySchemeType.OAuth2,
Flow = OpenApiOAuth2Flow.AccessCode,
Scopes = new Dictionary<string, string> {{"myScope", "myScope"}},
AuthorizationUrl = "redacted",
TokenUrl = "redacted"
}));
});
和 Swagger-UI 配置选项:
app.UseSwaggerUi3(settings =>
{
settings.OAuth2Client = new OAuth2ClientSettings
{
ClientId = "MyClientID",
ClientSecret = string.Empty,
AppName = "My App",
UsePkceWithAuthorizationCodeGrant = true
};
});
我希望默认检查范围,这可能吗?
【问题讨论】:
-
你找到答案了吗?
-
不,先生。有一些建议可以围绕它写一些 JS
-
@claudekennilol,这是一种解决方法 - stackoverflow.com/a/60960871/968003。看起来很丑,但我还没有看到更好的选择