mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-12 04:04:26 +00:00
fixup! Add support for the anchor redirects
This commit is contained in:
+11
-11
@@ -286,18 +286,18 @@ func (t *TraefikOidc) handleCallback(rw http.ResponseWriter, req *http.Request,
|
|||||||
http.Error(rw, "Failed to save session", http.StatusInternalServerError)
|
http.Error(rw, "Failed to save session", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Redirect to original path or root
|
// Redirect to original path or root
|
||||||
redirectPath := "/"
|
redirectPath := "/"
|
||||||
if incomingPath := session.GetIncomingPath(); incomingPath != "" && incomingPath != t.redirURLPath {
|
if incomingPath := session.GetIncomingPath(); incomingPath != "" && incomingPath != t.redirURLPath {
|
||||||
redirectPath = incomingPath
|
redirectPath = incomingPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// For redirecting, we need to ensure URL fragments are preserved
|
// For redirecting, we need to ensure URL fragments are preserved
|
||||||
// To do this, we'll use a small JavaScript snippet that preserves any URL fragments
|
// To do this, we'll use a small JavaScript snippet that preserves any URL fragments
|
||||||
// This is necessary because URL fragments are not sent to the server
|
// This is necessary because URL fragments are not sent to the server
|
||||||
rw.Header().Set("Content-Type", "text/html; charset=utf-8")
|
rw.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
rw.WriteHeader(http.StatusOK)
|
rw.WriteHeader(http.StatusOK)
|
||||||
fmt.Fprintf(rw, `<!DOCTYPE html>
|
fmt.Fprintf(rw, `<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Authentication Complete</title>
|
<title>Authentication Complete</title>
|
||||||
|
|||||||
+2
-2
@@ -2132,11 +2132,11 @@ func TestHandleCallback_PreservesURLFragments(t *testing.T) {
|
|||||||
if !strings.Contains(body, "/dashboard?param=value") {
|
if !strings.Contains(body, "/dashboard?param=value") {
|
||||||
t.Errorf("Response body doesn't contain the original redirect path")
|
t.Errorf("Response body doesn't contain the original redirect path")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(body, "window.location.hash") {
|
if !strings.Contains(body, "window.location.hash") {
|
||||||
t.Errorf("Response doesn't contain JavaScript logic to preserve URL fragments")
|
t.Errorf("Response doesn't contain JavaScript logic to preserve URL fragments")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(body, "redirectUrl.hash = window.location.hash") {
|
if !strings.Contains(body, "redirectUrl.hash = window.location.hash") {
|
||||||
t.Errorf("Response doesn't contain logic to copy the fragment from current URL")
|
t.Errorf("Response doesn't contain logic to copy the fragment from current URL")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user