Skip to content
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
26 changes: 26 additions & 0 deletions connector/oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ type Config struct {
// If not setted it will be auto-detected the best-fit for the connector.
PKCEChallenge string `json:"pkceChallenge"`

// PKCEChallenge specifies which PKCE algorithm will be used
PKCEChallenge string `json:"pkceChallenge"`

// OverrideClaimMapping will be used to override the options defined in claimMappings.
// i.e. if there are 'email' and `preferred_email` claims available, by default Dex will always use the `email` claim independent of the ClaimMapping.EmailKey.
// This setting allows you to override the default behavior of Dex and enforce the mappings defined in `claimMapping`.
Expand Down Expand Up @@ -396,6 +399,7 @@ func (c *Config) Open(id string, logger *slog.Logger) (conn connector.Connector,
groupsPrefix: c.ClaimMutations.ModifyGroupNames.Prefix,
groupsSuffix: c.ClaimMutations.ModifyGroupNames.Suffix,
pkceChallenge: c.PKCEChallenge,
pkceChallenge: c.PKCEChallenge,
endSessionURL: endSessionURL,
}, nil
}
Expand Down Expand Up @@ -432,9 +436,21 @@ type oidcConnector struct {
groupsPrefix string
groupsSuffix string
pkceChallenge string
pkceChallenge string
endSessionURL string
}

func getAuthCodeOptionForCodeChallenge(codeVerifier, codeChallengeMethod string) (oauth2.AuthCodeOption, error) {
switch codeChallengeMethod {
case "plain":
return oauth2.VerifierOption(codeVerifier), nil
case "S256":
return oauth2.S256ChallengeOption(codeVerifier), nil
default:
return nil, fmt.Errorf("unknown challenge method (%v)", codeChallengeMethod)
}
}

func (c *oidcConnector) Close() error {
c.cancel()
return nil
Expand All @@ -457,6 +473,16 @@ func (c *oidcConnector) LoginURL(s connector.Scopes, callbackURL, state string)
opts = append(opts, oauth2.AccessTypeOffline, oauth2.SetAuthURLParam("prompt", c.promptType))
}

if c.pkceChallenge != "" {
codeVerifier := oauth2.GenerateVerifier()
authCodeOption, err := getAuthCodeOptionForCodeChallenge(codeVerifier, c.pkceChallenge)
if err != nil {
return "", fmt.Errorf("oidc: failed to get PKCE AuthCodeOption for CodeChallenge: %v", err)
}
opts = append(opts, authCodeOption)
state = state + ":pkce:" + codeVerifier
}

if c.pkceChallenge != "" {
codeVerifier := oauth2.GenerateVerifier()
authCodeOption, err := getAuthCodeOptionForCodeChallenge(codeVerifier, c.pkceChallenge)
Expand Down
Loading