diff options
author | Marco Bonetti <marco@intercom.io> | 2016-06-10 14:11:54 +0100 |
---|---|---|
committer | Marco Bonetti <marco@intercom.io> | 2016-06-14 09:26:29 +0100 |
commit | a03243a826bb4eb5eebad19133f6b15e2f5dfdc2 (patch) | |
tree | bedda3934ce501a32f2f13b00b1929e458170cc7 /server/auth/github | |
parent | c074b8694f28ab6b3cc1ccb31474cfa507f73e81 (diff) |
Add support for a users whitelist
Diffstat (limited to 'server/auth/github')
-rw-r--r-- | server/auth/github/github.go | 13 | ||||
-rw-r--r-- | server/auth/github/github_test.go | 2 |
2 files changed, 12 insertions, 3 deletions
diff --git a/server/auth/github/github.go b/server/auth/github/github.go index 7904e26..a6a4a59 100644 --- a/server/auth/github/github.go +++ b/server/auth/github/github.go @@ -22,12 +22,17 @@ const ( type Config struct { config *oauth2.Config organization string + whitelist map[string]bool } // New creates a new Github provider from a configuration. func New(c *config.Auth) (auth.Provider, error) { - if c.ProviderOpts["organization"] == "" { - return nil, errors.New("github_opts organization must not be empty") + uw := make(map[string]bool) + for _, u := range c.UsersWhitelist { + uw[u] = true + } + if c.ProviderOpts["organization"] == "" && len(uw) == 0 { + return nil, errors.New("github_opts organization and the users whitelist must not be both empty") } return &Config{ config: &oauth2.Config{ @@ -41,6 +46,7 @@ func New(c *config.Auth) (auth.Provider, error) { }, }, organization: c.ProviderOpts["organization"], + whitelist: uw, }, nil } @@ -56,6 +62,9 @@ func (c *Config) Name() string { // Valid validates the oauth token. func (c *Config) Valid(token *oauth2.Token) bool { + if len(c.whitelist) == 0 && !c.whitelist[c.Username(token)] { + return false + } if !token.Valid() { return false } diff --git a/server/auth/github/github_test.go b/server/auth/github/github_test.go index 1d6b801..c0b26a4 100644 --- a/server/auth/github/github_test.go +++ b/server/auth/github/github_test.go @@ -32,7 +32,7 @@ func TestNewEmptyOrganization(t *testing.T) { a := assert.New(t) _, err := newGithub() - a.EqualError(err, "github_opts organization must not be empty") + a.EqualError(err, "github_opts organization and the users whitelist must not be both empty") organization = "exampleorg" } |