1
0
mirror of https://github.com/bitwarden/server synced 2026-01-16 07:23:15 +00:00

[PM-25415] move files into better place for code ownership (#6275)

* chore: move files into better place for code ownership

* fix: import correct namespace
This commit is contained in:
Ike
2025-09-04 10:08:03 -04:00
committed by GitHub
parent cdf1d7f074
commit 96fe09af89
54 changed files with 65 additions and 65 deletions

View File

@@ -0,0 +1,66 @@
// FIXME: Update this file to be null safe and then delete the line below
#nullable disable
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.Caching.Distributed;
namespace Bit.Core.Auth.IdentityServer;
public class DistributedCacheTicketStore : ITicketStore
{
private const string KeyPrefix = "auth-";
private readonly IDistributedCache _cache;
public DistributedCacheTicketStore(IDistributedCache distributedCache)
{
_cache = distributedCache;
}
public async Task<string> StoreAsync(AuthenticationTicket ticket)
{
var key = $"{KeyPrefix}{Guid.NewGuid()}";
await RenewAsync(key, ticket);
return key;
}
public Task RenewAsync(string key, AuthenticationTicket ticket)
{
var options = new DistributedCacheEntryOptions();
var expiresUtc = ticket.Properties.ExpiresUtc ??
DateTimeOffset.UtcNow.AddMinutes(15);
options.SetAbsoluteExpiration(expiresUtc);
var val = SerializeToBytes(ticket);
_cache.Set(key, val, options);
return Task.FromResult(0);
}
public Task<AuthenticationTicket> RetrieveAsync(string key)
{
AuthenticationTicket ticket;
var bytes = _cache.Get(key);
ticket = DeserializeFromBytes(bytes);
return Task.FromResult(ticket);
}
public Task RemoveAsync(string key)
{
_cache.Remove(key);
return Task.FromResult(0);
}
private static byte[] SerializeToBytes(AuthenticationTicket source)
{
return TicketSerializer.Default.Serialize(source);
}
private static AuthenticationTicket DeserializeFromBytes(byte[] source)
{
return source == null ? null : TicketSerializer.Default.Deserialize(source);
}
}