Add refresh token authentication system
Implement complete refresh token flow for improved security: - Short-lived access tokens (configurable, default 1h) - Long-lived refresh tokens (configurable, default 7d) - Automatic token rotation on refresh - Token revocation for proper logout Domain layer: - Add RefreshToken entity with validation and revocation - Add RefreshTokenRepository interface Application layer: - Add RefreshTokenHandler for token refresh operations - Add RevokeTokenHandler for single token revocation - Add RevokeAllTokensHandler for user-wide revocation Infrastructure layer: - Implement SQLite RefreshTokenRepository - Add refresh_tokens table migration with indexes - Add parseDuration helper for flexible time configuration HTTP layer: - Add POST /api/v1/auth/refresh endpoint - Add POST /api/v1/auth/logout endpoint - Update login/register to return refresh tokens - Improve Swagger documentation with clear descriptions Configuration: - Update .env.example with secure token expiry defaults - Add support for minute/hour/day duration formats Tests: - Fix test suite to work with new signatures - All existing tests passing
This commit is contained in:
@@ -23,6 +23,7 @@ func TestHabitRepositoryCreate(t *testing.T) {
|
||||
value_objects.HabitTypeBoolean,
|
||||
value_objects.FrequencyDaily,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
habit.Description = "Exercise every morning"
|
||||
|
||||
@@ -49,6 +50,7 @@ func TestHabitRepositoryCreateWithSpecificDays(t *testing.T) {
|
||||
value_objects.HabitTypeBoolean,
|
||||
value_objects.FrequencyWeekly,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
habit.SpecificDays = []int{1, 3, 5}
|
||||
|
||||
@@ -80,6 +82,7 @@ func TestHabitRepositoryFindByID(t *testing.T) {
|
||||
value_objects.HabitTypeCounter,
|
||||
value_objects.FrequencyDaily,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
targetValue := 30.0
|
||||
habit.TargetValue = &targetValue
|
||||
@@ -165,6 +168,7 @@ func TestHabitRepositoryUpdate(t *testing.T) {
|
||||
value_objects.HabitTypeBoolean,
|
||||
value_objects.FrequencyDaily,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
|
||||
err := repo.Create(ctx, habit)
|
||||
@@ -210,6 +214,7 @@ func TestHabitRepositoryUpdateNotFound(t *testing.T) {
|
||||
value_objects.HabitTypeBoolean,
|
||||
value_objects.FrequencyDaily,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
habit.ID = "non-existent"
|
||||
|
||||
@@ -232,6 +237,7 @@ func TestHabitRepositoryArchive(t *testing.T) {
|
||||
value_objects.HabitTypeBoolean,
|
||||
value_objects.FrequencyDaily,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
|
||||
err := repo.Create(ctx, habit)
|
||||
|
||||
Reference in New Issue
Block a user