mirror of
https://github.com/livekit/livekit.git
synced 2026-03-29 20:09:53 +00:00
* feat: add support for basic auth on prometheus * fix: properly name middleware generator * refactor: move all prometheus configs into common object * chore: add suggestions from review add back old config switch and print warning if it is used * fix: undo accidental change * fix: rebase/merge issue
31 lines
649 B
Go
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)
|
|
}
|
|
} |