add configurable preferred_username key
Signed-off-by: Rui Yang <ruiya@vmware.com>
This commit is contained in:
parent
fdf19e8014
commit
9952851cc4
3 changed files with 52 additions and 44 deletions
|
@ -31,6 +31,7 @@ type oauthConnector struct {
|
||||||
groupsKey string
|
groupsKey string
|
||||||
userIDKey string
|
userIDKey string
|
||||||
userNameKey string
|
userNameKey string
|
||||||
|
preferredUsernameKey string
|
||||||
httpClient *http.Client
|
httpClient *http.Client
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
@ -50,6 +51,7 @@ type Config struct {
|
||||||
GroupsKey string `json:"groupsKey"`
|
GroupsKey string `json:"groupsKey"`
|
||||||
UserIDKey string `json:"userIDKey"`
|
UserIDKey string `json:"userIDKey"`
|
||||||
UserNameKey string `json:"userNameKey"`
|
UserNameKey string `json:"userNameKey"`
|
||||||
|
PreferredUsernameKey string `json:"preferredUsernameKey"`
|
||||||
RootCAs []string `json:"rootCAs"`
|
RootCAs []string `json:"rootCAs"`
|
||||||
InsecureSkipVerify bool `json:"insecureSkipVerify"`
|
InsecureSkipVerify bool `json:"insecureSkipVerify"`
|
||||||
}
|
}
|
||||||
|
@ -182,9 +184,13 @@ func (c *oauthConnector) HandleCallback(s connector.Scopes, r *http.Request) (id
|
||||||
c.groupsKey = "groups"
|
c.groupsKey = "groups"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.preferredUsernameKey == "" {
|
||||||
|
c.preferredUsernameKey = "preferred_username"
|
||||||
|
}
|
||||||
|
|
||||||
identity.UserID, _ = userInfoResult[c.userIDKey].(string)
|
identity.UserID, _ = userInfoResult[c.userIDKey].(string)
|
||||||
identity.Username, _ = userInfoResult[c.userNameKey].(string)
|
identity.Username, _ = userInfoResult[c.userNameKey].(string)
|
||||||
identity.PreferredUsername, _ = userInfoResult["name"].(string)
|
identity.PreferredUsername, _ = userInfoResult[c.preferredUsernameKey].(string)
|
||||||
identity.Email, _ = userInfoResult["email"].(string)
|
identity.Email, _ = userInfoResult["email"].(string)
|
||||||
identity.EmailVerified, _ = userInfoResult["email_verified"].(bool)
|
identity.EmailVerified, _ = userInfoResult["email_verified"].(bool)
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@ func TestHandleCallBackForGroupsInUserInfo(t *testing.T) {
|
||||||
"name": "test-name",
|
"name": "test-name",
|
||||||
"user_id_key": "test-user-id",
|
"user_id_key": "test-user-id",
|
||||||
"user_name_key": "test-username",
|
"user_name_key": "test-username",
|
||||||
|
"preferred_username": "test-preferred-username",
|
||||||
"email": "test-email",
|
"email": "test-email",
|
||||||
"email_verified": true,
|
"email_verified": true,
|
||||||
"groups_key": []string{"admin-group", "user-group"},
|
"groups_key": []string{"admin-group", "user-group"},
|
||||||
|
@ -92,9 +93,9 @@ func TestHandleCallBackForGroupsInUserInfo(t *testing.T) {
|
||||||
expectEqual(t, len(identity.Groups), 2)
|
expectEqual(t, len(identity.Groups), 2)
|
||||||
expectEqual(t, identity.Groups[0], "admin-group")
|
expectEqual(t, identity.Groups[0], "admin-group")
|
||||||
expectEqual(t, identity.Groups[1], "user-group")
|
expectEqual(t, identity.Groups[1], "user-group")
|
||||||
expectEqual(t, identity.PreferredUsername, "test-name")
|
|
||||||
expectEqual(t, identity.UserID, "test-user-id")
|
expectEqual(t, identity.UserID, "test-user-id")
|
||||||
expectEqual(t, identity.Username, "test-username")
|
expectEqual(t, identity.Username, "test-username")
|
||||||
|
expectEqual(t, identity.PreferredUsername, "test-preferred-username")
|
||||||
expectEqual(t, identity.Email, "test-email")
|
expectEqual(t, identity.Email, "test-email")
|
||||||
expectEqual(t, identity.EmailVerified, true)
|
expectEqual(t, identity.EmailVerified, true)
|
||||||
}
|
}
|
||||||
|
@ -108,6 +109,7 @@ func TestHandleCallBackForGroupsInToken(t *testing.T) {
|
||||||
"name": "test-name",
|
"name": "test-name",
|
||||||
"user_id_key": "test-user-id",
|
"user_id_key": "test-user-id",
|
||||||
"user_name_key": "test-username",
|
"user_name_key": "test-username",
|
||||||
|
"preferred_username": "test-preferred-username",
|
||||||
"email": "test-email",
|
"email": "test-email",
|
||||||
"email_verified": true,
|
"email_verified": true,
|
||||||
}
|
}
|
||||||
|
@ -123,7 +125,7 @@ func TestHandleCallBackForGroupsInToken(t *testing.T) {
|
||||||
|
|
||||||
expectEqual(t, len(identity.Groups), 1)
|
expectEqual(t, len(identity.Groups), 1)
|
||||||
expectEqual(t, identity.Groups[0], "test-group")
|
expectEqual(t, identity.Groups[0], "test-group")
|
||||||
expectEqual(t, identity.PreferredUsername, "test-name")
|
expectEqual(t, identity.PreferredUsername, "test-preferred-username")
|
||||||
expectEqual(t, identity.UserID, "test-user-id")
|
expectEqual(t, identity.UserID, "test-user-id")
|
||||||
expectEqual(t, identity.Username, "test-username")
|
expectEqual(t, identity.Username, "test-username")
|
||||||
expectEqual(t, identity.Email, "test-email")
|
expectEqual(t, identity.Email, "test-email")
|
||||||
|
|
|
@ -35,15 +35,15 @@ connectors:
|
||||||
# scopes:
|
# scopes:
|
||||||
# - identity
|
# - identity
|
||||||
|
|
||||||
# Optional: Configurable keys for user id field look up
|
# Optional: Configurable keys for groups claim look up
|
||||||
# Default: groups
|
# Default: groups
|
||||||
# groupsKey:
|
# groupsKey:
|
||||||
|
|
||||||
# Optional: Configurable keys for name field look up
|
# Optional: Configurable keys for user ID claim look up
|
||||||
# Default: user_id
|
# Default: user_id
|
||||||
# userIDKey:
|
# userIDKey:
|
||||||
|
|
||||||
# Optional: Configurable keys for username field look up
|
# Optional: Configurable keys for preferred username claim look up
|
||||||
# Default: user_name
|
# Default: preferred_username
|
||||||
# userNameKey:
|
# preferredUsernameKey:
|
||||||
```
|
```
|
Reference in a new issue