prevent PII detail leaks

This commit is contained in:
Oliver Kieselbach
2026-02-07 22:25:06 +01:00
parent 3a46310cba
commit 2001dbaa29
2 changed files with 6 additions and 3 deletions
@@ -8,6 +8,7 @@ using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Azure.Functions.Worker.Middleware;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Identity.Web;
var builder = FunctionsApplication.CreateBuilder(args);
@@ -39,15 +40,16 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
{
OnAuthenticationFailed = context =>
{
Console.WriteLine($"[Auth] Authentication failed: {context.Exception?.Message}");
var logger = context.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>().CreateLogger("Auth");
logger.LogWarning("Authentication failed: {Error}", context.Exception?.Message);
return Task.CompletedTask;
},
OnTokenValidated = context =>
{
var logger = context.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>().CreateLogger("Auth");
var claims = context.Principal?.Claims;
var tenantId = claims?.FirstOrDefault(c => c.Type == "tid")?.Value;
var upn = claims?.FirstOrDefault(c => c.Type == "upn" || c.Type == "preferred_username")?.Value;
Console.WriteLine($"[Auth] Token validated for user: {upn}, tenant: {tenantId}");
logger.LogDebug("Token validated for tenant: {TenantId}", tenantId);
return Task.CompletedTask;
}
};
@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Generic;