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

Commit

Permalink
Fix Logout Redirection (#375)
Browse files Browse the repository at this point in the history
- a minor fix to the logout redirection, defaulting to the hostname if no redirect param is given
  • Loading branch information
gambol99 authored May 31, 2018
1 parent f415a8b commit d95cb7b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
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

0 comments on commit d95cb7b

Please sign in to comment.