option for whitelisted /path

This commit is contained in:
Andrew Schleifer 2018-09-20 15:28:14 +08:00
parent deaf725bae
commit 8bea12489d
1 changed files with 14 additions and 0 deletions

14
main.go
View File

@ -34,6 +34,7 @@ type Config struct {
TimeoutPtr *int
CookieSecret string
AllowAllPtr *bool
WhitelistPtr *string
}
func main() {
@ -49,6 +50,7 @@ func main() {
config.UsernameHeaderPtr = flag.String("username-header", "Discourse-User-Name", "Request header to pass authenticated username into")
config.GroupsHeaderPtr = flag.String("groups-header", "Discourse-User-Groups", "Request header to pass authenticated groups into")
config.TimeoutPtr = flag.Int("timeout", 10, "Read/write timeout")
config.WhitelistPtr = flag.String("whitelist", "", "Path which does not require authorization")
flag.Parse()
@ -107,6 +109,9 @@ func main() {
func authProxyHandler(handler http.Handler, config *Config) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if checkWhitelist(handler, r, w, config) {
return
}
if checkAuthorizationHeader(handler, r, w, config) {
return
}
@ -148,6 +153,15 @@ func checkAuthorizationHeader(handler http.Handler, r *http.Request, w http.Resp
return false
}
func checkWhitelist(handler http.Handler, r *http.Request, w http.ResponseWriter, config *Config) bool {
if r.URL.Path == *(config.WhitelistPtr) {
handler.ServeHTTP(w, r)
return true
}
return false
}
func redirectIfNoCookie(handler http.Handler, r *http.Request, w http.ResponseWriter, config *Config) {
cookie, err := r.Cookie("__discourse_proxy")
var username, groups string