Skip to content

Commit

Permalink
move oauth connector doc to dex website repo
Browse files Browse the repository at this point in the history
move default key values configure to connector construct function

Signed-off-by: Rui Yang <ruiya@vmware.com>
  • Loading branch information
Rui Yang authored and CI Bot committed Mar 20, 2021
1 parent f72bb7b commit f153234
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 90 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Dex implements the following connectors:
| [SAML 2.0](https://dexidp.io/docs/connectors/saml/) | no | yes | no | stable | WARNING: Unmaintained and likely vulnerable to auth bypasses ([#1884](https://github.com/dexidp/dex/discussions/1884)) |
| [GitLab](https://dexidp.io/docs/connectors/gitlab/) | yes | yes | yes | beta | |
| [OpenID Connect](https://dexidp.io/docs/connectors/oidc/) | yes | yes | yes | beta | Includes Salesforce, Azure, etc. |
| [Generic OAuth 2.0](https://dexidp.io/docs/connectors/oauth.md) | no | yes | yes | beta | |
| [OAuth 2.0](https://dexidp.io/docs/connectors/oauth/) | no | yes | yes | alpha | |
| [Google](https://dexidp.io/docs/connectors/google/) | yes | yes | yes | alpha | |
| [LinkedIn](https://dexidp.io/docs/connectors/linkedin/) | yes | no | no | beta | |
| [Microsoft](https://dexidp.io/docs/connectors/microsoft/) | yes | yes | no | beta | |
Expand All @@ -81,7 +81,6 @@ Dex implements the following connectors:
| [OpenShift](https://dexidp.io/docs/connectors/openshift/) | no | yes | no | alpha | |
| [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 | |
| [Generic OAuth 2.0](https://dexidp.io/docs/connectors/oauth/) | no | yes | yes | alpha |

Stable, beta, and alpha are defined as:

Expand Down
48 changes: 24 additions & 24 deletions connector/oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ type Config struct {
func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
var err error

if c.UserIDKey == "" {
c.UserIDKey = "id"
}

if c.ClaimMapping.UserNameKey == "" {
c.ClaimMapping.UserNameKey = "user_name"
}

if c.ClaimMapping.PreferredUsernameKey == "" {
c.ClaimMapping.PreferredUsernameKey = "preferred_username"
}

if c.ClaimMapping.GroupsKey == "" {
c.ClaimMapping.GroupsKey = "groups"
}

if c.ClaimMapping.EmailKey == "" {
c.ClaimMapping.EmailKey = "email"
}

if c.ClaimMapping.EmailVerifiedKey == "" {
c.ClaimMapping.EmailVerifiedKey = "email_verified"
}

oauthConn := &oauthConnector{
clientID: c.ClientID,
clientSecret: c.ClientSecret,
Expand Down Expand Up @@ -181,36 +205,12 @@ func (c *oauthConnector) HandleCallback(s connector.Scopes, r *http.Request) (id
return identity, fmt.Errorf("OAuth Connector: failed to parse userinfo: %v", err)
}

if c.userIDKey == "" {
c.userIDKey = "id"
}

userID, found := userInfoResult[c.userIDKey].(string)
if !found {
return identity, fmt.Errorf("OAuth Connector: not found %v claim", c.userIDKey)
}

identity.UserID = userID
if c.userNameKey == "" {
c.userNameKey = "user_name"
}

if c.preferredUsernameKey == "" {
c.preferredUsernameKey = "preferred_username"
}

if c.groupsKey == "" {
c.groupsKey = "groups"
}

if c.emailKey == "" {
c.emailKey = "email"
}

if c.emailVerifiedKey == "" {
c.emailVerifiedKey = "email_verified"
}

identity.Username, _ = userInfoResult[c.userNameKey].(string)
identity.PreferredUsername, _ = userInfoResult[c.preferredUsernameKey].(string)
identity.Email, _ = userInfoResult[c.emailKey].(string)
Expand Down
64 changes: 0 additions & 64 deletions docs/connectors/oauth.md

This file was deleted.

0 comments on commit f153234

Please sign in to comment.