From fec0d9efa6d0bcb06e3f475fb4672790ec16fee0 Mon Sep 17 00:00:00 2001 From: tomqwpl <42344626+tomqwpl@users.noreply.github.com> Date: Thu, 1 Feb 2024 14:40:03 +0000 Subject: [PATCH] Add support for users-management-permissions get/put (#463) * Add support for permission_resource_format/permission_resource_matching_uri * lint error * Add support for users-management-permissions --- client.go | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 9679096..ccff45f 100644 --- a/client.go +++ b/client.go @@ -508,7 +508,6 @@ func (g *GoCloak) GetRequestingPartyPermissions(ctx context.Context, token, real if err := checkForError(resp, err, errMessage); err != nil { return nil, err } - return &res, nil } @@ -4304,3 +4303,38 @@ func (g *GoCloak) RevokeToken(ctx context.Context, realm, clientID, clientSecret return checkForError(resp, err, errMessage) } + +// UpdateUsersManagementPermissions updates the management permissions for users +func (g *GoCloak) UpdateUsersManagementPermissions(ctx context.Context, accessToken, realm string, managementPermissions ManagementPermissionRepresentation) (*ManagementPermissionRepresentation, error) { + const errMessage = "could not update users management permissions" + + var result ManagementPermissionRepresentation + + resp, err := g.GetRequestWithBearerAuth(ctx, accessToken). + SetResult(&result). + SetBody(managementPermissions). + Put(g.getAdminRealmURL(realm, "users-management-permissions")) + + if err := checkForError(resp, err, errMessage); err != nil { + return nil, err + } + + return &result, nil +} + +// GetUsersManagementPermissions returns the management permissions for users +func (g *GoCloak) GetUsersManagementPermissions(ctx context.Context, accessToken, realm string) (*ManagementPermissionRepresentation, error) { + const errMessage = "could not get users management permissions" + + var result ManagementPermissionRepresentation + + resp, err := g.GetRequestWithBearerAuth(ctx, accessToken). + SetResult(&result). + Get(g.getAdminRealmURL(realm, "users-management-permissions")) + + if err := checkForError(resp, err, errMessage); err != nil { + return nil, err + } + + return &result, nil +}