Allow a whitelist of email addresses

This commit is contained in:
Jasper Lammens
2018-08-26 15:19:16 +02:00
committed by Thom Seddon
parent 36fffd2382
commit eaad0a9054
4 changed files with 32 additions and 1 deletions

View File

@ -38,6 +38,7 @@ type ForwardAuth struct {
CookieSecure bool
Domain []string
Whitelist []string
Direct bool
@ -86,12 +87,12 @@ func (f *ForwardAuth) ValidateCookie(r *http.Request, c *http.Cookie) (bool, str
// Validate email
func (f *ForwardAuth) ValidateEmail(email string) bool {
found := false
if len(f.Domain) > 0 {
parts := strings.Split(email, "@")
if len(parts) < 2 {
return false
}
found := false
for _, domain := range f.Domain {
if domain == parts[1] {
found = true
@ -100,6 +101,15 @@ func (f *ForwardAuth) ValidateEmail(email string) bool {
if !found {
return false
}
} else if len(f.Whitelist) > 0 {
for _, wlEmail := range f.Whitelist {
if wlEmail == email {
found = true
}
}
if !found {
return false
}
}
return true