mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
update infra docs
This commit is contained in:
@@ -13,18 +13,13 @@ namespace Infrastructure.Jwt;
|
||||
public class JwtInfrastructure : ITokenInfrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates a signed JWT containing the user's ID, username, issued-at time, expiry time,
|
||||
/// and a unique token identifier (JTI), signed using HMAC-SHA256 with the provided secret.
|
||||
/// Generates a signed JWT, signed using HMAC-SHA256 with the provided secret.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Sets the following registered claims: <c>sub</c> (userId), <c>unique_name</c> (username),
|
||||
/// <c>iat</c> (current UTC time), <c>exp</c> (expiry), and <c>jti</c> (a newly generated GUID).
|
||||
/// Sets registered claims <c>sub</c> (userId), <c>unique_name</c> (username), <c>iat</c> (current UTC time),
|
||||
/// <c>exp</c> (expiry), and <c>jti</c> (a newly generated GUID).
|
||||
/// </remarks>
|
||||
/// <param name="userId">The unique identifier of the user the token is issued for.</param>
|
||||
/// <param name="username">The username of the user, included as a claim.</param>
|
||||
/// <param name="expiry">The date and time at which the token expires.</param>
|
||||
/// <param name="secret">The symmetric secret used to sign the token (encoded as UTF-8 bytes).</param>
|
||||
/// <returns>The serialized, signed JWT string.</returns>
|
||||
public string GenerateJwt(Guid userId, string username, DateTime expiry, string secret)
|
||||
{
|
||||
JsonWebTokenHandler handler = new();
|
||||
@@ -61,12 +56,9 @@ public class JwtInfrastructure : ITokenInfrastructure
|
||||
/// Validates a JWT's signature and lifetime (issuer and audience validation are disabled),
|
||||
/// using the provided secret as the HMAC-SHA256 symmetric signing key.
|
||||
/// </summary>
|
||||
/// <param name="token">The JWT string to validate.</param>
|
||||
/// <param name="secret">The symmetric secret used to verify the token's signature (encoded as UTF-8 bytes).</param>
|
||||
/// <returns>A <see cref="ClaimsPrincipal" /> wrapping the validated token's claims identity.</returns>
|
||||
/// <exception cref="UnauthorizedException">
|
||||
/// 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).
|
||||
/// Thrown when the token is invalid, has no claims identity, is expired, or otherwise fails validation.
|
||||
/// </exception>
|
||||
public async Task<ClaimsPrincipal> ValidateJwtAsync(string token, string secret)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user