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)
}
// 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) {
p.ClearSessionCookie(rw, req)
rw.WriteHeader(code)
redirecURL := req.URL.RequestURI()
if req.Header.Get("X-Auth-Request-Redirect") != "" {
@ -402,6 +401,14 @@ func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
redirecURL = "/"
}
if p.SkipProviderButton {
req.Form.Set("rd", redirecURL)
p.OAuthStart(rw, req)
return
}
rw.WriteHeader(code)
t := struct {
ProviderName string
SignInMessage string
@ -543,11 +550,7 @@ func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
p.SaveSession(rw, req, session)
http.Redirect(rw, req, redirect, 302)
} else {
if p.SkipProviderButton {
p.OAuthStart(rw, req)
} else {
p.SignInPage(rw, req, http.StatusOK)
}
p.SignInPage(rw, req, http.StatusOK)
}
}