tweak middleware headers; v0.2.1
This commit is contained in:
parent
10ecb3058f
commit
ab1d495514
1 changed files with 9 additions and 5 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue