谁能知道如何将基本的auth与swashbuckle api的文档集成?
我看到swaggerconfig文件中有一个basicAuth函数:
c.BasicAuth("basic").Description("Basic HTTP Authentication");
我做了什么:
>取消注释前一行但没有改变!
有没有人知道我错过了什么?
谢谢!
解决方法
这是我做httpbasic身份验证的方式:
public class AddAuthorizationHeaderParameterOperationFilter: IOperationFilter { public void Apply(Operation operation,SchemaRegistry schemaRegistry,ApiDescription apiDescription) { var filterPipeline = apiDescription.ActionDescriptor.GetFilterPipeline(); var isAuthorized = filterPipeline .Select(filterInfo => filterInfo.Instance) .Any(filter => filter is IAuthorizationFilter); var allowAnonymous = apiDescription.ActionDescriptor.GetCustomAttributes<AllowAnonymousAttribute>().Any(); if (isAuthorized && !allowAnonymous) { operation.parameters.Add(new Parameter { name = "Authorization",@in = "header",description = "access token",required = true,type = "string" }); } } }
api的用户应写入字段值:basic [un:pw] .tobase64.