谁能知道我如何将基本身份验证与 swashbuckle api 的文档集成?
could anyone know how could i integrate basic auth with swashbuckle api's documentation?
我看到swaggerconfig文件中有一个basicAuth函数:
I saw that there's a basicAuth function in the swaggerconfig file:
c.BasicAuth("basic").Description("Basic HTTP Authentication");
我做了什么:
取消了上一行的注释,但没有任何改变!有人知道我错过了什么吗?
does anyone have any idea what did i miss?
谢谢!
我是这样进行 httpbasic 身份验证的:
Here's how i did httpbasic authentication:
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.
The api's user shall write in the field value: basic [un:pw].tobase64.
参考资料:swashbuckle 的问题 326swashbuckle 问题 2
上一篇:如何在 swagger 规范中表示十进制浮点?浮点、表示、如何在、swagger
下一篇:java.lang.NoClassDefFoundError的:com.google.android.gms.gcm.GoogleCloudMessagingNoClassDefFoundError、