Browse Source

Add GET /{realm}/groups and GET /{realm}/groups/{id}

master
harture 7 years ago
parent
commit
6f7e541456
  1. 24
      groups.go
  2. 4
      users.go

24
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
}

4
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
}

Loading…
Cancel
Save