diff --git a/api/users.go b/api/users.go index a643bd3..caaf5d2 100644 --- a/api/users.go +++ b/api/users.go @@ -9,17 +9,20 @@ import ( ) const ( - userPath = "/auth/admin/realms/:realm/users" - usersAdminExtensionAPIPath = "/auth/realms/:realmReq/api/admin/realms/:realm/users" - userCountPath = userPath + "/count" - userIDPath = userPath + "/:id" - userGroupsPath = userIDPath + "/groups" - userGroupIDPath = userGroupsPath + "/:groupId" - executeActionsEmailPath = userIDPath + "/execute-actions-email" - sendReminderEmailPath = "/auth/realms/:realm/onboarding/sendReminderEmail" - smsAPI = "/auth/realms/:realm/smsApi" - sendSmsCode = smsAPI + "/sendNewCode" - shadowUser = userIDPath + "/federated-identity/:provider" + userPath = "/auth/admin/realms/:realm/users" + adminExtensionAPIPath = "/auth/realms/:realmReq/api/admin/realms/:realm" + usersAdminExtensionAPIPath = adminExtensionAPIPath + "/users" + sendEmailAdminExtensionAPIPath = adminExtensionAPIPath + "/send-email" + userCountPath = userPath + "/count" + userIDPath = userPath + "/:id" + userGroupsPath = userIDPath + "/groups" + userGroupIDPath = userGroupsPath + "/:groupId" + executeActionsEmailPath = userIDPath + "/execute-actions-email" + sendReminderEmailPath = "/auth/realms/:realm/onboarding/sendReminderEmail" + smsAPI = "/auth/realms/:realm/smsApi" + sendSmsCode = smsAPI + "/sendNewCode" + sendSMSPath = smsAPI + "/sendSms" + shadowUser = userIDPath + "/federated-identity/:provider" ) // GetUsers returns a list of users, filtered according to the query parameters. @@ -124,3 +127,15 @@ func (c *Client) LinkShadowUser(accessToken string, reqRealmName string, userID _, err := c.post(accessToken, nil, url.Path(shadowUser), url.Param("realm", reqRealmName), url.Param("id", userID), url.Param("provider", provider), body.JSON(fedIDKC)) return err } + +// SendEmail sends an email to a user +func (c *Client) SendEmail(accessToken string, reqRealmName string, realmName string, emailRep keycloak.EmailRepresentation) error { + _, err := c.post(accessToken, nil, url.Path(sendEmailAdminExtensionAPIPath), url.Param("realmReq", reqRealmName), url.Param("realm", realmName), body.JSON(emailRep)) + return err +} + +// SendSMS sends an SMS to a user +func (c *Client) SendSMS(accessToken string, realmName string, smsRep keycloak.SMSRepresentation) error { + _, err := c.post(accessToken, nil, url.Path(sendSMSPath), url.Param("realm", realmName), body.JSON(smsRep)) + return err +} diff --git a/definitions.go b/definitions.go index aba9a58..a52b3db 100644 --- a/definitions.go +++ b/definitions.go @@ -757,3 +757,39 @@ type RecoveryCodeRepresentation struct { type ActivationCodeRepresentation struct { Code *string `json:"code,omitempty"` } + +// EmailRepresentation struct +type EmailRepresentation struct { + Recipient *string `json:"recipient,omitempty"` + Theming *EmailThemingRepresentation `json:"theming,omitempty"` + Attachments *[]AttachementRepresentation `json:"attachments,omitempty"` +} + +// EmailThemingRepresentation struct +type EmailThemingRepresentation struct { + SubjectKey *string `json:"subjectKey,omitempty"` + SubjectParameters *[]string `json:"subjectParameters,omitempty"` + Template *string `json:"template,omitempty"` + TemplateParameters *map[string]string `json:"templateParameters,omitempty"` + Locale *string `json:"locale,omitempty"` +} + +// AttachementRepresentation struct +type AttachementRepresentation struct { + Filename *string `json:"filename,omitempty"` + ContentType *string `json:"contentType,omitempty"` + Content *string `json:"content,omitempty"` +} + +// SMSRepresentation struct +type SMSRepresentation struct { + MSISDN *string `json:"msisdn,omitempty"` + Theming *SMSThemingRepresentation `json:"theming,omitempty"` +} + +// SMSThemingRepresentation struct +type SMSThemingRepresentation struct { + MessageKey *string `json:"messageKey,omitempty"` + MessageParameters *[]string `json:"messageParameters,omitempty"` + Locale *string `json:"locale,omitempty"` +}