@@ -13,6 +13,7 @@ import (
1313 "net/http/httputil"
1414 "net/url"
1515 "regexp"
16+ "strconv"
1617 "strings"
1718 "time"
1819
@@ -78,31 +79,32 @@ type OAuthProxy struct {
7879 AuthOnlyPath string
7980 UserInfoPath string
8081
81− redirectURL *url.URL // the url to receive requests at
82− whitelistDomains []string
83− provider providers.Provider
84− sessionStore sessionsapi.SessionStore
85− ProxyPrefix string
86− SignInMessage string
87− HtpasswdFile *HtpasswdFile
88− DisplayHtpasswdForm bool
89− serveMux http.Handler
90− SetXAuthRequest bool
91− PassBasicAuth bool
92− SkipProviderButton bool
93− PassUserHeaders bool
94− BasicAuthPassword string
95− PassAccessToken bool
96− SetAuthorization bool
97− PassAuthorization bool
98− skipAuthRegex []string
99− skipAuthPreflight bool
100− skipJwtBearerTokens bool
101− jwtBearerVerifiers []*oidc.IDTokenVerifier
102− compiledRegex []*regexp.Regexp
103− templates *template.Template
104− Banner string
105− Footer string
82+ redirectURL *url.URL // the url to receive requests at
83+ whitelistDomains []string
84+ provider providers.Provider
85+ providerNameOverride string
86+ sessionStore sessionsapi.SessionStore
87+ ProxyPrefix string
88+ SignInMessage string
89+ HtpasswdFile *HtpasswdFile
90+ DisplayHtpasswdForm bool
91+ serveMux http.Handler
92+ SetXAuthRequest bool
93+ PassBasicAuth bool
94+ SkipProviderButton bool
95+ PassUserHeaders bool
96+ BasicAuthPassword string
97+ PassAccessToken bool
98+ SetAuthorization bool
99+ PassAuthorization bool
100+ skipAuthRegex []string
101+ skipAuthPreflight bool
102+ skipJwtBearerTokens bool
103+ jwtBearerVerifiers []*oidc.IDTokenVerifier
104+ compiledRegex []*regexp.Regexp
105+ templates *template.Template
106+ Banner string
107+ Footer string
106108}
107109
108110// UpstreamProxy represents an upstream server to proxy to
@@ -203,12 +205,23 @@ func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
203205 }
204206 for _, u := range opts.proxyURLs {
205207 path := u.Path
208+ host := u.Host
206209 switch u.Scheme {
207210 case httpScheme, httpsScheme:
208211 logger.Printf("mapping path %q => upstream %q", path, u)
209212 proxy := NewWebSocketOrRestReverseProxy(u, opts, auth)
210213 serveMux.Handle(path, proxy)
214+ case "static":
215+ responseCode, err := strconv.Atoi(host)
216+ if err != nil {
217+ logger.Printf("unable to convert %q to int, use default \"200\"", host)
218+ responseCode = 200
219+ }
211220
221+ serveMux.HandleFunc(path, func(rw http.ResponseWriter, req *http.Request) {
222+ rw.WriteHeader(responseCode)
223+ fmt.Fprintf(rw, "Authenticated")
224+ })
212225 case "file":
213226 if u.Fragment != "" {
214227 path = u.Fragment
@@ -270,28 +283,29 @@ func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
270283 AuthOnlyPath: fmt.Sprintf("%s/auth", opts.ProxyPrefix),
271284 UserInfoPath: fmt.Sprintf("%s/userinfo", opts.ProxyPrefix),
272285
273− ProxyPrefix: opts.ProxyPrefix,
274− provider: opts.provider,
275− sessionStore: opts.sessionStore,
276− serveMux: serveMux,
277− redirectURL: redirectURL,
278− whitelistDomains: opts.WhitelistDomains,
279− skipAuthRegex: opts.SkipAuthRegex,
280− skipAuthPreflight: opts.SkipAuthPreflight,
281− skipJwtBearerTokens: opts.SkipJwtBearerTokens,
282− jwtBearerVerifiers: opts.jwtBearerVerifiers,
283− compiledRegex: opts.CompiledRegex,
284− SetXAuthRequest: opts.SetXAuthRequest,
285− PassBasicAuth: opts.PassBasicAuth,
286− PassUserHeaders: opts.PassUserHeaders,
287− BasicAuthPassword: opts.BasicAuthPassword,
288− PassAccessToken: opts.PassAccessToken,
289− SetAuthorization: opts.SetAuthorization,
290− PassAuthorization: opts.PassAuthorization,
291− SkipProviderButton: opts.SkipProviderButton,
292− templates: loadTemplates(opts.CustomTemplatesDir),
293− Banner: opts.Banner,
294− Footer: opts.Footer,
286+ ProxyPrefix: opts.ProxyPrefix,
287+ provider: opts.provider,
288+ providerNameOverride: opts.ProviderName,
289+ sessionStore: opts.sessionStore,
290+ serveMux: serveMux,
291+ redirectURL: redirectURL,
292+ whitelistDomains: opts.WhitelistDomains,
293+ skipAuthRegex: opts.SkipAuthRegex,
294+ skipAuthPreflight: opts.SkipAuthPreflight,
295+ skipJwtBearerTokens: opts.SkipJwtBearerTokens,
296+ jwtBearerVerifiers: opts.jwtBearerVerifiers,
297+ compiledRegex: opts.CompiledRegex,
298+ SetXAuthRequest: opts.SetXAuthRequest,
299+ PassBasicAuth: opts.PassBasicAuth,
300+ PassUserHeaders: opts.PassUserHeaders,
301+ BasicAuthPassword: opts.BasicAuthPassword,
302+ PassAccessToken: opts.PassAccessToken,
303+ SetAuthorization: opts.SetAuthorization,
304+ PassAuthorization: opts.PassAuthorization,
305+ SkipProviderButton: opts.SkipProviderButton,
306+ templates: loadTemplates(opts.CustomTemplatesDir),
307+ Banner: opts.Banner,
308+ Footer: opts.Footer,
295309 }
296310}
297311
@@ -453,6 +467,9 @@ func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
453467 ProxyPrefix: p.ProxyPrefix,
454468 Footer: template.HTML(p.Footer),
455469 }
470+ if p.providerNameOverride != "" {
471+ t.ProviderName = p.providerNameOverride
472+ }
456473 p.templates.ExecuteTemplate(rw, "sign_in.html", t)
457474}
458475
@@ -662,8 +679,14 @@ func (p *OAuthProxy) UserInfo(rw http.ResponseWriter, req *http.Request) {
662679
663680// SignOut sends a response to clear the authentication cookie
664681func (p *OAuthProxy) SignOut(rw http.ResponseWriter, req *http.Request) {
682+ redirect, err := p.GetRedirect(req)
683+ if err != nil {
684+ logger.Printf("Error obtaining redirect: %s", err.Error())
685+ p.ErrorPage(rw, 500, "Internal Error", err.Error())
686+ return
687+ }
665688 p.ClearSessionCookie(rw, req)
666− http.Redirect(rw, req, "/", 302)
689+ http.Redirect(rw, req, redirect, 302)
667690}
668691
669692// OAuthStart starts the OAuth2 authentication flow