mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +00:00
Improve api auth http error messages
This commit is contained in:
parent
8d091f7f7a
commit
46b151ddfe
1 changed files with 5 additions and 5 deletions
|
@ -81,20 +81,20 @@ func authMiddleware(next http.Handler) http.Handler {
|
|||
// get auth decision
|
||||
grantAccess, err := authenticator(server, r)
|
||||
if err != nil {
|
||||
log.Errorf("api: authenticator failed: %s", err)
|
||||
http.Error(w, "", http.StatusInternalServerError)
|
||||
log.Warningf("api: authenticator failed: %s", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
}
|
||||
if !grantAccess {
|
||||
log.Warningf("api: denying api access to %s", r.RemoteAddr)
|
||||
http.Error(w, "", http.StatusForbidden)
|
||||
http.Error(w, "Forbidden", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
// write new cookie
|
||||
token, err := random.Bytes(32) // 256 bit
|
||||
if err != nil {
|
||||
log.Errorf("api: failed to generate random token: %s", err)
|
||||
http.Error(w, "", http.StatusInternalServerError)
|
||||
log.Warningf("api: failed to generate random token: %s", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
}
|
||||
tokenString := base64.RawURLEncoding.EncodeToString(token)
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
|
|
Loading…
Add table
Reference in a new issue