diff --git a/FakeNTLMServer.csproj b/FakeNTLMServer.csproj index a3048ca..6e1eaf0 100644 --- a/FakeNTLMServer.csproj +++ b/FakeNTLMServer.csproj @@ -1,4 +1,4 @@ - + net8.0 diff --git a/Program.cs b/Program.cs index 7488e3e..d22627e 100644 --- a/Program.cs +++ b/Program.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Authentication.Negotiate; +using Microsoft.OpenApi.Models; var builder = WebApplication.CreateBuilder(args); @@ -11,7 +12,42 @@ builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme) builder.Services.AddAuthorization(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); +builder.Services.AddSwaggerGen(options => +{ + options.SwaggerDoc("v1", new OpenApiInfo + { + Title = "FakeNTLMServer", + Version = "v1", + Description = "NTLM/Negotiate authentication test server" + }); + + options.AddSecurityDefinition("Negotiate", new OpenApiSecurityScheme + { + Type = SecuritySchemeType.Http, + Scheme = "Negotiate", + Description = "Windows Authentication (NTLM/Kerberos). Credentials are sent automatically by the browser." + }); + + options.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Negotiate" + } + }, + Array.Empty() + } + }); + + var xmlFile = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + if (File.Exists(xmlPath)) + options.IncludeXmlComments(xmlPath); +}); var app = builder.Build(); @@ -19,7 +55,11 @@ var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseSwagger(); - app.UseSwaggerUI(); + app.UseSwaggerUI(options => + { + // Enable sending credentials (NTLM tokens) with Swagger UI requests + options.ConfigObject.AdditionalItems["withCredentials"] = true; + }); } app.UseHttpsRedirection();