@@ -128,6 +128,7 @@ func NewOAuthProxy(opts *options.Options, validator func(string) bool) (*OAuthPr
128128 ProxyPrefix: opts.ProxyPrefix,
129129 Footer: opts.Templates.Footer,
130130 Version: VERSION,
131+ Debug: opts.Templates.Debug,
131132 }
132133
133134 upstreamProxy, err := upstream.NewProxy(opts.UpstreamServers, opts.GetSignatureData(), errorPage.ProxyErrorHandler)
@@ -523,7 +524,7 @@ func (p *OAuthProxy) RobotsTxt(rw http.ResponseWriter, req *http.Request) {
523524}
524525
525526// ErrorPage writes an error response
526−func (p *OAuthProxy) ErrorPage(rw http.ResponseWriter, req *http.Request, code int, appError string) {
527+func (p *OAuthProxy) ErrorPage(rw http.ResponseWriter, req *http.Request, code int, appError string, messages ...interface{}) {
527528 redirectURL, err := p.getAppRedirect(req)
528529 if err != nil {
529530 logger.Errorf("Error obtaining redirect: %v", err)
@@ -532,7 +533,7 @@ func (p *OAuthProxy) ErrorPage(rw http.ResponseWriter, req *http.Request, code i
532533 redirectURL = "/"
533534 }
534535
535− p.errorPage.Render(rw, code, redirectURL, appError)
536+ p.errorPage.Render(rw, code, redirectURL, appError, messages...)
536537}
537538
538539// IsAllowedRequest is used to check if auth should be skipped for this request
@@ -751,28 +752,30 @@ func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
751752 errorString := req.Form.Get("error")
752753 if errorString != "" {
753754 logger.Errorf("Error while parsing OAuth2 callback: %s", errorString)
754− p.ErrorPage(rw, req, http.StatusForbidden, errorString)
755+ message := fmt.Sprintf("Login Failed: The upstream identity provider returned an error: %s", errorString)
756+ // Set the debug message and override the non debug message to be the same for this case
757+ p.ErrorPage(rw, req, http.StatusForbidden, message, message)
755758 return
756759 }
757760
758761 session, err := p.redeemCode(req)
759762 if err != nil {
760763 logger.Errorf("Error redeeming code during OAuth2 callback: %v", err)
761− p.ErrorPage(rw, req, http.StatusInternalServerError, "Internal Error")
764+ p.ErrorPage(rw, req, http.StatusInternalServerError, err.Error())
762765 return
763766 }
764767
765768 err = p.enrichSessionState(req.Context(), session)
766769 if err != nil {
767770 logger.Errorf("Error creating session during OAuth2 callback: %v", err)
768− p.ErrorPage(rw, req, http.StatusInternalServerError, "Internal Error")
771+ p.ErrorPage(rw, req, http.StatusInternalServerError, err.Error())
769772 return
770773 }
771774
772775 state := strings.SplitN(req.Form.Get("state"), ":", 2)
773776 if len(state) != 2 {
774777 logger.Error("Error while parsing OAuth2 state: invalid length")
775− p.ErrorPage(rw, req, http.StatusInternalServerError, "Invalid State")
778+ p.ErrorPage(rw, req, http.StatusInternalServerError, "State paremeter did not have expected length", "Login Failed: Invalid State after login.")
776779 return
777780 }
778781 nonce := state[0]
@@ -780,13 +783,13 @@ func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
780783 c, err := req.Cookie(p.CSRFCookieName)
781784 if err != nil {
782785 logger.PrintAuthf(session.Email, req, logger.AuthFailure, "Invalid authentication via OAuth2: unable to obtain CSRF cookie")
783− p.ErrorPage(rw, req, http.StatusForbidden, err.Error())
786+ p.ErrorPage(rw, req, http.StatusForbidden, err.Error(), "Login Failed: Unable to find a valid CSRF token. Please try again.")
784787 return
785788 }
786789 p.ClearCSRFCookie(rw, req)
787790 if c.Value != nonce {
788791 logger.PrintAuthf(session.Email, req, logger.AuthFailure, "Invalid authentication via OAuth2: CSRF token mismatch, potential attack")
789− p.ErrorPage(rw, req, http.StatusForbidden, "CSRF Failed")
792+ p.ErrorPage(rw, req, http.StatusForbidden, "CSRF token mismatch, potential attack", "Login Failed: Unable to find a valid CSRF token. Please try again.")
790793 return
791794 }
792795
@@ -810,7 +813,7 @@ func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
810813 http.Redirect(rw, req, redirect, http.StatusFound)
811814 } else {
812815 logger.PrintAuthf(session.Email, req, logger.AuthFailure, "Invalid authentication via OAuth2: unauthorized")
813− p.ErrorPage(rw, req, http.StatusForbidden, "Invalid Account")
816+ p.ErrorPage(rw, req, http.StatusForbidden, "Invalid session: unauthorized")
814817 }
815818}
816819
@@ -892,12 +895,12 @@ func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
892895 }
893896
894897 case ErrAccessDenied:
895− p.ErrorPage(rw, req, http.StatusUnauthorized, "Unauthorized")
898+ p.ErrorPage(rw, req, http.StatusForbidden, "The session failed authorization checks")
896899
897900 default:
898901 // unknown error
899902 logger.Errorf("Unexpected internal error: %v", err)
900− p.ErrorPage(rw, req, http.StatusInternalServerError, "Internal Error")
903+ p.ErrorPage(rw, req, http.StatusInternalServerError, err.Error())
901904 }
902905}
903906