Refactor group scope handling to support both strings and array (#244)

Refactor group scope handling to support both string and array
This commit is contained in:
Remco Brink
2025-05-19 20:49:11 +02:00
committed by GitHub
parent d4bfad90c3
commit ba54607e92

View File

@@ -171,17 +171,17 @@ func extractOauthGroups(userInfo OAuthUserClaims, groupScope string) ([]string,
return nil, fmt.Errorf("claim %s was not passed on", groupScope)
}
// Convert the interface{} to a []string
if groupsInterface == nil {
return []string{}, nil
}
groupsCast, ok := groupsInterface.([]any)
if !ok {
return nil, fmt.Errorf("scope %s is not an array", groupScope)
}
// Handle both string and array cases
var groups []string
for _, group := range groupsCast {
groups = append(groups, group.(string))
switch v := groupsInterface.(type) {
case string:
groups = append(groups, v)
case []any:
for _, group := range v {
groups = append(groups, group.(string))
}
default:
return nil, fmt.Errorf("scope %s is not a valid type", groupScope)
}
return groups, nil