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 support for customizable username field #181

Open
wants to merge 3 commits 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
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ An example configuration is available [here](../examples/config.yaml)
| k8s_ca_pem_base64_encoded | no | cluster | The Base64 encoded CA for your k8s server (used in generating instructions) |
| k8s_ca_pem_file | no | cluster | The CA file for your k8s server (used in generating instructions) |
| scopes | no | cluster | A list OpenID scopes to request |
| username_field | no | cluster | A field that points to username |
| tls_cert | no | root | Path to TLS cert if SSL enabled |
| tls_key | no | root | Path to TLS key if SSL enabled |
| idp_ca_uri | no | root | A url pointing to the CA for generating 'idp-certificate-authority' in the kubeconfig |
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Cluster struct {
Client *http.Client
Redirect_URI string
Config Config
Username_Field string
}

// Define our configuration
Expand Down
9 changes: 7 additions & 2 deletions templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ func (cluster *Cluster) renderToken(w http.ResponseWriter,
}

unix_username := "user"
if data["email"] != nil {
email := data["email"].(string)
username_field := "email"
if cluster.Username_Field != "" {
username_field = cluster.Username_Field
}

if data[username_field] != nil {
email := data[username_field].(string)
unix_username = strings.Split(email, "@")[0]
}

Expand Down