Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 560550b

Browse files
committed
Add logging to serversidetokenstore
1 parent f5d8786 commit 560550b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Duende.Bff.Blazor/ServerSideTokenStore.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
using Duende.AccessTokenManagement.OpenIdConnect;
66
using Microsoft.AspNetCore.Authentication;
77
using Microsoft.AspNetCore.DataProtection;
8-
using Microsoft.Extensions.Logging; // TODO - Add useful logging to this class
9-
8+
using Microsoft.Extensions.Logging;
109
namespace Duende.Bff.Blazor;
1110

1211
/// <summary>
@@ -21,6 +20,7 @@ public class ServerSideTokenStore(
2120
private readonly IDataProtector protector = dataProtectionProvider.CreateProtector(ServerSideTicketStore.DataProtectorPurpose);
2221
public async Task<UserToken> GetTokenAsync(ClaimsPrincipal user, UserTokenRequestParameters? parameters = null)
2322
{
23+
logger.LogDebug("Retrieving token for user {user}", user.Identity?.Name);
2424
var session = await GetSession(user);
2525
var ticket = session.Deserialize(protector, logger) ?? throw new InvalidOperationException("Failed to deserialize authentication ticket from session");
2626

@@ -32,6 +32,8 @@ private async Task<UserSession> GetSession(ClaimsPrincipal user)
3232
var sub = user.FindFirst("sub")?.Value ?? throw new InvalidOperationException("no sub claim");
3333
var sid = user.FindFirst("sid")?.Value ?? throw new InvalidOperationException("no sid claim");
3434

35+
logger.LogDebug("Retrieving session {sid} for sub {sub}", sid, sub);
36+
3537
var sessions = await sessionStore.GetUserSessionsAsync(new UserSessionsFilter
3638
{
3739
SubjectId = sub,
@@ -46,6 +48,7 @@ private async Task<UserSession> GetSession(ClaimsPrincipal user)
4648

4749
public async Task StoreTokenAsync(ClaimsPrincipal user, UserToken token, UserTokenRequestParameters? parameters = null)
4850
{
51+
logger.LogDebug("Storing token for user {user}", user.Identity?.Name);
4952
await UpdateTicket(user, ticket =>
5053
{
5154
tokensInAuthProperties.SetUserToken(token, ticket.Properties, parameters);
@@ -54,6 +57,7 @@ await UpdateTicket(user, ticket =>
5457

5558
public async Task ClearTokenAsync(ClaimsPrincipal user, UserTokenRequestParameters? parameters = null)
5659
{
60+
logger.LogDebug("Removing token for user {user}", user.Identity?.Name);
5761
await UpdateTicket(user, ticket =>
5862
{
5963
tokensInAuthProperties.RemoveUserToken(ticket.Properties, parameters);

0 commit comments

Comments
 (0)