JWT Manager
JWT Manager provides a reusable and extensible interface for creating and validating JSON Web Tokens (JWTs) in Go, supporting both HMAC (HS256) and RSA (RS256) signing methods.
Features
Token Creation: Generate signed JWT tokens with custom claims.
Token Validation: Parse and validate tokens with support for custom claims.
Pluggable Signing Methods: Easily switch between HS256 (HMAC) and RS256 (RSA).
Usage
JWTManager Interface
CreateToken: Generates a signed JWT token with the provided claims.
Params:
ctx
: Context for request tracing or cancellation.claims
: Claims to include in the token (must implement jwt.Claims).
Returns: Signed token string or an error.
ParseAndValidateToken: Parses and validates a JWT token, populating the provided claims struct.
Params:
ctx
: Context for request tracing or cancellation.tokenString
: The JWT token string to validate.claims
: Pointer to a claims struct to populate (must implement jwt.Claims).
Returns: Error if validation fails; otherwise, populates the provided claims struct.
Examples
Last updated