asp.net-web-api – 使用swashbuckle api文档的http basic auth
发布时间:2020-12-15 20:56:50 所属栏目:asp.Net 来源:网络整理
导读:谁能知道如何将基本的auth与swashbuckle api的文档集成? 我看到swaggerconfig文件中有一个basicAuth函数: c.BasicAuth("basic").Description("Basic HTTP Authentication"); 我做了什么: 取消注释前一行但没有改变! 有没有人知道我错过了什么? 谢谢!
谁能知道如何将基本的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. 参考文献: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 关于年龄验证的Cookie法
- asp.net-mvc – 我想调试(设置一个断点)System.Web.Mvc.Def
- asp.net – System.Web.HttpException:请求超时
- asp.net-mvc-3 – 如何在控制器方法的新选项卡中打开cshtml
- 基于asp.net下使用jquery实现ajax的解决方法
- JSON字符串反序列化成对象_部分属性值反序列化失败
- asp.net-core – .NET Core与ASP.NET Core
- Asp.net mvc – Html提交按钮未发送帖子?
- asp.net – 当通过文件上传控件上传文件时,在c#.net中重命名
- 使用Linq表达式在扩展方法中有趣(?)
推荐文章
站长推荐
- asp.net-mvc – 在ASP.NET MVC ContactsManager教
- 如何保护经典ASP ASPSESSIONID cookie?
- asp.net-mvc – 为什么HtmlHelpers需要这个HtmlH
- asp.net-mvc – 登录页面上的Asp.Net MVC捆绑
- asp.net – <#=#>是什么意思
- ASP.NET 判断微信浏览器
- asp.net – Googlebot导致.NET System.Web.HttpE
- asp.net-web-api2 – Swashbuckle 5和multipart
- ..net学习群
- .Net multipart / form-data form enctype和UTF-
热点阅读