我有一个使用Duende IdentityServer 6的ASPNET Core 6服务,它包括几个端点,如/connect/token和/connect/authorize。我需要这些端点显示在我的Swagger UI页面中,但我找不到让它们显示的方法。
这是我的AddSwaggerGen
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" });
c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
{
ClientCredentials = new OpenApiOAuthFlow
{
AuthorizationUrl =
new Uri($"{builder.Configuration.GetSection("BaseUri").Value}connect/authorize",
UriKind.RelativeOrAbsolute),
TokenUrl = new Uri($"{builder.Configuration.GetSection("BaseUri").Value}connect/token",
UriKind.RelativeOrAbsolute),
Scopes = new Dictionary<string, string>
{
{ Constants.Api.ScopeName, "Base level access to API" }
}
}
}
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oauth2" },
In = ParameterLocation.Cookie
},
new string[] { }
}
});
});
我只是使用基本的app.AddSwagger()
和app.AddSwaggerUI()
1条答案
按热度按时间jhdbpxl91#
据我的研究表明,CodingMytra是正确的。必须手动将IdentityServer端点添加到Swagger文档中。