diff --git a/groups.go b/groups.go new file mode 100644 index 0000000..7f171a3 --- /dev/null +++ b/groups.go @@ -0,0 +1,24 @@ +package keycloak + +import ( + "gopkg.in/h2non/gentleman.v2/plugins/url" +) + +const ( + groupsPath = "/auth/admin/realms/:realm/groups" + groupByIDPath = "/auth/admin/realms/:realm/groups/:id" +) + +// GetGroups gets all groups for the realm +func (c *Client) GetGroups(accessToken string, realmName string) ([]GroupRepresentation, error) { + var resp = []GroupRepresentation{} + var err = c.get(accessToken, &resp, url.Path(groupsPath), url.Param("realm", realmName)) + return resp, err +} + +// GetGroup gets a specific group’s representation +func (c *Client) GetGroup(accessToken string, realmName string, groupID string) (GroupRepresentation, error) { + var resp = GroupRepresentation{} + var err = c.get(accessToken, &resp, url.Path(groupByIDPath), url.Param("realm", realmName), url.Param("id", groupID)) + return resp, err +} diff --git a/users.go b/users.go index 9ca4931..fa0bdae 100644 --- a/users.go +++ b/users.go @@ -11,7 +11,7 @@ const ( userPath = "/auth/admin/realms/:realm/users" userCountPath = userPath + "/count" userIDPath = userPath + "/:id" - groupsPath = userIDPath + "/groups" + userGroupsPath = userIDPath + "/groups" resetPasswordPath = userIDPath + "/reset-password" sendVerifyEmailPath = userIDPath + "/send-verify-email" executeActionsEmailPath = userIDPath + "/execute-actions-email" @@ -56,7 +56,7 @@ func (c *Client) GetUser(accessToken string, realmName, userID string) (UserRepr // GetGroupsOfUser get the groups of the user. func (c *Client) GetGroupsOfUser(accessToken string, realmName, userID string) ([]GroupRepresentation, error) { var resp = []GroupRepresentation{} - var err = c.get(accessToken, &resp, url.Path(groupsPath), url.Param("realm", realmName), url.Param("id", userID)) + var err = c.get(accessToken, &resp, url.Path(userGroupsPath), url.Param("realm", realmName), url.Param("id", userID)) return resp, err }