Improve api auth http error messages

This commit is contained in:
Daniel 2019-07-31 22:29:39 +02:00
parent 8d091f7f7a
commit 46b151ddfe

View file

@ -81,20 +81,20 @@ func authMiddleware(next http.Handler) http.Handler {
// get auth decision // get auth decision
grantAccess, err := authenticator(server, r) grantAccess, err := authenticator(server, r)
if err != nil { if err != nil {
log.Errorf("api: authenticator failed: %s", err) log.Warningf("api: authenticator failed: %s", err)
http.Error(w, "", http.StatusInternalServerError) http.Error(w, "Internal Server Error", http.StatusInternalServerError)
} }
if !grantAccess { if !grantAccess {
log.Warningf("api: denying api access to %s", r.RemoteAddr) log.Warningf("api: denying api access to %s", r.RemoteAddr)
http.Error(w, "", http.StatusForbidden) http.Error(w, "Forbidden", http.StatusForbidden)
return return
} }
// write new cookie // write new cookie
token, err := random.Bytes(32) // 256 bit token, err := random.Bytes(32) // 256 bit
if err != nil { if err != nil {
log.Errorf("api: failed to generate random token: %s", err) log.Warningf("api: failed to generate random token: %s", err)
http.Error(w, "", http.StatusInternalServerError) http.Error(w, "Internal Server Error", http.StatusInternalServerError)
} }
tokenString := base64.RawURLEncoding.EncodeToString(token) tokenString := base64.RawURLEncoding.EncodeToString(token)
http.SetCookie(w, &http.Cookie{ http.SetCookie(w, &http.Cookie{