✨ feat(auth): JWT secret retention policy + automatic cleanup loop (ADR-0021) (#41)
Co-authored-by: Gabriel Radureau <arcodange@gmail.com> Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
This commit was merged in pull request #41.
This commit is contained in:
@@ -24,13 +24,25 @@ type JWTSecret struct {
|
||||
ExpiresAt *time.Time // Optional expiration time
|
||||
}
|
||||
|
||||
// JWTSecretManager manages multiple JWT secrets for rotation
|
||||
// JWTSecretManager manages multiple JWT secrets for rotation.
|
||||
// Secrets can carry an optional expiration; the cleanup loop removes them
|
||||
// after expiry while always preserving the primary secret (ADR-0021).
|
||||
type JWTSecretManager interface {
|
||||
AddSecret(secret string, isPrimary bool, expiresIn time.Duration)
|
||||
RotateToSecret(newSecret string)
|
||||
GetPrimarySecret() string
|
||||
GetAllValidSecrets() []JWTSecret
|
||||
GetSecretByIndex(index int) (string, bool)
|
||||
|
||||
// RemoveExpiredSecrets drops every non-primary secret whose ExpiresAt is
|
||||
// non-nil and in the past. Returns the count of secrets removed.
|
||||
// The primary secret is never removed regardless of expiration.
|
||||
RemoveExpiredSecrets() int
|
||||
|
||||
// StartCleanupLoop spawns a goroutine that calls RemoveExpiredSecrets at
|
||||
// the given interval. Stops when the context is cancelled. Safe to call
|
||||
// once at startup; calling again replaces the previous loop's context.
|
||||
StartCleanupLoop(ctx context.Context, interval time.Duration)
|
||||
}
|
||||
|
||||
// JWTService defines interface for JWT operations
|
||||
|
||||
Reference in New Issue
Block a user