using Microsoft.IdentityModel.Tokens; using System.IdentityModel.Tokens.Jwt; using System.Security.Cryptography; namespace DigitalData.Core.Application.Interfaces { /// /// Defines the operations for JWT service handling claims of type . /// public interface IJWTService { /// /// Generates a symmetric security key with the specified byte size. /// /// The size of the security key in bytes. Default is 32 bytes. /// A new instance of . public static SymmetricSecurityKey GenerateSecurityKey(int byteSize = 32) { using var rng = RandomNumberGenerator.Create(); var randomBytes = new byte[byteSize]; rng.GetBytes(randomBytes); var securityKey = new SymmetricSecurityKey(randomBytes); return securityKey; } /// /// Generates a token based on the specified claim value. /// /// The claim value to encode in the token. /// A JWT as a string. string GenerateToken(TClaimValue claimValue); /// /// Reads and validates a security token from a string representation. /// /// The JWT to read. /// A if the token is valid; otherwise, null. JwtSecurityToken? ReadSecurityToken(string token); } }