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

feat: allow domain names or IDs in keystone connector #3506

Merged
merged 1 commit into from
Jun 3, 2024
Merged
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
36 changes: 24 additions & 12 deletions connector/keystone/keystone.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
"log/slog"
"net/http"

"github.com/google/uuid"

"github.com/dexidp/dex/connector"
)

type conn struct {
Domain string
Domain domainKeystone
Host string
AdminUsername string
AdminPassword string
Expand All @@ -29,8 +31,8 @@ type userKeystone struct {
}

type domainKeystone struct {
ID string `json:"id"`
Name string `json:"name"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}

// Config holds the configuration parameters for Keystone connector.
Expand Down Expand Up @@ -71,13 +73,9 @@ type password struct {
}

type user struct {
Name string `json:"name"`
Domain domain `json:"domain"`
Password string `json:"password"`
}

type domain struct {
ID string `json:"id"`
Name string `json:"name"`
Domain domainKeystone `json:"domain"`
Password string `json:"password"`
}

type token struct {
Expand Down Expand Up @@ -112,8 +110,22 @@ var (

// Open returns an authentication strategy using Keystone.
func (c *Config) Open(id string, logger *slog.Logger) (connector.Connector, error) {
_, err := uuid.Parse(c.Domain)
var domain domainKeystone
// check if the supplied domain is a UUID or the special "default" value
// which is treated as an ID and not a name
if err == nil || c.Domain == "default" {
domain = domainKeystone{
ID: c.Domain,
}
} else {
domain = domainKeystone{
Name: c.Domain,
}
}

return &conn{
Domain: c.Domain,
Domain: domain,
Host: c.Host,
AdminUsername: c.AdminUsername,
AdminPassword: c.AdminPassword,
Expand Down Expand Up @@ -202,7 +214,7 @@ func (p *conn) getTokenResponse(ctx context.Context, username, pass string) (res
Password: password{
User: user{
Name: username,
Domain: domain{ID: p.Domain},
Domain: p.Domain,
Password: pass,
},
},
Expand Down
Loading