Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GroupList Retrieval by RoleName #299

Merged
merged 7 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,22 @@ func (client *gocloak) GetGroups(ctx context.Context, token, realm string, param
return result, nil
}

// GetGroupsByRole gets groups assigned with a specific role of a realm
func (client *gocloak) GetGroupsByRole(ctx context.Context, token, realm string, roleName string) ([]*Group, error) {
const errMessage = "could not get groups"

var result []*Group
resp, err := client.getRequestWithBearerAuth(ctx, token).
SetResult(&result).
Get(fmt.Sprintf("%s/%s/%s", client.getAdminRealmURL(realm, "roles"), roleName, "groups"))

if err := checkForError(resp, err, errMessage); err != nil {
return nil, err
}

return result, nil
}

// GetGroupsCount gets the groups count in the realm
func (client *gocloak) GetGroupsCount(ctx context.Context, token, realm string, params GetGroupsParams) (int, error) {
const errMessage = "could not get groups count"
Expand Down
2 changes: 2 additions & 0 deletions gocloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ type GoCloak interface {
RemoveDefaultGroup(ctx context.Context, accessToken, realm, groupID string) error
// GetGroups gets all groups of the given realm
GetGroups(ctx context.Context, accessToken, realm string, params GetGroupsParams) ([]*Group, error)
// GetGroupsByRole gets groups with specified roles assigned of given realm
GetGroupsByRole(ctx context.Context, accessToken, realm string, roleName string) ([]*Group, error)
// GetGroupsCount gets groups count of the given realm
GetGroupsCount(ctx context.Context, token, realm string, params GetGroupsParams) (int, error)
// GetGroup gets the given group
Expand Down