Skip to content

Commit

Permalink
Fix sign in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Aug 20, 2017
1 parent 7010627 commit b2be9f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions controllers/nginx/pkg/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"fmt"
"net"
"net/url"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -149,6 +150,7 @@ var (
"serverConfig": func(all config.TemplateConfig, server *ingress.Server) interface{} {
return struct{ First, Second interface{} }{all, server}
},
"buildAuthSignURL": buildAuthSignURL,
}
)

Expand Down Expand Up @@ -502,3 +504,18 @@ func buildNextUpstream(input interface{}) string {

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)
}
2 changes: 1 addition & 1 deletion controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ stream {
{{ end }}

{{ if not (empty $location.ExternalAuth.SigninURL) }}
error_page 401 = {{ $location.ExternalAuth.SigninURL }}?rd=$request_uri;
error_page 401 = {{ buildAuthSignURL $location.ExternalAuth.SigninURL }};
{{ end }}

{{/* if the location contains a rate limit annotation, create one */}}
Expand Down

0 comments on commit b2be9f0

Please sign in to comment.