@@ -364,7 +364,11 @@ func (p *OAuthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *s
364// RobotsTxt disallows scraping pages from the OAuthProxy
364// RobotsTxt disallows scraping pages from the OAuthProxy
365func (p *OAuthProxy) RobotsTxt(rw http.ResponseWriter) {
365func (p *OAuthProxy) RobotsTxt(rw http.ResponseWriter) {
366 rw.WriteHeader(http.StatusOK)
366 rw.WriteHeader(http.StatusOK)
367− fmt.Fprintf(rw, "User-agent: *\nDisallow: /")
367+ _, err := fmt.Fprintf(rw, "User-agent: *\nDisallow: /")
369+ logger.Printf("Error writing robots.txt: %s", err.Error())
370+ p.ErrorPage(rw, 500, "Internal Error", err.Error())
370// ErrorPage writes an error response
374// ErrorPage writes an error response
@@ -379,13 +383,22 @@ func (p *OAuthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, m
379 Message: message,
383 Message: message,
380 ProxyPrefix: p.ProxyPrefix,
384 ProxyPrefix: p.ProxyPrefix,
382− p.templates.ExecuteTemplate(rw, "error.html", t)
386+ err := p.templates.ExecuteTemplate(rw, "error.html", t)
388+ logger.Printf("Error rendering error.html template: %s", err.Error())
389+ http.Error(rw, "Internal Server Error", http.StatusInternalServerError)
385// SignInPage writes the sing in template to the response
393// SignInPage writes the sing in template to the response
386func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) {
394func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) {
387 prepareNoCache(rw)
395 prepareNoCache(rw)
388− p.ClearSessionCookie(rw, req)
396+ err := p.ClearSessionCookie(rw, req)
398+ logger.Printf("Error clearing session cookie: %s", err.Error())
399+ p.ErrorPage(rw, 500, "Internal Error", err.Error())
389 rw.WriteHeader(code)
402 rw.WriteHeader(code)
391 redirectURL, err := p.GetRedirect(req)
404 redirectURL, err := p.GetRedirect(req)
@@ -419,11 +432,15 @@ func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
419 if p.providerNameOverride != "" {
432 if p.providerNameOverride != "" {
420 t.ProviderName = p.providerNameOverride
433 t.ProviderName = p.providerNameOverride
422− p.templates.ExecuteTemplate(rw, "sign_in.html", t)
435+ err = p.templates.ExecuteTemplate(rw, "sign_in.html", t)
437+ logger.Printf("Error rendering sign_in.html template: %s", err.Error())
438+ p.ErrorPage(rw, 500, "Internal Error", err.Error())
425// ManualSignIn handles basic auth logins to the proxy
442// ManualSignIn handles basic auth logins to the proxy
426−func (p *OAuthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (string, bool) {
443+func (p *OAuthProxy) ManualSignIn(req *http.Request) (string, bool) {
427 if req.Method != "POST" || p.basicAuthValidator == nil {
444 if req.Method != "POST" || p.basicAuthValidator == nil {
428 return "", false
445 return "", false
@@ -632,10 +649,15 @@ func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
635− user, ok := p.ManualSignIn(rw, req)
652+ user, ok := p.ManualSignIn(req)
637 session := &sessionsapi.SessionState{User: user}
654 session := &sessionsapi.SessionState{User: user}
638− p.SaveSession(rw, req, session)
655+ err = p.SaveSession(rw, req, session)
657+ logger.Printf("Error saving session: %s", err.Error())
658+ p.ErrorPage(rw, 500, "Internal Error", err.Error())
639 http.Redirect(rw, req, redirect, http.StatusFound)
661 http.Redirect(rw, req, redirect, http.StatusFound)
641 if p.SkipProviderButton {
663 if p.SkipProviderButton {
@@ -663,7 +685,11 @@ func (p *OAuthProxy) UserInfo(rw http.ResponseWriter, req *http.Request) {
664 rw.Header().Set("Content-Type", "application/json")
686 rw.Header().Set("Content-Type", "application/json")
665 rw.WriteHeader(http.StatusOK)
687 rw.WriteHeader(http.StatusOK)
666− json.NewEncoder(rw).Encode(userInfo)
688+ err = json.NewEncoder(rw).Encode(userInfo)
690+ logger.Printf("Error encoding user info: %s", err.Error())
691+ p.ErrorPage(rw, 500, "Internal Error", err.Error())
669// SignOut sends a response to clear the authentication cookie
695// SignOut sends a response to clear the authentication cookie
@@ -674,7 +700,12 @@ func (p *OAuthProxy) SignOut(rw http.ResponseWriter, req *http.Request) {
674 p.ErrorPage(rw, 500, "Internal Error", err.Error())
700 p.ErrorPage(rw, 500, "Internal Error", err.Error())
677− p.ClearSessionCookie(rw, req)
703+ err = p.ClearSessionCookie(rw, req)
705+ logger.Printf("Error clearing session cookie: %s", err.Error())
706+ p.ErrorPage(rw, 500, "Internal Error", err.Error())
678 http.Redirect(rw, req, redirect, http.StatusFound)
709 http.Redirect(rw, req, redirect, http.StatusFound)
@@ -837,7 +868,10 @@ func (p *OAuthProxy) getAuthenticatedSession(rw http.ResponseWriter, req *http.R
837 if session != nil && session.Email != "" && !p.Validator(session.Email) {
868 if session != nil && session.Email != "" && !p.Validator(session.Email) {
838 logger.Printf(session.Email, req, logger.AuthFailure, "Invalid authentication via session: removing session %s", session)
869 logger.Printf(session.Email, req, logger.AuthFailure, "Invalid authentication via session: removing session %s", session)
839 // Invalid session, clear it
870 // Invalid session, clear it
840− p.ClearSessionCookie(rw, req)
871+ err := p.ClearSessionCookie(rw, req)
873+ logger.Printf("Error clearing session cookie: %s", err.Error())
841 return nil, ErrNeedsLogin
875 return nil, ErrNeedsLogin