Compare commits

...

2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
4c3be9b3c6 Fix custom SAML attribute values not resolving user fields
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
2026-03-04 14:07:45 +00:00
copilot-swe-agent[bot]
dec19a908c Initial plan 2026-03-04 13:58:35 +00:00

View File

@@ -1016,9 +1016,34 @@ func replaceAttributeValue(user *User, value string) []string {
valueList = replaceAttributeValues("$user.id", user.Id, valueList)
valueList = replaceAttributeValues("$user.phone", user.Phone, valueList)
// If no template substitution occurred, try to resolve value as a user field JSON tag name
if len(valueList) == 1 && valueList[0] == value {
if fieldValue, found := getUserStringFieldByJsonTag(user, value); found {
return []string{fieldValue}
}
}
return valueList
}
// getUserStringFieldByJsonTag looks up a string field on the User struct by its JSON tag name.
// Returns the field value and true if a matching exported string field is found, or ("", false) otherwise.
func getUserStringFieldByJsonTag(user *User, jsonTag string) (string, bool) {
userType := reflect.TypeOf(*user)
userValue := reflect.ValueOf(*user)
for i := 0; i < userType.NumField(); i++ {
field := userType.Field(i)
if !field.IsExported() {
continue
}
tag := strings.Split(field.Tag.Get("json"), ",")[0]
if tag == jsonTag && userValue.Field(i).Kind() == reflect.String {
return userValue.Field(i).String(), true
}
}
return "", false
}
func replaceAttributeValues(val string, replaceVal string, values []string) []string {
var newValues []string
for _, value := range values {