From 26fc713de38365d149d73ef560fced3429ddde05 Mon Sep 17 00:00:00 2001 From: sispeo <42068883+fperot74@users.noreply.github.com> Date: Wed, 10 Apr 2019 11:00:09 +0200 Subject: [PATCH] Add endpoints from new module keycloak-rest-api-extensions --- integration/integration.go | 13 ++++++++++++- users.go | 24 +++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/integration/integration.go b/integration/integration.go index 8a9a8db..e485a0b 100644 --- a/integration/integration.go +++ b/integration/integration.go @@ -15,7 +15,7 @@ const ( user = "version" ) -// This should be oncverted into +// This should be converted into // GetClient(accessToken string, realmName, idClient string) (kc.ClientRepresentation, error) // GetClientRoleMappings(accessToken string, realmName, userID, clientID string) ([]kc.RoleRepresentation, error) // AddClientRolesToUserRoleMapping(accessToken string, realmName, userID, clientID string, roles []kc.RoleRepresentation) error @@ -287,6 +287,17 @@ func main() { } } fmt.Println("User updated.") + // Check credentials + { + tstRealmReq := "master" + var creds, err = client.GetCredentialsForUser(accessToken, tstRealmReq, tstRealm, userID) + if err != nil { + log.Fatalf("could not get credentials: %v", err) + } + if len(creds) != 0 { + log.Fatalf("Maria should not have credentials") + } + } } // Delete user. diff --git a/users.go b/users.go index b3c6272..23dd3f5 100644 --- a/users.go +++ b/users.go @@ -8,11 +8,13 @@ import ( ) const ( - userPath = "/auth/admin/realms/:realm/users" - userCountPath = userPath + "/count" - userIDPath = userPath + "/:id" - resetPasswordPath = userIDPath + "/reset-password" - sendVerifyEmailPath = userIDPath + "/send-verify-email" + userPath = "/auth/admin/realms/:realm/users" + userCountPath = userPath + "/count" + userIDPath = userPath + "/:id" + resetPasswordPath = userIDPath + "/reset-password" + sendVerifyEmailPath = userIDPath + "/send-verify-email" + getCredentialsForUserPath = "/auth/realms/:realmReq/api/realms/:realm/users/:id/credentials" + deleteCredentialsForUserPath = getCredentialsForUserPath + "/:credid" ) // GetUsers returns a list of users, filtered according to the query parameters. @@ -74,3 +76,15 @@ func (c *Client) SendVerifyEmail(accessToken string, realmName string, userID st return c.put(accessToken, plugins...) } + +// GetCredentialsForUser gets the credential list for a user +func (c *Client) GetCredentialsForUser(accessToken string, realmReq, realmName string, userID string) ([]CredentialRepresentation, error) { + var resp = []CredentialRepresentation{} + var err = c.get(accessToken, &resp, url.Path(getCredentialsForUserPath), url.Param("realmReq", realmReq), url.Param("realm", realmName), url.Param("id", userID)) + return resp, err +} + +// DeleteCredentialsForUser remove credentials for a user +func (c *Client) DeleteCredentialsForUser(accessToken string, realmReq, realmName string, userID string, credentialID string) error { + return c.delete(accessToken, url.Path(deleteCredentialsForUserPath), url.Param("realmReq", realmReq), url.Param("realm", realmName), url.Param("id", userID), url.Param("credid", userID)) +}