support authentication for multiple domains

This commit is contained in:
Kegan Myers 2022-02-21 15:48:32 -06:00
parent aee714537e
commit 8b0a007e49

14
http.go
View file

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"
)
func init() {
@ -22,7 +23,7 @@ func httpCommon(res http.ResponseWriter, req *http.Request, fn func(request)) {
return
}
user, _, basicAuthOk := req.BasicAuth()
users, _, basicAuthOk := req.BasicAuth()
if !basicAuthOk {
fmt.Printf("basic auth failed\n")
res.WriteHeader(http.StatusForbidden)
@ -42,8 +43,15 @@ func httpCommon(res http.ResponseWriter, req *http.Request, fn func(request)) {
return
}
if user != body.FQDN {
fmt.Printf("expected %s == %s\n", user, body.FQDN)
passed := false
for _, user := range strings.Split(users, ",") {
if user == body.FQDN {
passed = true
}
}
if !passed {
fmt.Printf("expected %s in %s\n", body.FQDN, users)
res.WriteHeader(http.StatusForbidden)
return
}