Skip to content

Commit a783667

Browse files
LemmonsRui Yang
authored andcommitted
Add groupsClaimMapping to the OIDC connector
The groupsClaimMapping setting allows one to specify which claim to pull group information from the OIDC provider. Previously it assumed group information was always in the "groups" claim, but that isn't the case for many OIDC providers (such as AWS Cognito using the "cognito:groups" claim instead) Signed-off-by: Scott Lemmon <[email protected]> Signed-off-by: Rui Yang <[email protected]>
1 parent 61312e7 commit a783667

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Documentation/connectors/oidc.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ connectors:
7373
# This can be overridden with the below option
7474
# insecureEnableGroups: true
7575

76+
# If an OIDC provider uses a different claim name than the standard "groups" claim to provide group information
77+
# the claim to use can be specified
78+
# groupsClaimMapping: "cognito:groups"
79+
7680
# When enabled, the OpenID Connector will query the UserInfo endpoint for additional claims. UserInfo claims
7781
# take priority over claims returned by the IDToken. This option should be used when the IDToken doesn't contain
7882
# all the claims requested.

connector/oidc/oidc.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ type Config struct {
4444
// InsecureEnableGroups enables groups claims. This is disabled by default until https://github.com/dexidp/dex/issues/1065 is resolved
4545
InsecureEnableGroups bool `json:"insecureEnableGroups"`
4646

47+
// GroupsClaimMapping sets the name of the claim which contains the users groups. InsecureEnableGroups must be enabled to use this setting
48+
GroupsClaimMapping string `json:"groupsClaimMapping"` // defaults to "groups"
49+
4750
// GetUserInfo uses the userinfo endpoint to get additional claims for
4851
// the token. This is especially useful where upstreams return "thin"
4952
// id tokens
@@ -132,6 +135,11 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e
132135
c.PromptType = "consent"
133136
}
134137

138+
// GroupsClaimMapping should be "groups" by default, if not set
139+
if c.GroupsClaimMapping == "" {
140+
c.GroupsClaimMapping = "groups"
141+
}
142+
135143
clientID := c.ClientID
136144
return &oidcConnector{
137145
provider: provider,
@@ -151,6 +159,7 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e
151159
hostedDomains: c.HostedDomains,
152160
insecureSkipEmailVerified: c.InsecureSkipEmailVerified,
153161
insecureEnableGroups: c.InsecureEnableGroups,
162+
groupsClaimMapping: c.GroupsClaimMapping,
154163
getUserInfo: c.GetUserInfo,
155164
userIDKey: c.UserIDKey,
156165
userNameKey: c.UserNameKey,
@@ -175,6 +184,7 @@ type oidcConnector struct {
175184
hostedDomains []string
176185
insecureSkipEmailVerified bool
177186
insecureEnableGroups bool
187+
groupsClaimMapping string
178188
getUserInfo bool
179189
userIDKey string
180190
userNameKey string
@@ -357,13 +367,14 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I
357367
}
358368

359369
if c.insecureEnableGroups {
360-
vs, ok := claims["groups"].([]interface{})
370+
371+
vs, ok := claims[c.groupsClaimMapping].([]interface{})
361372
if ok {
362373
for _, v := range vs {
363374
if s, ok := v.(string); ok {
364375
identity.Groups = append(identity.Groups, s)
365376
} else {
366-
return identity, errors.New("malformed \"groups\" claim")
377+
return identity, fmt.Errorf("malformed \"%v\" claim", c.groupsClaimMapping)
367378
}
368379
}
369380
}

0 commit comments

Comments
 (0)