我使用NSwag在我的ASP.NET项目中设置了Swagger,但是我正在尝试添加对身份验证的支持。
我的身份验证模型是使用OAuth
ApplicationOAuthProvider
的简单用户名/密码
我用来登录的网址如下
/令牌
使用POST参数:
grant_type =密码&安培;用户名= $ {用户名}&安培;密码= $ {密码}
现在,我在[Global.asax]中的招摇设置是
app.UseSwaggerUi(typeof(Global).Assembly, new SwaggerUiSettings
{
MiddlewareBasePath = "/swagger",
OAuth2Client = new OAuth2ClientSettings
{
ClientId = "my_auth_id",
//ClientSecret = "bar",
AppName = "my",
//Realm = "my_realm",
//AdditionalQueryStringParameters = { { "foo", "bar" } }
},
DocumentProcessors = {
new SecurityDefinitionAppender("oauth2", new SwaggerSecurityScheme
{
Type = SwaggerSecuritySchemeType.Basic,
Description = "Description is set htere",
Flow = SwaggerOAuth2Flow.Password,
AuthorizationUrl = "https://localhost:28866/token?",
TokenUrl = "https://localhost:28866/token",
In = SwaggerSecurityApiKeyLocation.Query
//Scopes = new Dictionary<string,string>
//{
// //{ "read", "Read access to protected resources" },
// { "write", "Write access to protected resources" }
//}
})
},
OperationProcessors =
{
new OperationSecurityScopeProcessor("oauth2")
}
});
我知道它有点凌乱,但我确实尝试了所有可行的选项。
所以这实际上给了我授权按钮和用户名和密码字段。但是当我点击登录时它会刷新swagger.json,但实际上并没有尝试登录任何地方?