Skip to content

Commit a0e4661

Browse files
authored
Merge pull request #1189 from aledbf/fix-auth-rd
Fix sign in URL redirect parameter
2 parents 4c1111b + b2be9f0 commit a0e4661

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

controllers/nginx/pkg/template/template.go

+17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"encoding/json"
2323
"fmt"
2424
"net"
25+
"net/url"
2526
"os"
2627
"os/exec"
2728
"strings"
@@ -149,6 +150,7 @@ var (
149150
"serverConfig": func(all config.TemplateConfig, server *ingress.Server) interface{} {
150151
return struct{ First, Second interface{} }{all, server}
151152
},
153+
"buildAuthSignURL": buildAuthSignURL,
152154
}
153155
)
154156

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

503505
return strings.Join(nextUpstreamCodes, " ")
504506
}
507+
508+
func buildAuthSignURL(input interface{}) string {
509+
s, ok := input.(string)
510+
if !ok {
511+
glog.Errorf("expected an string type but %T was returned", input)
512+
}
513+
514+
u, _ := url.Parse(s)
515+
q := u.Query()
516+
if len(q) == 0 {
517+
return fmt.Sprintf("%v?rd=$request_uri", s)
518+
}
519+
520+
return fmt.Sprintf("%v&rd=$request_uri", s)
521+
}

controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ stream {
585585
{{ end }}
586586

587587
{{ if not (empty $location.ExternalAuth.SigninURL) }}
588-
error_page 401 = {{ $location.ExternalAuth.SigninURL }}?rd=$request_uri;
588+
error_page 401 = {{ buildAuthSignURL $location.ExternalAuth.SigninURL }};
589589
{{ end }}
590590

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

0 commit comments

Comments
 (0)