diff --git a/users.go b/users.go index 05c8561..34d0b67 100644 --- a/users.go +++ b/users.go @@ -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" ) @@ -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. @@ -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 +}