@@ -42,13 +42,23 @@ type OauthProxy struct {
4242 SignInMessage string
4343 HtpasswdFile * HtpasswdFile
4444 DisplayHtpasswdForm bool
45- serveMux * http.ServeMux
45+ serveMux http.Handler
4646 PassBasicAuth bool
4747 skipAuthRegex []string
4848 compiledRegex []* regexp.Regexp
4949 templates * template.Template
5050}
5151
52+ type UpstreamProxy struct {
53+ upstream string
54+ handler http.Handler
55+ }
56+
57+ func (u * UpstreamProxy ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
58+ w .Header ().Set ("GAP-Upstream-Address" , u .upstream )
59+ u .handler .ServeHTTP (w , r )
60+ }
61+
5262func NewReverseProxy (target * url.URL ) (proxy * httputil.ReverseProxy ) {
5363 return httputil .NewSingleHostReverseProxy (target )
5464}
@@ -85,7 +95,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
8595 } else {
8696 setProxyDirector (proxy )
8797 }
88- serveMux .Handle (path , proxy )
98+ serveMux .Handle (path , & UpstreamProxy { u . Host , proxy } )
8999 }
90100 for _ , u := range opts .CompiledRegex {
91101 log .Printf ("compiled skip-auth-regex => %q" , u )
@@ -338,7 +348,7 @@ func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (st
338348 }
339349 // check auth
340350 if p .HtpasswdFile .Validate (user , passwd ) {
341- log .Printf ("authenticated %s via manual sign in " , user )
351+ log .Printf ("authenticated %q via HtpasswdFile " , user )
342352 return user , true
343353 }
344354 return "" , false
@@ -366,7 +376,6 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
366376 if req .Header .Get ("X-Real-IP" ) != "" {
367377 remoteAddr += fmt .Sprintf (" (%q)" , req .Header .Get ("X-Real-IP" ))
368378 }
369- log .Printf ("%s %s %s" , remoteAddr , req .Method , req .URL .RequestURI ())
370379
371380 var ok bool
372381 var user string
@@ -461,7 +470,6 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
461470 }
462471
463472 if ! ok {
464- log .Printf ("%s - invalid cookie session" , remoteAddr )
465473 p .SignInPage (rw , req , 403 )
466474 return
467475 }
@@ -472,6 +480,11 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
472480 req .Header ["X-Forwarded-User" ] = []string {user }
473481 req .Header ["X-Forwarded-Email" ] = []string {email }
474482 }
483+ if email == "" {
484+ rw .Header ().Set ("GAP-Auth" , user )
485+ } else {
486+ rw .Header ().Set ("GAP-Auth" , email )
487+ }
475488
476489 p .serveMux .ServeHTTP (rw , req )
477490}
@@ -493,7 +506,7 @@ func (p *OauthProxy) CheckBasicAuth(req *http.Request) (string, bool) {
493506 return "" , false
494507 }
495508 if p .HtpasswdFile .Validate (pair [0 ], pair [1 ]) {
496- log .Printf ("authenticated %s via basic auth" , pair [0 ])
509+ log .Printf ("authenticated %q via basic auth" , pair [0 ])
497510 return pair [0 ], true
498511 }
499512 return "" , false
0 commit comments