mirror of
https://github.com/Luzifer/nginx-sso.git
synced 2024-12-20 12:51:17 +00:00
Add support for K8s ingress-nginx "rd" URL parameter
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
b515730dcf
commit
2986da43bc
1 changed files with 16 additions and 6 deletions
16
redirect.go
16
redirect.go
|
@ -12,6 +12,7 @@ func getRedirectURL(r *http.Request, fallback string) (string, error) {
|
||||||
var (
|
var (
|
||||||
params url.Values
|
params url.Values
|
||||||
redirURL string
|
redirURL string
|
||||||
|
removeParam string
|
||||||
sessURL string
|
sessURL string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,9 +24,16 @@ func getRedirectURL(r *http.Request, fallback string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
case r.URL.Query().Get("rd") != "":
|
||||||
|
// We have a GET request with a "rd" query param (K8s ingress-nginx)
|
||||||
|
redirURL = r.URL.Query().Get("rd")
|
||||||
|
removeParam = "rd"
|
||||||
|
params = r.URL.Query()
|
||||||
|
|
||||||
case r.URL.Query().Get("go") != "":
|
case r.URL.Query().Get("go") != "":
|
||||||
// We have a GET request, use "go" query param
|
// We have a GET request, use "go" query param
|
||||||
redirURL = r.URL.Query().Get("go")
|
redirURL = r.URL.Query().Get("go")
|
||||||
|
removeParam = "go"
|
||||||
params = r.URL.Query()
|
params = r.URL.Query()
|
||||||
|
|
||||||
case r.FormValue("go") != "":
|
case r.FormValue("go") != "":
|
||||||
|
@ -42,13 +50,15 @@ func getRedirectURL(r *http.Request, fallback string) (string, error) {
|
||||||
return fallback, nil
|
return fallback, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the "go" parameter as it is a parameter for nginx-sso
|
// Remove the redirect parameter as it is a parameter for nginx-sso
|
||||||
params.Del("go")
|
if removeParam != "" {
|
||||||
|
params.Del(removeParam)
|
||||||
|
}
|
||||||
|
|
||||||
// Parse given URL to extract attached parameters
|
// Parse given URL to extract attached parameters
|
||||||
pURL, err := url.Parse(redirURL)
|
pURL, err := url.Parse(redirURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, "Unable to parse redirect URL")
|
return "", errors.Wrap(err, "parsing redirect URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transfer parameters from URL to params set
|
// Transfer parameters from URL to params set
|
||||||
|
|
Loading…
Reference in a new issue