Skip to content

Commit

Permalink
Add email suffix support
Browse files Browse the repository at this point in the history
  • Loading branch information
joyrex2001 committed Nov 13, 2024
1 parent b211f55 commit fe7c2cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion connector/openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -50,6 +53,7 @@ type openshiftConnector struct {
insecureCA bool
rootCA string
groups []string
emailSuffix string
}

type user struct {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -211,11 +216,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,
}

Expand Down
4 changes: 2 additions & 2 deletions connector/openshift/openshift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,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),
Expand All @@ -182,7 +182,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")
}
Expand Down

0 comments on commit fe7c2cd

Please sign in to comment.