Paul B
Paul B

Reputation: 11

Exclude NSwag Swagger UI from ASP.NET Core Authentication

I'm using NSwag library and AzureAD for authentication and want to exclude the swagger UI from asp.net core authentication entirely, similar to using the AllowAnonymous attribute on the controller.

builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
             .AddMicrosoftIdentityWebApi(adSection);


builder.Services.AddAuthorization(options =>
{
    // By default, all incoming requests will be authorized according to 
    // the default policy
    options.FallbackPolicy = options.DefaultPolicy;
});

Upvotes: 0

Views: 29

Answers (1)

Ruikai Feng
Ruikai Feng

Reputation: 11621

move swagger related middlewares

app.UseOpenApi();   
app.UseSwaggerUi();

before app.UseAuthorization();

Upvotes: 0

Related Questions