Browse Source

Merge 3f304955cb into 13f012fb81

pull/3844/merge
Vincent van Dam 4 days ago committed by GitHub
parent
commit
e4a31cdbbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      connector/openshift/openshift.go
  2. 4
      connector/openshift/openshift_test.go

12
connector/openshift/openshift.go

@ -31,6 +31,9 @@ type Config struct {
Groups []string `json:"groups"`
InsecureCA bool `json:"insecureCA"`
RootCA string `json:"rootCA"`
// If this is set, the email claim will have this domain appended.
// This should not include the @ character.
EmailSuffix string `json:"emailSuffix"`
}
var (
@ -50,6 +53,7 @@ type openshiftConnector struct {
insecureCA bool
rootCA string
groups []string
emailSuffix string
}
type user struct {
@ -101,6 +105,7 @@ func (c *Config) OpenWithHTTPClient(id string, logger *slog.Logger,
rootCA: c.RootCA,
groups: c.Groups,
httpClient: httpClient,
emailSuffix: c.EmailSuffix,
}
var metadata struct {
@ -212,11 +217,16 @@ func (c *openshiftConnector) identity(ctx context.Context, s connector.Scopes,
}
}
email := user.Name
if c.emailSuffix != "" {
email = email + "@" + c.emailSuffix
}
identity = connector.Identity{
UserID: user.UID,
Username: user.Name,
PreferredUsername: user.Name,
Email: user.Name,
Email: email,
Groups: user.Groups,
}

4
connector/openshift/openshift_test.go

@ -169,7 +169,7 @@ func TestCallbackIdentity(t *testing.T) {
expectNil(t, err)
oc := openshiftConnector{apiURL: s.URL, httpClient: h, oauth2Config: &oauth2.Config{
oc := openshiftConnector{apiURL: s.URL, httpClient: h, emailSuffix: "test.example.com", oauth2Config: &oauth2.Config{
Endpoint: oauth2.Endpoint{
AuthURL: fmt.Sprintf("%s/oauth/authorize", s.URL),
TokenURL: fmt.Sprintf("%s/oauth/token", s.URL),
@ -181,7 +181,7 @@ func TestCallbackIdentity(t *testing.T) {
expectEquals(t, identity.UserID, "12345")
expectEquals(t, identity.Username, "jdoe")
expectEquals(t, identity.PreferredUsername, "jdoe")
expectEquals(t, identity.Email, "jdoe")
expectEquals(t, identity.Email, "jdoe@test.example.com")
expectEquals(t, len(identity.Groups), 1)
expectEquals(t, identity.Groups[0], "users")
}

Loading…
Cancel
Save