From ba54607e92dcd9441335b69d2fd3de16b4c9a556 Mon Sep 17 00:00:00 2001 From: Remco Brink Date: Mon, 19 May 2025 20:49:11 +0200 Subject: [PATCH] Refactor group scope handling to support both strings and array (#244) Refactor group scope handling to support both string and array --- .../authentication/Authentication.go | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/webserver/authentication/Authentication.go b/internal/webserver/authentication/Authentication.go index 41232f1..2d08413 100644 --- a/internal/webserver/authentication/Authentication.go +++ b/internal/webserver/authentication/Authentication.go @@ -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