feat(logging): add comprehensive authentication logging
- Add cookie authentication event logging in Program.cs (redirect to login, access denied, principal validation) - Add logging in RedirectToLogin.razor for redirection tracking - Add detailed logging in Login.razor for login attempts, 2FA verification, and authentication completion - Add structured logging in AuthController for all authentication endpoints (register, login, 2fa, refresh, change-password, logout, etc.) - Use appropriate log levels (Information, Warning, Error, Debug) based on event importance
This commit is contained in:
1 parent
550c621f35
commit
a379f2b136
4 files changed
+162
-25
No files matched your search
@@ -232,6 +232,33 @@ public partial class Program {
|
||||
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
|
||||
options.ExpireTimeSpan = TimeSpan.FromDays(7);
|
||||
options.SlidingExpiration = true;
|
||||
|
||||
// Add logging events
|
||||
options.Events = new CookieAuthenticationEvents
|
||||
{
|
||||
OnRedirectToLogin = context =>
|
||||
{
|
||||
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<Program>>();
|
||||
logger.LogWarning("Redirect to login: {Path} -> {LoginPath}",
|
||||
context.Request.Path, options.LoginPath);
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
return Task.CompletedTask;
|
||||
},
|
||||
OnRedirectToAccessDenied = context =>
|
||||
{
|
||||
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<Program>>();
|
||||
logger.LogWarning("Access denied: {Path} -> {AccessDeniedPath}",
|
||||
context.Request.Path, options.AccessDeniedPath);
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
return Task.CompletedTask;
|
||||
},
|
||||
OnValidatePrincipal = context =>
|
||||
{
|
||||
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<Program>>();
|
||||
logger.LogDebug("Validating principal for {Path}", context.HttpContext.Request.Path);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
};
|
||||
})
|
||||
.AddJwtBearer("JwtBearer", options =>
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user