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