Browse Source

[SCPR-32] Add methods to send email and SMS (#73)

Co-authored-by: Lorenceau Pablo <pablo.lorenceau@elca.ch>
master
pablo-lo 5 years ago
committed by GitHub
parent
commit
5b5193e6be
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      api/users.go
  2. 36
      definitions.go

17
api/users.go

@ -10,7 +10,9 @@ import (
const ( const (
userPath = "/auth/admin/realms/:realm/users" userPath = "/auth/admin/realms/:realm/users"
usersAdminExtensionAPIPath = "/auth/realms/:realmReq/api/admin/realms/:realm/users" adminExtensionAPIPath = "/auth/realms/:realmReq/api/admin/realms/:realm"
usersAdminExtensionAPIPath = adminExtensionAPIPath + "/users"
sendEmailAdminExtensionAPIPath = adminExtensionAPIPath + "/send-email"
userCountPath = userPath + "/count" userCountPath = userPath + "/count"
userIDPath = userPath + "/:id" userIDPath = userPath + "/:id"
userGroupsPath = userIDPath + "/groups" userGroupsPath = userIDPath + "/groups"
@ -19,6 +21,7 @@ const (
sendReminderEmailPath = "/auth/realms/:realm/onboarding/sendReminderEmail" sendReminderEmailPath = "/auth/realms/:realm/onboarding/sendReminderEmail"
smsAPI = "/auth/realms/:realm/smsApi" smsAPI = "/auth/realms/:realm/smsApi"
sendSmsCode = smsAPI + "/sendNewCode" sendSmsCode = smsAPI + "/sendNewCode"
sendSMSPath = smsAPI + "/sendSms"
shadowUser = userIDPath + "/federated-identity/:provider" shadowUser = userIDPath + "/federated-identity/:provider"
) )
@ -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)) _, 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 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
}

36
definitions.go

@ -757,3 +757,39 @@ type RecoveryCodeRepresentation struct {
type ActivationCodeRepresentation struct { type ActivationCodeRepresentation struct {
Code *string `json:"code,omitempty"` 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"`
}

Loading…
Cancel
Save