Set the 'WWW-Authenticate' header on 401 responses when basic

auth is enabled. This is required for basic auth to work with
web browsers.
This commit is contained in:
Robert Bailey
2015-04-27 22:24:26 -07:00
parent d327ba7776
commit 4304b1d24a
3 changed files with 21 additions and 7 deletions

View File

@@ -49,7 +49,18 @@ func NewRequestAuthenticator(mapper api.RequestContextMapper, auth authenticator
)
}
var Unauthorized http.HandlerFunc = unauthorized
func Unauthorized(supportsBasicAuth bool) http.HandlerFunc {
if supportsBasicAuth {
return unauthorizedBasicAuth
}
return unauthorized
}
// unauthorizedBasicAuth serves an unauthorized message to clients.
func unauthorizedBasicAuth(w http.ResponseWriter, req *http.Request) {
w.Header().Set("WWW-Authenticate", `Basic realm="kubernetes-master"`)
http.Error(w, "Unauthorized", http.StatusUnauthorized)
}
// unauthorized serves an unauthorized message to clients.
func unauthorized(w http.ResponseWriter, req *http.Request) {