Send WWW-Authenticate along with 401 for RFC 7235 conformity

This commit is contained in:
Paul Brinkmeier 2024-07-18 21:56:51 +02:00
parent 38a487a6e1
commit 2d25a53949
2 changed files with 2 additions and 1 deletions

View File

@ -9,4 +9,4 @@
- [x] Write ESP8266 client - [x] Write ESP8266 client
- [ ] Make port configurable - [ ] Make port configurable
- [ ] Transfer using JSON - [ ] Transfer using JSON
- [ ] Correctly implement basic auth - [x] Correctly implement basic auth

View File

@ -148,6 +148,7 @@ func main() {
http.HandleFunc("/departures", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/departures", func(w http.ResponseWriter, r *http.Request) {
user, pass, ok := r.BasicAuth() user, pass, ok := r.BasicAuth()
if !(ok && user == "admin" && pass == password) { if !(ok && user == "admin" && pass == password) {
w.Header().Set("WWW-Authenticate", "Basic realm=\"Access to departure API\"")
http.Error(w, "You shall not pass", http.StatusUnauthorized) http.Error(w, "You shall not pass", http.StatusUnauthorized)
return return
} }