From 1399147ac93c652443502a1ea0b102122f4ed24c Mon Sep 17 00:00:00 2001 From: Joe DeCock Date: Fri, 16 Aug 2024 15:07:02 -0500 Subject: [PATCH] Add logging to serversidetokenstore --- src/Duende.Bff.Blazor/ServerSideTokenStore.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Duende.Bff.Blazor/ServerSideTokenStore.cs b/src/Duende.Bff.Blazor/ServerSideTokenStore.cs index 1870d8bc..d97bee81 100644 --- a/src/Duende.Bff.Blazor/ServerSideTokenStore.cs +++ b/src/Duende.Bff.Blazor/ServerSideTokenStore.cs @@ -5,8 +5,7 @@ using Duende.AccessTokenManagement.OpenIdConnect; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.DataProtection; -using Microsoft.Extensions.Logging; // TODO - Add useful logging to this class - +using Microsoft.Extensions.Logging; namespace Duende.Bff.Blazor; /// @@ -21,6 +20,7 @@ public class ServerSideTokenStore( private readonly IDataProtector protector = dataProtectionProvider.CreateProtector(ServerSideTicketStore.DataProtectorPurpose); public async Task GetTokenAsync(ClaimsPrincipal user, UserTokenRequestParameters? parameters = null) { + logger.LogDebug("Retrieving token for user {user}", user.Identity?.Name); var session = await GetSession(user); var ticket = session.Deserialize(protector, logger) ?? throw new InvalidOperationException("Failed to deserialize authentication ticket from session"); @@ -32,6 +32,8 @@ private async Task GetSession(ClaimsPrincipal user) var sub = user.FindFirst("sub")?.Value ?? throw new InvalidOperationException("no sub claim"); var sid = user.FindFirst("sid")?.Value ?? throw new InvalidOperationException("no sid claim"); + logger.LogDebug("Retrieving session {sid} for sub {sub}", sid, sub); + var sessions = await sessionStore.GetUserSessionsAsync(new UserSessionsFilter { SubjectId = sub, @@ -46,6 +48,7 @@ private async Task GetSession(ClaimsPrincipal user) public async Task StoreTokenAsync(ClaimsPrincipal user, UserToken token, UserTokenRequestParameters? parameters = null) { + logger.LogDebug("Storing token for user {user}", user.Identity?.Name); await UpdateTicket(user, ticket => { tokensInAuthProperties.SetUserToken(token, ticket.Properties, parameters); @@ -54,6 +57,7 @@ await UpdateTicket(user, ticket => public async Task ClearTokenAsync(ClaimsPrincipal user, UserTokenRequestParameters? parameters = null) { + logger.LogDebug("Removing token for user {user}", user.Identity?.Name); await UpdateTicket(user, ticket => { tokensInAuthProperties.RemoveUserToken(ticket.Properties, parameters);