在swashbuckle 2.2.0(带有swagger 2.0)中,在授权响应之后是一个不像1.1.0的弹出窗口(曾经是一个页面加载)
如果上下文用户身份验证未经过身份验证,则我们有类似隐藏/显示未授权api的内容/反之亦然。
Github Swashbuckle issue希望有人可能有解决方案或尝试过这个。
未发送身份验证上下文以重新加载启动IdocumentFilter的页面。
public class HideUnauthorizedOperations : IDocumentFilter
{
private IHttpContextAccessor _httpContext;
public HideUnauthorizedOperations(IHttpContextAccessor httpContext)
{
_httpContext = httpContext;
}
public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
{
var authenticated = _httpContext.HttpContext.User.Identity.IsAuthenticated;
//TODO context user is null, need to fix the authentication
//if (!authenticated)
//{
// foreach (var values in swaggerDoc.Paths.Values)
// {
// var nullifyThese = new List<Operation>();
// foreach (var operation in values.EnumerateOperations())
// {
// if (operation != null && operation.Security?.Count > 0)
// nullifyThese.Add(operation);
// }
// values.NullifyOperations(nullifyThese);
// }
//}
}
}