Skip to content

Commit b56a616

Browse files
claims: add JSON serialization for interface arrays
Implement handling of []interface{} types by serializing them to JSON string format. This allows arrays like ["role1", "role2"] to be converted to string representations for further processing.
1 parent 59cef11 commit b56a616

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/auth/claims.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,23 @@ func getClaim(all map[string]interface{}, claim string) interface{} {
152152
// stringifyClaimValue will try to convert the provided raw value into a
153153
// faithful string representation of that value per these rules:
154154
//
155-
// - strings => unchanged
156-
// - bool => "true" / "false"
157-
// - json.Number => String()
158-
// - float32/64 => truncated to int64 and then formatted as an ascii string
159-
// - intXX/uintXX => casted to int64 and then formatted as an ascii string
155+
// - []interface{} => marshaling to JSON string
156+
// - strings => unchanged
157+
// - bool => "true" / "false"
158+
// - json.Number => String()
159+
// - float32/64 => truncated to int64 and then formatted as an ascii string
160+
// - intXX/uintXX => casted to int64 and then formatted as an ascii string
160161
//
161162
// If successful the string value and true are returned. otherwise an empty
162163
// string and false are returned.
163164
func stringifyClaimValue(rawValue interface{}) (string, bool) {
164165
switch v := rawValue.(type) {
166+
case []interface{}:
167+
b, err := json.Marshal(v)
168+
if err != nil {
169+
return "", false
170+
}
171+
return string(b), true
165172
case string:
166173
return v, true
167174
case bool:

0 commit comments

Comments
 (0)