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

add hidden prop to connector config #3818

Open
wants to merge 1 commit into
base: master
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
16 changes: 10 additions & 6 deletions cmd/dex/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,10 @@ func (s *Storage) UnmarshalJSON(b []byte) error {
// Connector is a magical type that can unmarshal YAML dynamically. The
// Type field determines the connector type, which is then customized for Config.
type Connector struct {
Type string `json:"type"`
Name string `json:"name"`
ID string `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
ID string `json:"id"`
Hidden bool `json:"hidden"`

Config server.ConnectorConfig `json:"config"`
}
Expand All @@ -376,9 +377,10 @@ type Connector struct {
// dynamically determine the type of the connector config.
func (c *Connector) UnmarshalJSON(b []byte) error {
var conn struct {
Type string `json:"type"`
Name string `json:"name"`
ID string `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
ID string `json:"id"`
Hidden bool `json:"hidden"`

Config json.RawMessage `json:"config"`
}
Expand Down Expand Up @@ -422,6 +424,7 @@ func (c *Connector) UnmarshalJSON(b []byte) error {
Name: conn.Name,
ID: conn.ID,
Config: connConfig,
Hidden: conn.Hidden,
}
return nil
}
Expand All @@ -438,6 +441,7 @@ func ToStorageConnector(c Connector) (storage.Connector, error) {
Type: c.Type,
Name: c.Name,
Config: data,
Hidden: c.Hidden,
}, nil
}

Expand Down
9 changes: 5 additions & 4 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ func (s *Server) handleAuthorization(w http.ResponseWriter, r *http.Request) {
for index, conn := range connectors {
connURL.Path = s.absPath("/auth", url.PathEscape(conn.ID))
connectorInfos[index] = connectorInfo{
ID: conn.ID,
Name: conn.Name,
Type: conn.Type,
URL: template.URL(connURL.String()),
ID: conn.ID,
Name: conn.Name,
Type: conn.Type,
URL: template.URL(connURL.String()),
Hidden: conn.Hidden,
}
}

Expand Down
19 changes: 13 additions & 6 deletions server/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,11 @@ var scopeDescriptions = map[string]string{
}

type connectorInfo struct {
ID string
Name string
URL template.URL
Type string
ID string
Name string
URL template.URL
Type string
Hidden bool
}

type byName []connectorInfo
Expand Down Expand Up @@ -283,11 +284,17 @@ func (t *templates) deviceSuccess(r *http.Request, w http.ResponseWriter, client
}

func (t *templates) login(r *http.Request, w http.ResponseWriter, connectors []connectorInfo) error {
sort.Sort(byName(connectors))
var visibleConnectors []connectorInfo
for _, connector := range connectors {
if !connector.Hidden {
visibleConnectors = append(visibleConnectors, connector)
}
}
sort.Sort(byName(visibleConnectors))
data := struct {
Connectors []connectorInfo
ReqPath string
}{connectors, r.URL.Path}
}{visibleConnectors, r.URL.Path}
return renderTemplate(w, t.loginTmpl, data)
}

Expand Down
2 changes: 2 additions & 0 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ type Connector struct {
// However, fixing this requires migrating Kubernetes objects for all previously created connectors,
// or making Dex reading both tags and act accordingly.
Config []byte `json:"email"`
// It specifies if the connector should be hidden in the login web page.
Hidden bool `json:"hidden"`
}

// VerificationKey is a rotated signing key which can still be used to verify
Expand Down