Fix sign in URL

This commit is contained in:
Manuel de Brito Fontes 2017-08-20 20:39:58 -03:00
parent 7010627c4c
commit b2be9f0e04
2 changed files with 18 additions and 1 deletions

View file

@ -22,6 +22,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net" "net"
"net/url"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
@ -149,6 +150,7 @@ var (
"serverConfig": func(all config.TemplateConfig, server *ingress.Server) interface{} { "serverConfig": func(all config.TemplateConfig, server *ingress.Server) interface{} {
return struct{ First, Second interface{} }{all, server} return struct{ First, Second interface{} }{all, server}
}, },
"buildAuthSignURL": buildAuthSignURL,
} }
) )
@ -502,3 +504,18 @@ func buildNextUpstream(input interface{}) string {
return strings.Join(nextUpstreamCodes, " ") return strings.Join(nextUpstreamCodes, " ")
} }
func buildAuthSignURL(input interface{}) string {
s, ok := input.(string)
if !ok {
glog.Errorf("expected an string type but %T was returned", input)
}
u, _ := url.Parse(s)
q := u.Query()
if len(q) == 0 {
return fmt.Sprintf("%v?rd=$request_uri", s)
}
return fmt.Sprintf("%v&rd=$request_uri", s)
}

View file

@ -585,7 +585,7 @@ stream {
{{ end }} {{ end }}
{{ if not (empty $location.ExternalAuth.SigninURL) }} {{ if not (empty $location.ExternalAuth.SigninURL) }}
error_page 401 = {{ $location.ExternalAuth.SigninURL }}?rd=$request_uri; error_page 401 = {{ buildAuthSignURL $location.ExternalAuth.SigninURL }};
{{ end }} {{ end }}
{{/* if the location contains a rate limit annotation, create one */}} {{/* if the location contains a rate limit annotation, create one */}}