|
|
|
@ -19,39 +19,44 @@ const ( |
|
|
|
accountMoveAfterPath = accountCredentialIDPath + "/moveAfter/:previousCredentialID" |
|
|
|
) |
|
|
|
|
|
|
|
var ( |
|
|
|
hdrAcceptJSON = headers.Set("Accept", "application/json") |
|
|
|
hdrContentTypeTextPlain = headers.Set("Content-Type", "text/plain") |
|
|
|
) |
|
|
|
|
|
|
|
// GetCredentials returns the list of credentials of the user
|
|
|
|
func (c *AccountClient) GetCredentials(accessToken string, realmName string) ([]keycloak.CredentialRepresentation, error) { |
|
|
|
var resp = []keycloak.CredentialRepresentation{} |
|
|
|
var err = c.client.get(accessToken, &resp, url.Path(accountCredentialsPath), url.Param("realm", realmName), headers.Set("Accept", "application/json")) |
|
|
|
var err = c.client.get(accessToken, &resp, url.Path(accountCredentialsPath), url.Param("realm", realmName), hdrAcceptJSON) |
|
|
|
return resp, err |
|
|
|
} |
|
|
|
|
|
|
|
// GetCredentialRegistrators returns list of credentials types available for the user
|
|
|
|
func (c *AccountClient) GetCredentialRegistrators(accessToken string, realmName string) ([]string, error) { |
|
|
|
var resp = []string{} |
|
|
|
var err = c.client.get(accessToken, &resp, url.Path(accountCredentialsRegistratorsPath), url.Param("realm", realmName), headers.Set("Accept", "application/json")) |
|
|
|
var err = c.client.get(accessToken, &resp, url.Path(accountCredentialsRegistratorsPath), url.Param("realm", realmName), hdrAcceptJSON) |
|
|
|
return resp, err |
|
|
|
} |
|
|
|
|
|
|
|
// UpdateLabelCredential updates the label of credential
|
|
|
|
func (c *AccountClient) UpdateLabelCredential(accessToken string, realmName string, credentialID string, label string) error { |
|
|
|
return c.client.put(accessToken, url.Path(accountCredentialLabelPath), url.Param("realm", realmName), url.Param("credentialID", credentialID), body.String(label), headers.Set("Accept", "application/json"), headers.Set("Content-Type", "text/plain")) |
|
|
|
return c.client.put(accessToken, url.Path(accountCredentialLabelPath), url.Param("realm", realmName), url.Param("credentialID", credentialID), body.String(label), hdrAcceptJSON, hdrContentTypeTextPlain) |
|
|
|
} |
|
|
|
|
|
|
|
// DeleteCredential deletes the credential
|
|
|
|
func (c *AccountClient) DeleteCredential(accessToken string, realmName string, credentialID string) error { |
|
|
|
return c.client.delete(accessToken, url.Path(accountCredentialIDPath), url.Param("realm", realmName), url.Param("credentialID", credentialID), headers.Set("Accept", "application/json")) |
|
|
|
return c.client.delete(accessToken, url.Path(accountCredentialIDPath), url.Param("realm", realmName), url.Param("credentialID", credentialID), hdrAcceptJSON) |
|
|
|
} |
|
|
|
|
|
|
|
// MoveToFirst moves the credential at the top of the list
|
|
|
|
func (c *AccountClient) MoveToFirst(accessToken string, realmName string, credentialID string) error { |
|
|
|
_, err := c.client.post(accessToken, nil, url.Path(accountMoveFirstPath), url.Param("realm", realmName), url.Param("credentialID", credentialID), headers.Set("Accept", "application/json")) |
|
|
|
_, err := c.client.post(accessToken, nil, url.Path(accountMoveFirstPath), url.Param("realm", realmName), url.Param("credentialID", credentialID), hdrAcceptJSON) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
// MoveAfter moves the credential after the specified one into the list
|
|
|
|
func (c *AccountClient) MoveAfter(accessToken string, realmName string, credentialID string, previousCredentialID string) error { |
|
|
|
_, err := c.client.post(accessToken, nil, url.Path(accountMoveAfterPath), url.Param("realm", realmName), url.Param("credentialID", credentialID), url.Param("previousCredentialID", previousCredentialID), headers.Set("Accept", "application/json")) |
|
|
|
_, err := c.client.post(accessToken, nil, url.Path(accountMoveAfterPath), url.Param("realm", realmName), url.Param("credentialID", credentialID), url.Param("previousCredentialID", previousCredentialID), hdrAcceptJSON) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
@ -65,7 +70,7 @@ func (c *AccountClient) UpdatePassword(accessToken, realm, currentPassword, newP |
|
|
|
// GetAccount provides the user's information
|
|
|
|
func (c *AccountClient) GetAccount(accessToken string, realm string) (keycloak.UserRepresentation, error) { |
|
|
|
var resp = keycloak.UserRepresentation{} |
|
|
|
var err = c.client.get(accessToken, &resp, url.Path(accountExtensionAPIPath), url.Param("realm", realm), headers.Set("Accept", "application/json")) |
|
|
|
var err = c.client.get(accessToken, &resp, url.Path(accountExtensionAPIPath), url.Param("realm", realm), hdrAcceptJSON) |
|
|
|
return resp, err |
|
|
|
} |
|
|
|
|
|
|
|
@ -77,7 +82,7 @@ func (c *AccountClient) UpdateAccount(accessToken string, realm string, user key |
|
|
|
|
|
|
|
// DeleteAccount delete current user
|
|
|
|
func (c *AccountClient) DeleteAccount(accessToken string, realmName string) error { |
|
|
|
return c.client.delete(accessToken, url.Path(accountExtensionAPIPath), url.Param("realm", realmName), headers.Set("Accept", "application/json")) |
|
|
|
return c.client.delete(accessToken, url.Path(accountExtensionAPIPath), url.Param("realm", realmName), hdrAcceptJSON) |
|
|
|
} |
|
|
|
|
|
|
|
// ExecuteActionsEmail send an email with required actions to the user
|
|
|
|
|