Skip to content

Commit

Permalink
Debug logging for auth provider add/remove
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffputz committed Jul 6, 2024
1 parent 09864ba commit 6a2f424
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/PopForums.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authorization;
using System;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using PopForums.AzureKit;
Expand All @@ -11,7 +12,11 @@
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.ResponseCompression;
using System.IO.Compression;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using PopForums.Configuration;

var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
Expand Down Expand Up @@ -83,6 +88,10 @@
services.Configure<BrotliCompressionProviderOptions>(options => options.Level = CompressionLevel.Fastest);


// temporary for https://github.com/dotnet/aspnetcore/discussions/56205
services.RemoveAll<IAuthenticationSchemeProvider>();
services.AddSingleton<IAuthenticationSchemeProvider, LoggingAuthSchemeProvider>();

var app = builder.Build();

if (!app.Environment.IsDevelopment())
Expand Down Expand Up @@ -124,4 +133,23 @@
"default",
"{controller=Home}/{action=Index}/{id?}");

app.Run();
app.Run();


// temporary for https://github.com/dotnet/aspnetcore/discussions/56205

public class LoggingAuthSchemeProvider(IOptions<AuthenticationOptions> options, IErrorLog logger)
: AuthenticationSchemeProvider(options)
{
public override bool TryAddScheme(AuthenticationScheme scheme)
{
logger.Log(null, ErrorSeverity.Information, $"Adding scheme '{scheme.Name}'.");
return base.TryAddScheme(scheme);
}

public override void RemoveScheme(string name)
{
logger.Log(null, ErrorSeverity.Critical, $"Removing scheme '{name}'!!!{Environment.StackTrace}");
base.RemoveScheme(name);
}
}

0 comments on commit 6a2f424

Please sign in to comment.