small refactors and cleanup

Signed-off-by: Rui Yang <ruiya@vmware.com>
This commit is contained in:
Rui Yang 2021-12-01 12:45:25 -05:00
parent 8b865169bd
commit 539e08ba50
2 changed files with 24 additions and 19 deletions

View File

@ -81,7 +81,6 @@ Dex implements the following connectors:
| [Atlassian Crowd](https://dexidp.io/docs/connectors/atlassiancrowd/) | yes | yes | yes * | beta | preferred_username claim must be configured through config | | [Atlassian Crowd](https://dexidp.io/docs/connectors/atlassiancrowd/) | yes | yes | yes * | beta | preferred_username claim must be configured through config |
| [Gitea](https://dexidp.io/docs/connectors/gitea/) | yes | no | yes | alpha | | | [Gitea](https://dexidp.io/docs/connectors/gitea/) | yes | no | yes | alpha | |
| [OpenStack Keystone](https://dexidp.io/docs/connectors/keystone/) | yes | yes | no | alpha | | | [OpenStack Keystone](https://dexidp.io/docs/connectors/keystone/) | yes | yes | no | alpha | |
| [Generic OAuth 2.0](https://dexidp.io/docs/connectors/oauth/) | no | yes | yes | alpha | |
Stable, beta, and alpha are defined as: Stable, beta, and alpha are defined as:

View File

@ -65,28 +65,34 @@ type Config struct {
func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) { func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
var err error var err error
if c.UserIDKey == "" { userIDKey := c.UserIDKey
c.UserIDKey = "id" if userIDKey == "" {
userIDKey = "id"
} }
if c.ClaimMapping.UserNameKey == "" { userNameKey := c.ClaimMapping.UserNameKey
c.ClaimMapping.UserNameKey = "user_name" if userNameKey == "" {
userNameKey = "user_name"
} }
if c.ClaimMapping.PreferredUsernameKey == "" { preferredUsernameKey := c.ClaimMapping.PreferredUsernameKey
c.ClaimMapping.PreferredUsernameKey = "preferred_username" if preferredUsernameKey == "" {
preferredUsernameKey = "preferred_username"
} }
if c.ClaimMapping.GroupsKey == "" { groupsKey := c.ClaimMapping.GroupsKey
c.ClaimMapping.GroupsKey = "groups" if groupsKey == "" {
groupsKey = "groups"
} }
if c.ClaimMapping.EmailKey == "" { emailKey := c.ClaimMapping.EmailKey
c.ClaimMapping.EmailKey = "email" if emailKey == "" {
emailKey = "email"
} }
if c.ClaimMapping.EmailVerifiedKey == "" { emailVerifiedKey := c.ClaimMapping.EmailVerifiedKey
c.ClaimMapping.EmailVerifiedKey = "email_verified" if emailVerifiedKey == "" {
emailVerifiedKey = "email_verified"
} }
oauthConn := &oauthConnector{ oauthConn := &oauthConnector{
@ -98,12 +104,12 @@ func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error)
scopes: c.Scopes, scopes: c.Scopes,
redirectURI: c.RedirectURI, redirectURI: c.RedirectURI,
logger: logger, logger: logger,
userIDKey: c.UserIDKey, userIDKey: userIDKey,
userNameKey: c.ClaimMapping.UserNameKey, userNameKey: userNameKey,
preferredUsernameKey: c.ClaimMapping.PreferredUsernameKey, preferredUsernameKey: preferredUsernameKey,
groupsKey: c.ClaimMapping.GroupsKey, groupsKey: groupsKey,
emailKey: c.ClaimMapping.EmailKey, emailKey: emailKey,
emailVerifiedKey: c.ClaimMapping.EmailVerifiedKey, emailVerifiedKey: emailVerifiedKey,
} }
oauthConn.httpClient, err = newHTTPClient(c.RootCAs, c.InsecureSkipVerify) oauthConn.httpClient, err = newHTTPClient(c.RootCAs, c.InsecureSkipVerify)