aboutsummaryrefslogtreecommitdiff
path: root/pkg/ext/auth.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/ext/auth.go')
-rw-r--r--pkg/ext/auth.go22
1 files changed, 12 insertions, 10 deletions
diff --git a/pkg/ext/auth.go b/pkg/ext/auth.go
index 5c3070e..ef126ec 100644
--- a/pkg/ext/auth.go
+++ b/pkg/ext/auth.go
@@ -14,19 +14,20 @@ type authService interface {
ValidateToken(token []byte) (bool, error)
}
-func DisableAuthentication(next http.HandlerFunc) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
+func DisableAuthentication(next HandlerFunc) HandlerFunc {
+ return func(w http.ResponseWriter, r *Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, "disableAuthentication", true)
- next(w, r.WithContext(ctx))
+ r.Request = r.WithContext(ctx)
+ next(w, r)
}
}
func VerifyRespository(
config *serverconfig.ConfigurationRepository,
-) func(next http.HandlerFunc) http.HandlerFunc {
- return func(next http.HandlerFunc) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
+) func(next HandlerFunc) HandlerFunc {
+ return func(next HandlerFunc) HandlerFunc {
+ return func(w http.ResponseWriter, r *Request) {
name := r.PathValue("name")
if name != "" {
repo := config.GetByName(name)
@@ -41,9 +42,9 @@ func VerifyRespository(
}
}
-func Authenticate(auth authService) func(next http.HandlerFunc) http.HandlerFunc {
- return func(next http.HandlerFunc) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
+func Authenticate(auth authService) func(next HandlerFunc) HandlerFunc {
+ return func(next HandlerFunc) HandlerFunc {
+ return func(w http.ResponseWriter, r *Request) {
cookie, err := r.Cookie("auth")
if err != nil {
if !errors.Is(err, http.ErrNoCookie) {
@@ -70,9 +71,10 @@ func Authenticate(auth authService) func(next http.HandlerFunc) http.HandlerFunc
ctx := r.Context()
ctx = context.WithValue(ctx, "logged", valid)
+ r.Request = r.WithContext(ctx)
slog.Info("Validated token", "valid?", valid)
- next(w, r.WithContext(ctx))
+ next(w, r)
}
}
}