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
|
||||
userIDKey string
|
||||
userNameKey string
|
||||
preferredUsernameKey string
|
||||
httpClient *http.Client
|
||||
logger log.Logger
|
||||
}
|
||||
|
@ -50,6 +51,7 @@ type Config struct {
|
|||
GroupsKey string `json:"groupsKey"`
|
||||
UserIDKey string `json:"userIDKey"`
|
||||
UserNameKey string `json:"userNameKey"`
|
||||
PreferredUsernameKey string `json:"preferredUsernameKey"`
|
||||
RootCAs []string `json:"rootCAs"`
|
||||
InsecureSkipVerify bool `json:"insecureSkipVerify"`
|
||||
}
|
||||
|
@ -182,9 +184,13 @@ func (c *oauthConnector) HandleCallback(s connector.Scopes, r *http.Request) (id
|
|||
c.groupsKey = "groups"
|
||||
}
|
||||
|
||||
if c.preferredUsernameKey == "" {
|
||||
c.preferredUsernameKey = "preferred_username"
|
||||
}
|
||||
|
||||
identity.UserID, _ = userInfoResult[c.userIDKey].(string)
|
||||
identity.Username, _ = userInfoResult[c.userNameKey].(string)
|
||||
identity.PreferredUsername, _ = userInfoResult["name"].(string)
|
||||
identity.PreferredUsername, _ = userInfoResult[c.preferredUsernameKey].(string)
|
||||
identity.Email, _ = userInfoResult["email"].(string)
|
||||
identity.EmailVerified, _ = userInfoResult["email_verified"].(bool)
|
||||
|
||||
|
|
|
@ -74,6 +74,7 @@ func TestHandleCallBackForGroupsInUserInfo(t *testing.T) {
|
|||
"name": "test-name",
|
||||
"user_id_key": "test-user-id",
|
||||
"user_name_key": "test-username",
|
||||
"preferred_username": "test-preferred-username",
|
||||
"email": "test-email",
|
||||
"email_verified": true,
|
||||
"groups_key": []string{"admin-group", "user-group"},
|
||||
|
@ -92,9 +93,9 @@ func TestHandleCallBackForGroupsInUserInfo(t *testing.T) {
|
|||
expectEqual(t, len(identity.Groups), 2)
|
||||
expectEqual(t, identity.Groups[0], "admin-group")
|
||||
expectEqual(t, identity.Groups[1], "user-group")
|
||||
expectEqual(t, identity.PreferredUsername, "test-name")
|
||||
expectEqual(t, identity.UserID, "test-user-id")
|
||||
expectEqual(t, identity.Username, "test-username")
|
||||
expectEqual(t, identity.PreferredUsername, "test-preferred-username")
|
||||
expectEqual(t, identity.Email, "test-email")
|
||||
expectEqual(t, identity.EmailVerified, true)
|
||||
}
|
||||
|
@ -108,6 +109,7 @@ func TestHandleCallBackForGroupsInToken(t *testing.T) {
|
|||
"name": "test-name",
|
||||
"user_id_key": "test-user-id",
|
||||
"user_name_key": "test-username",
|
||||
"preferred_username": "test-preferred-username",
|
||||
"email": "test-email",
|
||||
"email_verified": true,
|
||||
}
|
||||
|
@ -123,7 +125,7 @@ func TestHandleCallBackForGroupsInToken(t *testing.T) {
|
|||
|
||||
expectEqual(t, len(identity.Groups), 1)
|
||||
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.Username, "test-username")
|
||||
expectEqual(t, identity.Email, "test-email")
|
||||
|
|
|
@ -35,15 +35,15 @@ connectors:
|
|||
# scopes:
|
||||
# - identity
|
||||
|
||||
# Optional: Configurable keys for user id field look up
|
||||
# Optional: Configurable keys for groups claim look up
|
||||
# Default: groups
|
||||
# groupsKey:
|
||||
|
||||
# Optional: Configurable keys for name field look up
|
||||
# Optional: Configurable keys for user ID claim look up
|
||||
# Default: user_id
|
||||
# userIDKey:
|
||||
|
||||
# Optional: Configurable keys for username field look up
|
||||
# Default: user_name
|
||||
# userNameKey:
|
||||
# Optional: Configurable keys for preferred username claim look up
|
||||
# Default: preferred_username
|
||||
# preferredUsernameKey:
|
||||
```
|
Reference in a new issue