//
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
//
using System.Text;
using Astral.Core.Options;
using Microsoft.IdentityModel.Tokens;
namespace Astral.ApiServer.Extensions;
///
/// Extensions for .
///
public static class JwtOptionsExtensions
{
///
/// Generate an instance of from .
///
/// Instance of .
/// Instance of .
public static TokenValidationParameters ToTokenValidationParameters(this JwtOptions config)
{
return new TokenValidationParameters
{
ValidateIssuer = config.ValidateIssuer,
ValidateAudience = config.ValidateAudience,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidAudience = config.Audience,
ValidAudiences =
[config.Audience],
ValidIssuer = config.Issuer,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(config.SecretKey))
};
}
}