Files
upstream-livekit/pkg/service/basic_auth.go
upstream-mirror 78704103fc
Some checks failed
Release to Docker / docker (push) Failing after 2s
Release Test Server to Docker / docker (push) Failing after 3s
Test / test (push) Failing after 16s
snapshot of https://github.com/livekit/livekit.git @ 08c5433449c106943231037d0b892895f6e92d3b (2026-09-15)
2026-09-15 16:14:22 +05:00

31 lines
649 B
Go

package service
import (
"net/http"
)
func GenBasicAuthMiddleware(username string, password string) (func(http.ResponseWriter, *http.Request, http.HandlerFunc) ) {
return func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
given_username, given_password, ok := r.BasicAuth()
unauthorized := func() {
rw.Header().Set("WWW-Authenticate", "Basic realm=\"Protected Area\"")
rw.WriteHeader(http.StatusUnauthorized)
}
if !ok {
unauthorized()
return
}
if given_username != username {
unauthorized()
return
}
if given_password != password {
unauthorized()
return
}
next(rw, r)
}
}