Skip to content

Commit

Permalink
[Cloudtrust-1617] Get/Update account API
Browse files Browse the repository at this point in the history
  • Loading branch information
harture authored Sep 4, 2019
1 parent d6c41c2 commit 509d5f3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"gopkg.in/h2non/gentleman.v2/plugins/body"
"gopkg.in/h2non/gentleman.v2/plugins/headers"
"gopkg.in/h2non/gentleman.v2/plugins/url"
)

Expand All @@ -22,6 +23,7 @@ const (
getCredentialsForUserPath = usersAdminExtensionApiPath + "/:id/credentials"
deleteCredentialsForUserPath = getCredentialsForUserPath + "/:credid"
accountPasswordPath = "/auth/realms/master/api/account/realms/:realm/credentials/password"
accountPath = "/auth/realms/master/api/account/realms/:realm/"
)

// GetUsers returns a list of users, filtered according to the query parameters.
Expand Down Expand Up @@ -145,3 +147,16 @@ func (c *Client) UpdatePassword(accessToken, realm, currentPassword, newPassword
var m = map[string]string{"currentPassword": currentPassword, "newPassword": newPassword, "confirmation": confirmPassword}
return c.post(accessToken, nil, url.Path(accountPasswordPath), url.Param("realm", realm), body.JSON(m))
}

// GetAccount provides the user's information
func (c *Client) GetAccount(accessToken string, realm string) (UserRepresentation, error) {
var resp = UserRepresentation{}
var err = c.get(accessToken, &resp, url.Path(accountPath), url.Param("realm", realm), headers.Set("Accept", "application/json"))
return resp, err
}

// UpdateAccount updates the user's information
func (c *Client) UpdateAccount(accessToken string, realm string, user UserRepresentation) error {
_, err := c.post(accessToken, nil, url.Path(accountPath), url.Param("realm", realm), body.JSON(user))
return err
}

0 comments on commit 509d5f3

Please sign in to comment.