401 Unauthorize HTTP error added (#681)

401 Unauthorize HTTP error added to trigger browser credentials pop-up promt [RFC 7235 https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication]
This commit is contained in:
ofen 2020-08-09 09:38:41 +03:00 committed by GitHub
parent 807c2b076c
commit 81746d14b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -49,7 +49,8 @@ func main() {
func requestHandler(w http.ResponseWriter, r *http.Request) bool { func requestHandler(w http.ResponseWriter, r *http.Request) bool {
username, password, ok := r.BasicAuth() username, password, ok := r.BasicAuth()
if !ok { if !ok {
httpserver.Errorf(w, r, "missing `Authorization: Basic *` header") w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
http.Error(w, "missing `Authorization: Basic *` header", http.StatusUnauthorized)
return true return true
} }
ac := authConfig.Load().(map[string]*UserInfo) ac := authConfig.Load().(map[string]*UserInfo)