working commit

This commit is contained in:
2026-02-06 19:15:12 +02:00
parent fe91517e3f
commit f76881a765
14 changed files with 478 additions and 20 deletions
+46
View File
@@ -0,0 +1,46 @@
package handler
import (
//"encoding/base64"
//"fmt"
//"strings"
"mstore/app/router"
"mstore/pkg/auxhttp"
)
const (
authTag = "authpass"
userTag = "username"
)
func (hand *Handler) AuthMiddleware(next router.Handler) router.Handler {
var handlerFunc router.HandlerFunc
handlerFunc = func(rctx *router.Context) {
authSuccessful, authError := hand.CheckAccess(rctx)
if authSuccessful && authError == nil {
rctx.SetBool(authTag, true)
}
if authError != nil {
hand.logg.Errorf("Authorization middleware error: %v", authError)
}
next.ServeHTTP(rctx)
}
return handlerFunc
}
func (hand *Handler) CheckAccess(rctx *router.Context) (bool, error) {
var err error
var res bool
authHeader := rctx.GetHeader("Authorization")
hand.logg.Debugf("Authorization header is %s", authHeader)
username, password, err := auxhttp.ParseBasicAuth(authHeader)
hand.logg.Debugf("Authorization username is %s:%s", username, password)
res = true
return res, err
}