Skip to content
Snippets Groups Projects
Unverified Commit d95cb7b4 authored by Rohith Jayawardene's avatar Rohith Jayawardene Committed by GitHub
Browse files

Fix Logout Redirection (#375)

- a minor fix to the logout redirection, defaulting to the hostname if no redirect param is given
parent f415a8b9
No related branches found
No related tags found
No related merge requests found
#### **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** #### **2.2.0**
FEATURES: FEATURES:
......
...@@ -27,7 +27,7 @@ import ( ...@@ -27,7 +27,7 @@ import (
) )
var ( var (
release = "v2.2.0" release = "v2.2.1"
gitsha = "no gitsha provided" gitsha = "no gitsha provided"
compiled = "0" compiled = "0"
version = "" version = ""
......
...@@ -327,10 +327,12 @@ func (r *oauthProxy) logoutHandler(w http.ResponseWriter, req *http.Request) { ...@@ -327,10 +327,12 @@ func (r *oauthProxy) logoutHandler(w http.ResponseWriter, req *http.Request) {
// @check if we should redirect to the provider // @check if we should redirect to the provider
if r.config.EnableLogoutRedirect { if r.config.EnableLogoutRedirect {
sendTo := fmt.Sprintf("%s/protocol/openid-connect/logout", strings.TrimSuffix(r.config.DiscoveryURL, "/.well-known/openid-configuration")) sendTo := fmt.Sprintf("%s/protocol/openid-connect/logout", strings.TrimSuffix(r.config.DiscoveryURL, "/.well-known/openid-configuration"))
if redirectURL != "" { // @step: if not redirect uri is set we default back to the hostname
sendTo = fmt.Sprintf("%s?redirect_uri=%s", sendTo, url.QueryEscape(redirectURL)) 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 return
} }
......
...@@ -62,6 +62,21 @@ var ( ...@@ -62,6 +62,21 @@ var (
symbolsFilter = regexp.MustCompilePOSIX("[_$><\\[\\].,\\+-/'%^&*()!\\\\]+") 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 // readConfigFile reads and parses the configuration file
func readConfigFile(filename string, config *Config) error { func readConfigFile(filename string, config *Config) error {
content, err := ioutil.ReadFile(filename) content, err := ioutil.ReadFile(filename)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment