tweak middleware headers; v0.2.1

This commit is contained in:
Iris Lightshard 2023-01-26 20:54:48 -07:00
parent 10ecb3058f
commit ab1d495514
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398

View file

@ -100,7 +100,6 @@ func Provision(userStore auth.UserStore, ttl int) http.Handler {
return return
} }
} }
w.Header().Add("WWW-Authenticate", "Basic")
w.WriteHeader(http.StatusUnauthorized) w.WriteHeader(http.StatusUnauthorized)
return return
} }
@ -110,6 +109,7 @@ func Provision(userStore auth.UserStore, ttl int) http.Handler {
func Validate(next http.Handler, userStore auth.UserStore, scopes map[string]string) http.Handler { func Validate(next http.Handler, userStore auth.UserStore, scopes map[string]string) http.Handler {
handlerFunc := func(w http.ResponseWriter, req *http.Request) { handlerFunc := func(w http.ResponseWriter, req *http.Request) {
errString := ""
authHeader := req.Header.Get("Authorization") authHeader := req.Header.Get("Authorization")
if strings.HasPrefix(authHeader, "Bearer ") { if strings.HasPrefix(authHeader, "Bearer ") {
authToken := strings.Split(authHeader, "Bearer ")[1] authToken := strings.Split(authHeader, "Bearer ")[1]
@ -117,9 +117,13 @@ func Validate(next http.Handler, userStore auth.UserStore, scopes map[string]str
if validated && err == nil { if validated && err == nil {
next.ServeHTTP(w, req) next.ServeHTTP(w, req)
return return
} else {
errString = err.Error()
} }
} else {
errString = "No authentication data"
} }
w.Header().Add("WWW-Authenticate", "Basic") w.Header().Add("Quartzgun-Error", errString)
w.WriteHeader(http.StatusUnauthorized) w.WriteHeader(http.StatusUnauthorized)
} }