Swashbuckle将Auth Bearer令牌传递给API

时间:2018-09-12 15:29:39

标签: swagger swashbuckle

Swashbuckle是否有任何有关如何将不记名令牌传递给API的文档,升级到最新的swashbuckle 2.1版后,我无法传递不记名令牌

1 个答案:

答案 0 :(得分:2)

我有blogged about this before

services.AddSwaggerGen(options =>
{
    options.AddSecurityDefinition("oauth2", new ApiKeyScheme
    {
        Description = "Standard Authorization header using the Bearer scheme. Example: \"bearer {token}\"",
        In = "header",
        Name = "Authorization",
        Type = "apiKey"
    });

    options.OperationFilter<SecurityRequirementsOperationFilter>();

您将需要一个SecurityRequirementsOperationFilter的副本,可以通过谷歌搜索找到它,或者从我的Swashbuckle.AspNetCore.Filters软件包中安装它。