1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-06-17 00:17:40 +02:00

Adding Support for multi white listed urls with regex url match.

This commit is contained in:
vishnu chilamakuru
2015-01-12 14:48:41 +05:30
parent a80b93130c
commit c4d25d271f
3 changed files with 31 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import (
"net/url"
"strings"
"time"
"regexp"
"github.com/bitly/go-simplejson"
)
@ -40,6 +41,8 @@ type OauthProxy struct {
DisplayHtpasswdForm bool
serveMux *http.ServeMux
PassBasicAuth bool
skipAuthRegex []string
compiledRegex []*regexp.Regexp
}
func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
@ -52,6 +55,10 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
log.Printf("mapping path %q => upstream %q", path, u)
serveMux.Handle(path, httputil.NewSingleHostReverseProxy(u))
}
for _, u := range opts.CompiledRegex {
log.Printf("compiled skip-auth-regex => %q", u)
}
redirectUrl := opts.redirectUrl
redirectUrl.Path = oauthCallbackPath
@ -76,6 +83,8 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
oauthLoginUrl: login,
serveMux: serveMux,
redirectUrl: redirectUrl,
skipAuthRegex: opts.SkipAuthRegex,
compiledRegex: opts.CompiledRegex,
PassBasicAuth: opts.PassBasicAuth,
}
}
@ -299,6 +308,15 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
return
}
for _, u := range p.compiledRegex {
match := u.MatchString(req.URL.Path)
if match {
p.serveMux.ServeHTTP(rw, req)
return
}
}
if req.URL.Path == signInPath {
redirect, err := p.GetRedirect(req)
if err != nil {