35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
|
// <copyright file="JwtConfigurationExtensions.cs" company="alveus.dev">
|
||
|
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
|
||
|
// </copyright>
|
||
|
|
||
|
using Astral.Core.Options;
|
||
|
using TimeSpanParserUtil;
|
||
|
|
||
|
namespace Astral.Core.Extensions;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Extensions for <see cref="JwtOptions" />.
|
||
|
/// </summary>
|
||
|
public static class JwtConfigurationExtensions
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Return when (UTC) the access token expires.
|
||
|
/// </summary>
|
||
|
/// <param name="configuration">Instance of <see cref="JwtOptions" />.</param>
|
||
|
/// <returns>A UTC DateTime of when the expiration occurs.</returns>
|
||
|
public static DateTime AccessTokenExpirationDateTime(this JwtOptions 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="JwtOptions" />.</param>
|
||
|
/// <returns>A UTC DateTime of when the expiration occurs.</returns>
|
||
|
public static DateTime RefreshTokenExpirationDateTime(this JwtOptions configuration)
|
||
|
{
|
||
|
return DateTime.UtcNow.Add(TimeSpanParser.Parse(configuration.RefreshTokenExpiration));
|
||
|
}
|
||
|
}
|