如何使用 asp.net web api 在 url header of swagger ui 中传递访问令牌?
How to pass access token in url header of swagger ui using asp.net web api?
我在 asp.net 中有招摇 API。我在我的项目中使用基于令牌的身份验证。我通过 tokenendpointpath 中的 post 请求获得令牌作为响应
[/token]。现在我需要在每个请求 curl 授权时自动传递该令牌 header。我尝试了很多方法,但它不是 working.I 不希望用户每次在请求时输入该令牌。请帮我解决这个问题。
//请求token
//请求资源
//Swagger.config class
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.DocumentFilter<AuthTokenOperation>();
c.SingleApiVersion("v1", "API");
c.PrettyPrint();
})
.EnableSwaggerUi(c =>
{
c.DocumentTitle("MY API");
});
}
}
提前致谢
更新到网络 api .net 框架
.EnableSwagger(c =>
{
c.DocumentFilter<AuthTokenOperation>();
c.SingleApiVersion("v1", "API");
c.PrettyPrint();
c.ApiKey("apiKey")
.Description("API Key for accessing secure APIs")
.Name("Api-Key")
.In("header");
})
我在 asp.net 中有招摇 API。我在我的项目中使用基于令牌的身份验证。我通过 tokenendpointpath 中的 post 请求获得令牌作为响应 [/token]。现在我需要在每个请求 curl 授权时自动传递该令牌 header。我尝试了很多方法,但它不是 working.I 不希望用户每次在请求时输入该令牌。请帮我解决这个问题。
//请求token
//请求资源
//Swagger.config class
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.DocumentFilter<AuthTokenOperation>();
c.SingleApiVersion("v1", "API");
c.PrettyPrint();
})
.EnableSwaggerUi(c =>
{
c.DocumentTitle("MY API");
});
}
}
提前致谢
更新到网络 api .net 框架
.EnableSwagger(c =>
{
c.DocumentFilter<AuthTokenOperation>();
c.SingleApiVersion("v1", "API");
c.PrettyPrint();
c.ApiKey("apiKey")
.Description("API Key for accessing secure APIs")
.Name("Api-Key")
.In("header");
})