From 5f89fb78a5bcbfeb1d02b371b4ea0256a0a33efa Mon Sep 17 00:00:00 2001 From: Christian Roessner Date: Wed, 30 Oct 2024 14:56:38 +0100 Subject: [PATCH] Fix: Add Redis dependency and check user existence with Redis Integrated the Redis library to the project and modified the runLuaFilterAndPost function to check if a user exists using Redis. Handled potential Redis-related errors and adjusted the UserFound logic accordingly. Signed-off-by: Christian Roessner --- server/core/hydra.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/core/hydra.go b/server/core/hydra.go index bccf0479..3f3f6a6c 100644 --- a/server/core/hydra.go +++ b/server/core/hydra.go @@ -40,6 +40,7 @@ import ( openapi "github.com/ory/hydra-client-go/v2" "github.com/pquerna/otp" "github.com/pquerna/otp/totp" + "github.com/redis/go-redis/v9" "github.com/spf13/viper" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -1640,6 +1641,13 @@ func (a *ApiConfig) logFailedLoginAndRedirect(auth *AuthState) { // runLuaFilterAndPost filters and executes post-action Lua scripts based on the given post-2FA authentication result. func runLuaFilterAndPost(ctx *gin.Context, auth *AuthState, authResult global.AuthResult) global.AuthResult { + userFound, err := auth.userExists() + if err != nil { + if !stderrors.Is(err, redis.Nil) { + level.Error(log.Logger).Log(global.LogKeyGUID, auth.GUID, global.LogKeyError, err) + } + } + passDBResult := &PassDBResult{ Authenticated: func() bool { if authResult == global.AuthResultOK { @@ -1648,7 +1656,7 @@ func runLuaFilterAndPost(ctx *gin.Context, auth *AuthState, authResult global.Au return false }(), - UserFound: auth.UserFound, + UserFound: userFound, } authResult = auth.filterLua(passDBResult, ctx)