galaeth-draft/Galaeth.Core/Extensions/JwtConfigurationExtensions.cs
2024-11-17 09:31:01 +00:00

31 lines
1.1 KiB
C#

using Galaeth.Core.Configuration;
using TimeSpanParserUtil;
namespace Galaeth.Core.Extensions;
/// <summary>
/// Extensions for <see cref="JwtConfiguration"/>.
/// </summary>
public static class JwtConfigurationExtensions
{
/// <summary>
/// Return when (UTC) the access token expires.
/// </summary>
/// <param name="configuration">Instance of <see cref="JwtConfiguration"/>.</param>
/// <returns>A UTC DateTime of when the expiration occurs.</returns>
public static DateTime AccessTokenExpirationDateTime(this JwtConfiguration configuration)
{
return DateTime.UtcNow.Add(TimeSpanParser.Parse(configuration.AccessTokenExpiration));
}
/// <summary>
/// Return when (UTC) the refresh token expires.
/// </summary>
/// <param name="configuration">Instance of <see cref="JwtConfiguration"/>.</param>
/// <returns>A UTC DateTime of when the expiration occurs.</returns>
public static DateTime RefreshTokenExpirationDateTime(this JwtConfiguration configuration)
{
return DateTime.UtcNow.Add(TimeSpanParser.Parse(configuration.RefreshTokenExpiration));
}
}