I have setup Swagger within my ASP.NET project using NSwag which works fine but I am attempting to add support for authentication.
My authentication model is a simple username/password that uses OAuth
using ApplicationOAuthProvider
The URL I use to login is as below
/token
With the POST parameters:
grant_type=password&username=${username}&password=${password}
Now my swagger setup [in Global.asax] is
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")
}
});
I know its a bit messy but I was literally trying every option I could to make it work.
So this actually gives me the Authorize button and a Username and Password field. But when I click login it refreshes the swagger.json but doesnt actually attempt to log in anywhere?