From da4f97de04643e8864ad16c57c952102aa06a7d3 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Sat, 5 Oct 2024 09:33:56 +0100 Subject: [PATCH] Fix the bug with user not being redirected to originally requested URL post authentication. --- helpers.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/helpers.go b/helpers.go index abb88b7..a6189e0 100644 --- a/helpers.go +++ b/helpers.go @@ -226,7 +226,14 @@ func (t *TraefikOidc) handleCallback(rw http.ResponseWriter, req *http.Request) } t.logger.Debugf("Authentication successful. User email: %s", email) - http.Redirect(rw, req, "/", http.StatusFound) + http.Redirect(rw, req, func() string { + if path, ok := session.Values["incoming_path"].(string); ok { + t.logger.Debug("Redirecting to incoming path from original request: %s", path) + return path + } + t.logger.Debug("Redirecting to root path as no incoming path found") + return "/" + }(), http.StatusFound) } func extractClaims(tokenString string) (map[string]interface{}, error) {