Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring multiple OAuth clients in the same realm #53

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/cla/consent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@
email: [email protected]
- name: Phil Porada
email: [email protected]
- name: Matthias Stone
email: [email protected]

4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (cfg *Config) AddAuthorizationPolicy(p *authz.PolicyConfig) error {

// Validate validates Config.
func (cfg *Config) Validate() error {
if cfg == nil {
return fmt.Errorf("config is nil")
}

if len(cfg.AuthenticationPortals) < 1 && len(cfg.AuthorizationPolicies) < 1 {
return fmt.Errorf("no portals and gatekeepers found")
}
Expand Down
41 changes: 41 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,41 @@ func TestNewConfig(t *testing.T) {
},
},
},
{
name: "test valid config whan multiple portals have same realm from different identity stores",
identityStores: []*ids.IdentityStoreConfig{
{
Name: "localdb1",
Kind: "local",
Params: map[string]interface{}{
"realm": "local",
"path": filepath.Join(path.Dir(dbPath), "user_db1.json"),
},
},
{
Name: "localdb2",
Kind: "local",
Params: map[string]interface{}{
"realm": "local",
"path": filepath.Join(path.Dir(dbPath), "user_db2.json"),
},
},
},
portals: []*authn.PortalConfig{
{
Name: "myportal1",
IdentityStores: []string{
"localdb1",
},
},
{
Name: "myportal2",
IdentityStores: []string{
"localdb2",
},
},
},
},
}

for _, tc := range testcases {
Expand Down Expand Up @@ -361,3 +396,9 @@ func TestNewConfig(t *testing.T) {
})
}
}

func TestValidateNilConfig(t *testing.T) {
var cfg *Config
err := cfg.Validate()
tests.EvalErrWithLog(t, err, "Validate", true, fmt.Errorf("config is nil"), nil)
}
10 changes: 0 additions & 10 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type Server struct {
ssoProviders []sso.SingleSignOnProvider
userRegistries []registry.UserRegistry
nameRefs refMap
realmRefs refMap
logger *zap.Logger
}

Expand All @@ -74,7 +73,6 @@ func NewServer(config *Config, logger *zap.Logger) (*Server, error) {
config: config,
logger: logger,
nameRefs: newRefMap(),
realmRefs: newRefMap(),
}

for _, cfg := range config.IdentityProviders {
Expand All @@ -85,14 +83,10 @@ func NewServer(config *Config, logger *zap.Logger) (*Server, error) {
if _, exists := srv.nameRefs.identityProviders[provider.GetName()]; exists {
return nil, errors.ErrNewServer.WithArgs("duplicate identity provider name", provider.GetName())
}
if _, exists := srv.realmRefs.identityProviders[provider.GetRealm()]; exists {
return nil, errors.ErrNewServer.WithArgs("duplicate identity provider realm", provider.GetRealm())
}
if err := provider.Configure(); err != nil {
return nil, errors.ErrNewServer.WithArgs("failed configuring identity provider", err)
}
srv.nameRefs.identityProviders[provider.GetName()] = provider
srv.realmRefs.identityProviders[provider.GetRealm()] = provider
srv.identityProviders = append(srv.identityProviders, provider)
}

Expand All @@ -104,14 +98,10 @@ func NewServer(config *Config, logger *zap.Logger) (*Server, error) {
if _, exists := srv.nameRefs.identityStores[store.GetName()]; exists {
return nil, errors.ErrNewServer.WithArgs("duplicate identity store name", store.GetName())
}
if _, exists := srv.realmRefs.identityStores[store.GetRealm()]; exists {
return nil, errors.ErrNewServer.WithArgs("duplicate identity store realm", store.GetRealm())
}
if err := store.Configure(); err != nil {
return nil, errors.ErrNewServer.WithArgs("failed configuring identity store", err)
}
srv.nameRefs.identityStores[store.GetName()] = store
srv.realmRefs.identityStores[store.GetRealm()] = store
srv.identityStores = append(srv.identityStores, store)
}

Expand Down
Loading