@@ -19,12 +19,6 @@ import (
1919 "github.com/bitly/oauth2_proxy/providers"
2020)
2121
22−const robotsPath = "/robots.txt"
23−const pingPath = "/ping"
24−const signInPath = "/oauth2/sign_in"
25−const oauthStartPath = "/oauth2/start"
26−const oauthCallbackPath = "/oauth2/callback"
27−
2822type OauthProxy struct {
2923 CookieSeed string
3024 CookieKey string
@@ -35,6 +29,12 @@ type OauthProxy struct {
3529 CookieRefresh time.Duration
3630 Validator func(string) bool
3731
32+ RobotsPath string
33+ PingPath string
34+ SignInPath string
35+ OauthStartPath string
36+ OauthCallbackPath string
37+
3838 redirectUrl *url.URL // the url to receive requests at
3939 provider providers.Provider
4040 oauthLoginUrl *url.URL // to redirect the user to
@@ -42,6 +42,7 @@ type OauthProxy struct {
4242 oauthScope string
4343 clientID string
4444 clientSecret string
45+ ProxyPrefix string
4546 SignInMessage string
4647 HtpasswdFile *HtpasswdFile
4748 DisplayHtpasswdForm bool
@@ -106,7 +107,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
106107 }
107108
108109 redirectUrl := opts.redirectUrl
109− redirectUrl.Path = oauthCallbackPath
110+ redirectUrl.Path = fmt.Sprintf("%s/callback", opts.ProxyPrefix)
110111
111112 log.Printf("OauthProxy configured for %s", opts.ClientID)
112113 domain := opts.CookieDomain
@@ -131,7 +132,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
131132 }
132133
133134 return &OauthProxy{
134− CookieKey: "_oauthproxy",
135+ CookieKey: opts.CookieKey,
135136 CookieSeed: opts.CookieSecret,
136137 CookieDomain: opts.CookieDomain,
137138 CookieSecure: opts.CookieSecure,
@@ -140,8 +141,15 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
140141 CookieRefresh: opts.CookieRefresh,
141142 Validator: validator,
142143
144+ RobotsPath: "/robots.txt",
145+ PingPath: "/ping",
146+ SignInPath: fmt.Sprintf("%s/sign_in", opts.ProxyPrefix),
147+ OauthStartPath: fmt.Sprintf("%s/start", opts.ProxyPrefix),
148+ OauthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix),
149+
143150 clientID: opts.ClientID,
144151 clientSecret: opts.ClientSecret,
152+ ProxyPrefix: opts.ProxyPrefix,
145153 oauthScope: opts.provider.Data().Scope,
146154 provider: opts.provider,
147155 oauthLoginUrl: opts.provider.Data().LoginUrl,
@@ -300,7 +308,7 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
300308 rw.WriteHeader(code)
301309
302310 redirect_url := req.URL.RequestURI()
303− if redirect_url == signInPath {
311+ if redirect_url == p.SignInPath {
304312 redirect_url = "/"
305313 }
306314
@@ -310,12 +318,14 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
310318 CustomLogin bool
311319 Redirect string
312320 Version string
321+ ProxyPrefix string
313322 }{
314323 ProviderName: p.provider.Data().ProviderName,
315324 SignInMessage: p.SignInMessage,
316325 CustomLogin: p.displayCustomLoginForm(),
317326 Redirect: redirect_url,
318327 Version: VERSION,
328+ ProxyPrefix: p.ProxyPrefix,
319329 }
320330 p.templates.ExecuteTemplate(rw, "sign_in.html", t)
321331}
@@ -365,12 +375,12 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
365375 var email string
366376 var access_token string
367377
368− if req.URL.Path == robotsPath {
378+ if req.URL.Path == p.RobotsPath {
369379 p.RobotsTxt(rw)
370380 return
371381 }
372382
373− if req.URL.Path == pingPath {
383+ if req.URL.Path == p.PingPath {
374384 p.PingPage(rw)
375385 return
376386 }
@@ -384,7 +394,7 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
384394
385395 }
386396
387− if req.URL.Path == signInPath {
397+ if req.URL.Path == p.SignInPath {
388398 redirect, err := p.GetRedirect(req)
389399 if err != nil {
390400 p.ErrorPage(rw, 500, "Internal Error", err.Error())
@@ -400,7 +410,7 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
400410 }
401411 return
402412 }
403− if req.URL.Path == oauthStartPath {
413+ if req.URL.Path == p.OauthStartPath {
404414 redirect, err := p.GetRedirect(req)
405415 if err != nil {
406416 p.ErrorPage(rw, 500, "Internal Error", err.Error())
@@ -409,7 +419,7 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
409419 http.Redirect(rw, req, p.GetLoginURL(req.Host, redirect), 302)
410420 return
411421 }
412− if req.URL.Path == oauthCallbackPath {
422+ if req.URL.Path == p.OauthCallbackPath {
413423 // finish the oauth cycle
414424 err := req.ParseForm()
415425 if err != nil {