Created
November 13, 2013 01:33
-
-
Save codegangsta/7442073 to your computer and use it in GitHub Desktop.
This file contains 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
package auth | |
import ( | |
"encoding/base64" | |
"net/http" | |
) | |
func Basic(username string, password string) http.HandlerFunc { | |
var siteAuth = base64.StdEncoding.EncodeToString([]byte(username + ":" + password)) | |
return func(res http.ResponseWriter, req *http.Request) { | |
auth := req.Header.Get("Authorization") | |
if auth != "Basic "+siteAuth { | |
res.Header().Set("WWW-Authenticate", "Basic realm=\"Authorization Required\"") | |
http.Error(res, "Not Authorized", http.StatusUnauthorized) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment