forked from mystiq/dex
default to preferred_username claim
Signed-off-by: Rui Yang <ruiya@vmware.com>
This commit is contained in:
parent
9a4e0fcd00
commit
d9afb7e59c
2 changed files with 23 additions and 21 deletions
|
@ -55,8 +55,8 @@ type Config struct {
|
||||||
// Configurable key which contains the user name claim
|
// Configurable key which contains the user name claim
|
||||||
UserNameKey string `json:"userNameKey"`
|
UserNameKey string `json:"userNameKey"`
|
||||||
|
|
||||||
// Configurable key which contains the username claims
|
// Configurable key which contains the preferred username claims
|
||||||
PreferredUsernameKey string `json:"preferredUsernameKey"` // defaults to "username"
|
PreferredUsernameKey string `json:"preferredUsernameKey"`
|
||||||
|
|
||||||
// PromptType will be used fot the prompt parameter (when offline_access, by default prompt=consent)
|
// PromptType will be used fot the prompt parameter (when offline_access, by default prompt=consent)
|
||||||
PromptType string `json:"promptType"`
|
PromptType string `json:"promptType"`
|
||||||
|
@ -302,9 +302,9 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I
|
||||||
hostedDomain, _ := claims["hd"].(string)
|
hostedDomain, _ := claims["hd"].(string)
|
||||||
|
|
||||||
if c.preferredUsernameKey == "" {
|
if c.preferredUsernameKey == "" {
|
||||||
c.preferredUsernameKey = "username"
|
c.preferredUsernameKey = "preferred_username"
|
||||||
}
|
}
|
||||||
username, _ := claims[c.preferredUsernameKey].(string)
|
preferredUsername, _ := claims[c.preferredUsernameKey].(string)
|
||||||
|
|
||||||
if len(c.hostedDomains) > 0 {
|
if len(c.hostedDomains) > 0 {
|
||||||
found := false
|
found := false
|
||||||
|
@ -332,7 +332,7 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I
|
||||||
identity = connector.Identity{
|
identity = connector.Identity{
|
||||||
UserID: idToken.Subject,
|
UserID: idToken.Subject,
|
||||||
Username: name,
|
Username: name,
|
||||||
PreferredUsername: username,
|
PreferredUsername: preferredUsername,
|
||||||
Email: email,
|
Email: email,
|
||||||
EmailVerified: emailVerified,
|
EmailVerified: emailVerified,
|
||||||
ConnectorData: connData,
|
ConnectorData: connData,
|
||||||
|
|
|
@ -85,16 +85,18 @@ func TestHandleCallback(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "withUserIDKey",
|
name: "withUserIDKey",
|
||||||
userIDKey: "name",
|
userIDKey: "name",
|
||||||
expectUserID: "namevalue",
|
expectUserID: "namevalue",
|
||||||
expectUserName: "namevalue",
|
expectUserName: "namevalue",
|
||||||
expectedEmailField: "emailvalue",
|
expectPreferredUsername: "usernamevalue",
|
||||||
|
expectedEmailField: "emailvalue",
|
||||||
token: map[string]interface{}{
|
token: map[string]interface{}{
|
||||||
"sub": "subvalue",
|
"sub": "subvalue",
|
||||||
"name": "namevalue",
|
"name": "namevalue",
|
||||||
"email": "emailvalue",
|
"preferred_username": "usernamevalue",
|
||||||
"email_verified": true,
|
"email": "emailvalue",
|
||||||
|
"email_verified": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -112,17 +114,17 @@ func TestHandleCallback(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "withPreferredUsernameKey",
|
name: "withPreferredUsernameKey",
|
||||||
preferredUsernameKey: "preferred_username",
|
preferredUsernameKey: "username_key",
|
||||||
expectUserID: "subvalue",
|
expectUserID: "subvalue",
|
||||||
expectUserName: "namevalue",
|
expectUserName: "namevalue",
|
||||||
expectPreferredUsername: "usernamevalue",
|
expectPreferredUsername: "username_value",
|
||||||
expectedEmailField: "emailvalue",
|
expectedEmailField: "emailvalue",
|
||||||
token: map[string]interface{}{
|
token: map[string]interface{}{
|
||||||
"sub": "subvalue",
|
"sub": "subvalue",
|
||||||
"name": "namevalue",
|
"name": "namevalue",
|
||||||
"preferred_username": "usernamevalue",
|
"username_key": "username_value",
|
||||||
"email": "emailvalue",
|
"email": "emailvalue",
|
||||||
"email_verified": true,
|
"email_verified": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue