如何将自定义 header 或请求参数添加到 Swashbuckle.AspNetCore 中的授权请求

How to add custom header or request param to auth request in Swashbuckle.AspNetCore

我正在构建网站 api,顶部是 Swashbuckle.AspNetCore。我已经实现了授权并且它有效但是我需要添加自定义 header 或请求参数到授权请求。我看不出如何做到这一点。有没有?

当前代码是

 c.AddSecurityDefinition("oauth2", new OAuth2Scheme
                {
                    Type = "oauth2",
                    Flow = "password",
                    TokenUrl = $"{configuration.GetSection("Security").GetValue<string>("STSHost")}/connect/token"
                });

无法向身份验证请求添加自定义 headers,但您可以使用 OAuthAdditionalQueryStringParams 方法添加其他查询参数。

它采用字符串键和值的字典并映射到 additionalQueryStringParams OAuth2 configuration value