I have an ASP.NET Core 2.2 Web Api and I added the swagger support with nswag. The web api is protected using a local IdentityServer4 that generates access tokens.
I found the code to add an authorization button and form and set the bearer token in the header. And it works!
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddSwaggerDocument(config =>
{
config.DocumentName = "OpenAPI 2";
config.OperationProcessors.Add(new OperationSecurityScopeProcessor("JWT Token"));
config.AddSecurity("JWT Token", Enumerable.Empty<string>(),
new OpenApiSecurityScheme()
{
Type = OpenApiSecuritySchemeType.ApiKey,
Name = "Authorization",
In = OpenApiSecurityApiKeyLocation.Header,
Description = "Copy this into the value field: Bearer {token}"
}
);
});
//...
}
Button in the swagger page
Form for copy/paste of the bearer token
I'm looking for a way to automate the flow and setting the access token without a copy/paste.
Is it possible to setup nswag to do this?