December 6, 2023

ASP.NET Core 8.0: Securing Swagger UI Endpoints

With ASP.NET Core 8.0, now you can secure Swagger UI endpoints by calling MapSwagger().RequireAuthorization. Consider the following code example. WebApplicationBuilder builder = WebApplication.CreateBuilder(args); builder.Services.AddEndpointsApiExplorer();builder.Services.AddSwaggerGen(); builder.Services.AddAuthorization();builder.Services.AddAuthentication(“Bearer”