I\'m trying to add authorization header into SwaggerUI api test. below is my Startup.cs
public void ConfigureServices(IServiceCollection services)
{
In addition to what Kiril said,in my case I want to get the JWT token through Swagger and this is the code I used, adding the OpenApiSecurityScheme to what he suggested:
c.AddSecurityDefinition("bearer",
new OpenApiSecurityScheme{
Flows = new OpenApiOAuthFlows()
{
ClientCredentials = new OpenApiOAuthFlow()
{
TokenUrl = new Uri("https://auth.myauthserver.com/oauth2/token"),
Scopes = new Dictionary(){ {"myscope", "Access API"}},
AuthorizationUrl = new Uri("https://auth.myauthserver.com/oauth2/authorize")
}
},
Type = SecuritySchemeType.OAuth2,
OpenIdConnectUrl = new Uri("https://myauthserver/.well-known/openid-configuration"),
BearerFormat = "JWT",
In = ParameterLocation.Header,
Scheme = "bearer"
});