git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #16 from drewolson/master

Allow specifying multiple google apps domains.

commit18b4612aae9cb146aacbb3f63e4bacdf5cc7877d authorJehiah Czebotar <jehiah@gmail.com> dateThu 22 May 2014, 09:47 (12 years ago) parent7d0a823964929a
2 files changed+10−13
main.go+5−4 validator.go+5−9
main.go+5−4
@@ -23,12 +23,13 @@ var (
2323 htpasswdFile = flag.String("htpasswd-file", "", "additionally authenticate against a htpasswd file. Entries must be created with \"htpasswd -s\" for SHA encryption")
2424 cookieSecret = flag.String("cookie-secret", "", "the seed string for secure cookies")
2525 cookieDomain = flag.String("cookie-domain", "", "an optional cookie domain to force cookies to")
26− googleAppsDomain = flag.String("google-apps-domain", "", "authenticate against the given google apps domain")
2726 authenticatedEmailsFile = flag.String("authenticated-emails-file", "", "authenticate against emails via file (one per line)")
27+ googleAppsDomains = StringArray{}
2828 upstreams = StringArray{}
2929)
3030
3131func init() {
32+ flag.Var(&googleAppsDomains, "google-apps-domain", "authenticate against the given google apps domain (may be given multiple times)")
3233 flag.Var(&upstreams, "upstream", "the http url(s) of the upstream endpoint. If multiple, routing is based on path")
3334}
3435
@@ -78,11 +79,11 @@ func main() {
7879 log.Fatalf("error parsing --redirect-url %s", err.Error())
7980 }
8081
81− validator := NewValidator(*googleAppsDomain, *authenticatedEmailsFile)
82+ validator := NewValidator(googleAppsDomains, *authenticatedEmailsFile)
8283 oauthproxy := NewOauthProxy(upstreamUrls, *clientID, *clientSecret, validator)
8384 oauthproxy.SetRedirectUrl(redirectUrl)
84− if *googleAppsDomain != "" && *authenticatedEmailsFile == "" {
85− oauthproxy.SignInMessage = fmt.Sprintf("using a %s email address", *googleAppsDomain)
85+ if len(googleAppsDomains) != 0 && *authenticatedEmailsFile == "" {
86+ oauthproxy.SignInMessage = fmt.Sprintf("using a email address from the following domains: %v", strings.Join(googleAppsDomains, ", "))
8687 }
8788 if *htpasswdFile != "" {
8889 oauthproxy.HtpasswdFile, err = NewHtpasswdFromFile(*htpasswdFile)
validator.go+5−9
@@ -8,13 +8,8 @@ import (
88 "strings"
99)
1010
11−func NewValidator(domain string, usersFile string) func(string) bool {
12−
11+func NewValidator(domains []string, usersFile string) func(string) bool {
1312 validUsers := make(map[string]bool)
14− emailSuffix := ""
15− if domain != "" {
16− emailSuffix = fmt.Sprintf("@%s", domain)
17− }
1813
1914 if usersFile != "" {
2015 r, err := os.Open(usersFile)
@@ -32,9 +27,10 @@ func NewValidator(domain string, usersFile string) func(string) bool {
3227 }
3328
3429 validator := func(email string) bool {
35− var valid bool
36− if emailSuffix != "" {
37− valid = strings.HasSuffix(email, emailSuffix)
30+ valid := false
31+ for _, domain := range domains {
32+ emailSuffix := fmt.Sprintf("@%s", domain)
33+ valid = valid || strings.HasSuffix(email, emailSuffix)
3834 }
3935 if !valid {
4036 _, valid = validUsers[email]