28 lines
858 B
C#
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");
|
|
}
|
|
}
|
|
}
|