first commit
This commit is contained in:
15
app/auth.go
Normal file
15
app/auth.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package app
|
||||
|
||||
import "net/http"
|
||||
|
||||
func basicAuthMiddleware(handler http.Handler, username, password string) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
user, pass, ok := r.BasicAuth()
|
||||
if !ok || user != username || pass != password {
|
||||
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
handler.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user