Swashbuckle需要多个标头用于OpenAPI身份验证

时间:2020-05-07 09:55:17

标签: swashbuckle

我有一个API,它需要两个标头,一个“用户ID”和一个“秘密”。我无法找到一种方法使它们同时在OpenAPI输出中列出,它们被显示为单独的授权选项。 OpenAPI表示可以为Multiple API Keys(省略破折号)执行此操作,但是我找不到找到指定两者在代码中相关的方法。在Swashbuckle中这可能吗? (上午使用.Net Core 3.1)

          options.AddSecurityDefinition("appkey", new OpenApiSecurityScheme
            {
                Description = "Unique application key (user ID)",
                In = ParameterLocation.Header,
                Name = CustomAuthenticationOptions.ApplicationKeyHeaderName,
                Type = SecuritySchemeType.ApiKey
            });
            options.AddSecurityDefinition("secret", new OpenApiSecurityScheme
            {
                Description = "Secret key (password)",
                In = ParameterLocation.Header,
                Name = CustomAuthenticationOptions.SecretKeyHeaderName,
                Type = SecuritySchemeType.ApiKey,
            });

0 个答案:

没有答案