33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
|
using System.Text;
|
||
|
using Galaeth.Core.Configuration;
|
||
|
using Microsoft.IdentityModel.Tokens;
|
||
|
|
||
|
namespace Galaeth.ApiServer.Extensions;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Extensions for <see cref="JwtConfiguration"/>.
|
||
|
/// </summary>
|
||
|
public static class JwtConfigurationExtensions
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Generate an instance of <see cref="TokenValidationParameters"/> from <see cref="JwtConfiguration"/>.
|
||
|
/// </summary>
|
||
|
/// <param name="config">Instance of <see cref="JwtConfiguration"/>.</param>
|
||
|
/// <returns>Instance of <see cref="TokenValidationParameters"/>.</returns>
|
||
|
public static TokenValidationParameters ToTokenValidationParameters(this JwtConfiguration 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)),
|
||
|
};
|
||
|
}
|
||
|
}
|