AS400_API_DOTNET/Configuration/JwtOptions.cs
2025-10-17 16:01:56 +07:00

28 lines
858 B
C#

using System;
using System.Text;
namespace AS400API.Configuration;
public sealed class JwtOptions
{
public const string SectionName = "Jwt";
public string Issuer { get; set; } = "AS400API";
public string Audience { get; set; } = "AS400API.Clients";
public string Key { get; set; } = "change-me-to-a-long-random-secret";
public int AccessTokenLifetimeMinutes { get; set; } = 60;
public void EnsureIsValid()
{
if (string.IsNullOrWhiteSpace(Key) || Encoding.UTF8.GetByteCount(Key) < 32)
{
throw new InvalidOperationException("Jwt:Key must be at least 32 UTF-8 bytes. Set a strong secret in configuration");
}
if (AccessTokenLifetimeMinutes <= 0)
{
throw new InvalidOperationException("Jwt:AccessTokenLifetimeMinutes must be a positive integer");
}
}
}