Created
October 20, 2019 17:46
-
-
Save zackproser/8c01049767dd0e8413363568a36fe066 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func basicAuth(h httprouter.Handle) httprouter.Handle { | |
| return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | |
| // Get the Basic Authentication credentials | |
| user, password, hasAuth := r.BasicAuth() | |
| if hasAuth && user == Config.Server.CatfactsUser && password == Config.Server.CatfactsPassword { | |
| h(w, r, ps) | |
| } else { | |
| // Request Basic Authentication | |
| w.Header().Set("WWW-Authenticate", "Basic realm=Restricted") | |
| http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment