Initial
This commit is contained in:
commit
97dc0a3570
78 files changed
+7054
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"goAuth/internal/csrf"
|
||||
)
|
||||
|
||||
func (h *Handler) superuser(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
u := userFromRequest(r)
|
||||
if u == nil || !u.IsAdmin {
|
||||
writeError(w, http.StatusForbidden, "forbidden")
|
||||
return
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) refreshCsrf(w http.ResponseWriter) {
|
||||
if _, err := csrf.UpdateCsrf(w, h.cfg.Cookies.CsrfName, h.cfg.Cookies.Secure); err != nil {
|
||||
slog.Error("refresh csrf", slog.String("op", "rest.refreshCsrf"), slog.Any("error", err))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user