mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-13 04:07:37 +00:00
fixup! fixup! fixup! Downgrade gorilla sessions preventing the publishing by traefik hub temporarily.
This commit is contained in:
+15
-3
@@ -385,14 +385,22 @@ func (t *TraefikOidc) handleLogout(rw http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Build post logout redirect URI if not set
|
||||
// Build post logout redirect URI with FQDN if not set
|
||||
if t.postLogoutRedirectURI == "" {
|
||||
t.postLogoutRedirectURI = buildFullURL(t.scheme, t.determineHost(req), "/")
|
||||
// Get the host from request headers or direct host
|
||||
host := t.determineHost(req)
|
||||
scheme := t.determineScheme(req)
|
||||
|
||||
// Build the full URL with scheme and host
|
||||
t.postLogoutRedirectURI = fmt.Sprintf("%s://%s%s",
|
||||
scheme,
|
||||
host,
|
||||
t.logoutURLPath)
|
||||
}
|
||||
|
||||
// If we have an end session endpoint and an ID token, use OIDC end session
|
||||
if t.endSessionURL != "" && idToken != "" {
|
||||
logoutURL, err := BuildLogoutURL(t.endSessionURL, idToken, t.logoutURLPath)
|
||||
logoutURL, err := BuildLogoutURL(t.endSessionURL, idToken, t.postLogoutRedirectURI)
|
||||
if err != nil {
|
||||
handleError(rw, fmt.Sprintf("Failed to build logout URL: %v", err), http.StatusInternalServerError, t.logger)
|
||||
return
|
||||
@@ -414,6 +422,10 @@ func BuildLogoutURL(endSessionURL, idToken, postLogoutRedirectURI string) (strin
|
||||
return "", fmt.Errorf("failed to parse end session URL: %w", err)
|
||||
}
|
||||
|
||||
if postLogoutRedirectURI == "" {
|
||||
postLogoutRedirectURI = "/"
|
||||
}
|
||||
|
||||
q := u.Query()
|
||||
q.Set("id_token_hint", idToken)
|
||||
if postLogoutRedirectURI != "" {
|
||||
|
||||
@@ -772,8 +772,15 @@ func (t *TraefikOidc) extractGroupsAndRoles(idToken string) ([]string, []string,
|
||||
|
||||
// buildFullURL constructs a full URL from scheme, host and path
|
||||
func buildFullURL(scheme, host, path string) string {
|
||||
// If the path is already a full URL, return it as-is
|
||||
if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") {
|
||||
return path
|
||||
}
|
||||
|
||||
// Ensure the path starts with a forward slash
|
||||
if !strings.HasPrefix(path, "/") {
|
||||
path = "/" + path
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s://%s%s", scheme, host, path)
|
||||
}
|
||||
|
||||
+3
-3
@@ -863,7 +863,7 @@ func TestHandleLogout(t *testing.T) {
|
||||
},
|
||||
endSessionURL: "https://provider/end-session",
|
||||
expectedStatus: http.StatusFound,
|
||||
expectedURL: "https://provider/end-session?id_token_hint=test.id.token&post_logout_redirect_uri=http%3A%2F%2Fexample.com%2F",
|
||||
expectedURL: "https://provider/end-session?id_token_hint=test.id.token&post_logout_redirect_uri=http%3A%2F%2Fexample.com",
|
||||
host: "test-host",
|
||||
},
|
||||
{
|
||||
@@ -876,14 +876,14 @@ func TestHandleLogout(t *testing.T) {
|
||||
},
|
||||
endSessionURL: "",
|
||||
expectedStatus: http.StatusFound,
|
||||
expectedURL: "http://example.com/",
|
||||
expectedURL: "http://example.com",
|
||||
host: "test-host",
|
||||
},
|
||||
{
|
||||
name: "Logout with empty session",
|
||||
setupSession: func(session *sessions.Session) {},
|
||||
expectedStatus: http.StatusFound,
|
||||
expectedURL: "http://example.com/",
|
||||
expectedURL: "http://example.com",
|
||||
host: "test-host",
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user