Fix redirects on /sign_in when -skip-provider-button is set

Push the logic down a level: now the dispatch happens in SignInPage,
where the correct redirect URI is known.

Fixes #30, hopefully
This commit is contained in:
Benjamin Staffin 2019-05-08 20:44:22 -04:00
parent 0af18d6d7c
commit faf49ee4e3

View File

@ -389,10 +389,9 @@ func (p *OAuthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, m
p.templates.ExecuteTemplate(rw, "error.html", t) p.templates.ExecuteTemplate(rw, "error.html", t)
} }
// SignInPage writes the sing in template to the response // SignInPage writes the sign-in template to the response
func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) { func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) {
p.ClearSessionCookie(rw, req) p.ClearSessionCookie(rw, req)
rw.WriteHeader(code)
redirecURL := req.URL.RequestURI() redirecURL := req.URL.RequestURI()
if req.Header.Get("X-Auth-Request-Redirect") != "" { if req.Header.Get("X-Auth-Request-Redirect") != "" {
@ -402,6 +401,14 @@ func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
redirecURL = "/" redirecURL = "/"
} }
if p.SkipProviderButton {
req.Form.Set("rd", redirecURL)
p.OAuthStart(rw, req)
return
}
rw.WriteHeader(code)
t := struct { t := struct {
ProviderName string ProviderName string
SignInMessage string SignInMessage string
@ -542,14 +549,10 @@ func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
session := &sessionsapi.SessionState{User: user} session := &sessionsapi.SessionState{User: user}
p.SaveSession(rw, req, session) p.SaveSession(rw, req, session)
http.Redirect(rw, req, redirect, 302) http.Redirect(rw, req, redirect, 302)
} else {
if p.SkipProviderButton {
p.OAuthStart(rw, req)
} else { } else {
p.SignInPage(rw, req, http.StatusOK) p.SignInPage(rw, req, http.StatusOK)
} }
} }
}
// SignOut sends a response to clear the authentication cookie // SignOut sends a response to clear the authentication cookie
func (p *OAuthProxy) SignOut(rw http.ResponseWriter, req *http.Request) { func (p *OAuthProxy) SignOut(rw http.ResponseWriter, req *http.Request) {