43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Text;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace USEntryCoach.Server.Settings;
|
|
|
|
public sealed class ApiSettings
|
|
{
|
|
public const string SectionName = "API";
|
|
|
|
[Required(ErrorMessage = "OpenAI API token is required!", AllowEmptyStrings = false)]
|
|
public required string OpenAiToken { get; set; }
|
|
}
|
|
|
|
public sealed class AuthenticationSettings
|
|
{
|
|
public const string SectionName = "Authentication";
|
|
|
|
private string _jwtGenerationSecret = null!;
|
|
|
|
[Required(ErrorMessage = "JWT generation secret token is required!", AllowEmptyStrings = false)]
|
|
public required string JwtGenerationSecret
|
|
{
|
|
get => _jwtGenerationSecret;
|
|
set
|
|
{
|
|
_jwtGenerationSecret = value;
|
|
JwtGenerationSecretBytes = Encoding.UTF8.GetBytes(value);
|
|
}
|
|
}
|
|
|
|
public byte[] JwtGenerationSecretBytes { get; private set; }
|
|
|
|
const string JwtExpiryTimeMin = "00:00:30";
|
|
const string JwtExpiryTimeMax = "24:00:00";
|
|
|
|
[Range(typeof(TimeSpan), JwtExpiryTimeMin, JwtExpiryTimeMax,
|
|
ErrorMessage = $"JWT expiry time must be in the range from {JwtExpiryTimeMin} to {JwtExpiryTimeMax}.")]
|
|
public TimeSpan JwtExpiryTime { get; set; } = TimeSpan.FromMinutes(5);
|
|
}
|
|
|