snapshot of https://github.com/livekit/livekit.git @ 08c5433449c106943231037d0b892895f6e92d3b (2026-09-15)
This commit is contained in:
31
pkg/service/basic_auth.go
Normal file
31
pkg/service/basic_auth.go
Normal file
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user