Skip to content
This repository was archived by the owner on Dec 7, 2020. It is now read-only.

Fix Logout Redirection #375

Merged
merged 1 commit into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

#### **2.2.1**

FIX
- a minor fix to the logout handler, when logout redirection is enable if no redirect param is given we default to the hostname [#PR375](https://github.com/gambol99/keycloak-proxy/pull/375)

#### **2.2.0**

FEATURES:
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

var (
release = "v2.2.0"
release = "v2.2.1"
gitsha = "no gitsha provided"
compiled = "0"
version = ""
Expand Down
8 changes: 5 additions & 3 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,12 @@ func (r *oauthProxy) logoutHandler(w http.ResponseWriter, req *http.Request) {
// @check if we should redirect to the provider
if r.config.EnableLogoutRedirect {
sendTo := fmt.Sprintf("%s/protocol/openid-connect/logout", strings.TrimSuffix(r.config.DiscoveryURL, "/.well-known/openid-configuration"))
if redirectURL != "" {
sendTo = fmt.Sprintf("%s?redirect_uri=%s", sendTo, url.QueryEscape(redirectURL))
// @step: if not redirect uri is set we default back to the hostname
if redirectURL == "" {
redirectURL = getRequestHostURL(req)
}
r.redirectToURL(sendTo, w, req)

r.redirectToURL(fmt.Sprintf("%s?redirect_uri=%s", sendTo, url.QueryEscape(redirectURL)), w, req)

return
}
Expand Down
15 changes: 15 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ var (
symbolsFilter = regexp.MustCompilePOSIX("[_$><\\[\\].,\\+-/'%^&*()!\\\\]+")
)

// getRequestHostURL returns the hostname from the request
func getRequestHostURL(r *http.Request) string {
hostname := r.Host
if r.Header.Get("X-Forwarded-Host") != "" {
hostname = r.Header.Get("X-Forwarded-Host")
}

scheme := "http"
if r.TLS != nil {
scheme = "https"
}

return fmt.Sprintf("%s://%s", scheme, hostname)
}

// readConfigFile reads and parses the configuration file
func readConfigFile(filename string, config *Config) error {
content, err := ioutil.ReadFile(filename)
Expand Down