mirror of
https://github.com/safing/portbase
synced 2025-09-04 19:50:18 +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
|
// 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{
|
||||||
|
|
Loading…
Add table
Reference in a new issue