From 62766b7638440061e6eb144ad53418d0eefe76de Mon Sep 17 00:00:00 2001 From: Aaron Po Date: Sat, 20 Jun 2026 15:13:02 -0400 Subject: [PATCH] Format ./web/backend/Infrastructure/Infrastructure.Jwt --- .../ITokenInfrastructure.cs | 9 ++----- .../Infrastructure.Jwt.csproj | 12 +++------ .../Infrastructure.Jwt/JwtInfrastructure.cs | 25 ++++++------------- 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/web/backend/Infrastructure/Infrastructure.Jwt/ITokenInfrastructure.cs b/web/backend/Infrastructure/Infrastructure.Jwt/ITokenInfrastructure.cs index 7fbf240..c26ea32 100644 --- a/web/backend/Infrastructure/Infrastructure.Jwt/ITokenInfrastructure.cs +++ b/web/backend/Infrastructure/Infrastructure.Jwt/ITokenInfrastructure.cs @@ -15,12 +15,7 @@ public interface ITokenInfrastructure /// The date and time at which the token expires. /// The symmetric secret used to sign the token. /// The serialized, signed JWT string. - string GenerateJwt( - Guid userId, - string username, - DateTime expiry, - string secret - ); + string GenerateJwt(Guid userId, string username, DateTime expiry, string secret); /// /// Validates a JWT and returns the resulting claims principal. @@ -33,4 +28,4 @@ public interface ITokenInfrastructure /// validation. /// Task ValidateJwtAsync(string token, string secret); -} \ No newline at end of file +} diff --git a/web/backend/Infrastructure/Infrastructure.Jwt/Infrastructure.Jwt.csproj b/web/backend/Infrastructure/Infrastructure.Jwt/Infrastructure.Jwt.csproj index 3823c8d..d66c84f 100644 --- a/web/backend/Infrastructure/Infrastructure.Jwt/Infrastructure.Jwt.csproj +++ b/web/backend/Infrastructure/Infrastructure.Jwt/Infrastructure.Jwt.csproj @@ -7,17 +7,11 @@ - - + + - + diff --git a/web/backend/Infrastructure/Infrastructure.Jwt/JwtInfrastructure.cs b/web/backend/Infrastructure/Infrastructure.Jwt/JwtInfrastructure.cs index 165197b..72837bb 100644 --- a/web/backend/Infrastructure/Infrastructure.Jwt/JwtInfrastructure.cs +++ b/web/backend/Infrastructure/Infrastructure.Jwt/JwtInfrastructure.cs @@ -25,12 +25,7 @@ public class JwtInfrastructure : ITokenInfrastructure /// The date and time at which the token expires. /// The symmetric secret used to sign the token (encoded as UTF-8 bytes). /// The serialized, signed JWT string. - public string GenerateJwt( - Guid userId, - string username, - DateTime expiry, - string secret - ) + public string GenerateJwt(Guid userId, string username, DateTime expiry, string secret) { JsonWebTokenHandler handler = new(); byte[] key = Encoding.UTF8.GetBytes(secret); @@ -46,7 +41,7 @@ public class JwtInfrastructure : ITokenInfrastructure JwtRegisteredClaimNames.Exp, new DateTimeOffset(expiry).ToUnixTimeSeconds().ToString() ), - new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) + new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), }; SecurityTokenDescriptor tokenDescriptor = new() @@ -56,13 +51,12 @@ public class JwtInfrastructure : ITokenInfrastructure SigningCredentials = new SigningCredentials( new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256 - ) + ), }; return handler.CreateToken(tokenDescriptor); } - /// /// Validates a JWT's signature and lifetime (issuer and audience validation are disabled), /// using the provided secret as the HMAC-SHA256 symmetric signing key. @@ -74,21 +68,16 @@ public class JwtInfrastructure : ITokenInfrastructure /// Thrown when the token is invalid, has no claims identity, is expired, or otherwise fails validation /// (including when validation itself throws, e.g. due to a malformed token or signature mismatch). /// - public async Task ValidateJwtAsync( - string token, - string secret - ) + public async Task ValidateJwtAsync(string token, string secret) { JsonWebTokenHandler handler = new(); - byte[] keyBytes = Encoding.UTF8.GetBytes( - secret - ); + byte[] keyBytes = Encoding.UTF8.GetBytes(secret); TokenValidationParameters parameters = new() { ValidateIssuer = false, ValidateAudience = false, ValidateLifetime = true, - IssuerSigningKey = new SymmetricSecurityKey(keyBytes) + IssuerSigningKey = new SymmetricSecurityKey(keyBytes), }; try @@ -104,4 +93,4 @@ public class JwtInfrastructure : ITokenInfrastructure throw new UnauthorizedException("Invalid token"); } } -} \ No newline at end of file +}