40 lines
1011 B
C#
40 lines
1011 B
C#
namespace TaxBaik.Web.Services;
|
|
|
|
/// <summary>
|
|
/// Scoped in-memory token store for Blazor Server.
|
|
/// SOLID: Single Responsibility - Token lifecycle management
|
|
/// Avoids JS interop from DelegatingHandler (which runs on non-circuit thread)
|
|
/// </summary>
|
|
public interface ITokenStore
|
|
{
|
|
string? AccessToken { get; set; }
|
|
string? RefreshToken { get; set; }
|
|
long? TokenExpiryTicks { get; set; }
|
|
|
|
bool IsAccessTokenExpired();
|
|
void Clear();
|
|
}
|
|
|
|
public class TokenStore : ITokenStore
|
|
{
|
|
public string? AccessToken { get; set; }
|
|
public string? RefreshToken { get; set; }
|
|
public long? TokenExpiryTicks { get; set; }
|
|
|
|
public bool IsAccessTokenExpired()
|
|
{
|
|
if (TokenExpiryTicks == null)
|
|
return true;
|
|
|
|
var expiryTime = new DateTime(TokenExpiryTicks.Value, DateTimeKind.Utc);
|
|
return expiryTime <= DateTime.UtcNow;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
AccessToken = null;
|
|
RefreshToken = null;
|
|
TokenExpiryTicks = null;
|
|
}
|
|
}
|