Skip to content

Commit

Permalink
Merge pull request dexidp#1839 from seuf/authproxy-header-configuration
Browse files Browse the repository at this point in the history
Allow configuration of returned auth proxy header
  • Loading branch information
sagikazarmark authored Jan 7, 2021
2 parents ee50c09 + e164bb3 commit 4f32639
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions connector/authproxy/authproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ import (

// Config holds the configuration parameters for a connector which returns an
// identity with the HTTP header X-Remote-User as verified email.
type Config struct{}
type Config struct {
UserHeader string `json:"userHeader"`
}

// Open returns an authentication strategy which requires no user interaction.
func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
return &callback{logger: logger, pathSuffix: "/" + id}, nil
userHeader := c.UserHeader
if userHeader == "" {
userHeader = "X-Remote-User"
}

return &callback{userHeader: userHeader, logger: logger, pathSuffix: "/" + id}, nil
}

// Callback is a connector which returns an identity with the HTTP header
// X-Remote-User as verified email.
type callback struct {
userHeader string
logger log.Logger
pathSuffix string
}
Expand All @@ -43,9 +51,9 @@ func (m *callback) LoginURL(s connector.Scopes, callbackURL, state string) (stri

// HandleCallback parses the request and returns the user's identity
func (m *callback) HandleCallback(s connector.Scopes, r *http.Request) (connector.Identity, error) {
remoteUser := r.Header.Get("X-Remote-User")
remoteUser := r.Header.Get(m.userHeader)
if remoteUser == "" {
return connector.Identity{}, fmt.Errorf("required HTTP header X-Remote-User is not set")
return connector.Identity{}, fmt.Errorf("required HTTP header %s is not set", m.userHeader)
}
// TODO: add support for X-Remote-Group, see
// https://kubernetes.io/docs/admin/authentication/#authenticating-proxy
Expand Down

0 comments on commit 4f32639

Please sign in to comment.