Skip to content
Snippets Groups Projects
Commit e164bb38 authored by Thierry Sallé's avatar Thierry Sallé Committed by seuf
Browse files

Apply suggestions from code review

parent a1c71987
Branches
Tags
No related merge requests found
...@@ -20,13 +20,18 @@ type Config struct { ...@@ -20,13 +20,18 @@ type Config struct {
// Open returns an authentication strategy which requires no user interaction. // Open returns an authentication strategy which requires no user interaction.
func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) { func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
return &callback{UserHeader: c.UserHeader, 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 // Callback is a connector which returns an identity with the HTTP header
// X-Remote-User as verified email. // X-Remote-User as verified email.
type callback struct { type callback struct {
UserHeader string userHeader string
logger log.Logger logger log.Logger
pathSuffix string pathSuffix string
} }
...@@ -46,13 +51,9 @@ func (m *callback) LoginURL(s connector.Scopes, callbackURL, state string) (stri ...@@ -46,13 +51,9 @@ func (m *callback) LoginURL(s connector.Scopes, callbackURL, state string) (stri
// HandleCallback parses the request and returns the user's identity // HandleCallback parses the request and returns the user's identity
func (m *callback) HandleCallback(s connector.Scopes, r *http.Request) (connector.Identity, error) { func (m *callback) HandleCallback(s connector.Scopes, r *http.Request) (connector.Identity, error) {
userHeader := "X-Remote-User" // Default value remoteUser := r.Header.Get(m.userHeader)
if m.UserHeader != "" {
userHeader = m.UserHeader
}
remoteUser := r.Header.Get(userHeader)
if remoteUser == "" { if remoteUser == "" {
return connector.Identity{}, fmt.Errorf("required HTTP header %s is not set", m.UserHeader) return connector.Identity{}, fmt.Errorf("required HTTP header %s is not set", m.userHeader)
} }
// TODO: add support for X-Remote-Group, see // TODO: add support for X-Remote-Group, see
// https://kubernetes.io/docs/admin/authentication/#authenticating-proxy // https://kubernetes.io/docs/admin/authentication/#authenticating-proxy
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment