Skip to content

Commit

Permalink
[CLOUDTRUST-2997] Add consent methods from keycloak-sms module
Browse files Browse the repository at this point in the history
  • Loading branch information
fperot74 committed Mar 2, 2021
1 parent f3e5b53 commit ecf487d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
30 changes: 15 additions & 15 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

[[constraint]]
name = "github.com/cloudtrust/common-service"
version = "2.3.3"
version = "2.3.4"

[[constraint]]
name = "github.com/pkg/errors"
Expand Down
2 changes: 2 additions & 0 deletions api/keycloak_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ func (c *Client) get(accessToken string, data interface{}, plugins ...plugin.Plu
return keycloak.ClientDetailedError{HTTPStatus: http.StatusUnauthorized, Message: string(resp.Bytes())}
case resp.StatusCode >= 400:
return treatErrorStatus(resp)
case resp.StatusCode == 204:
return nil
case resp.StatusCode >= 200:
switch resp.Header.Get("Content-Type") {
case "application/json":
Expand Down
13 changes: 13 additions & 0 deletions api/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
sendReminderEmailPath = "/auth/realms/:realm/onboarding/sendReminderEmail"
smsAPI = "/auth/realms/:realm/smsApi"
sendSmsCode = smsAPI + "/sendNewCode"
sendSmsConsentCode = smsAPI + "/users/:userId/consent"
checkSmsConsentCode = sendSmsConsentCode + "/:consent"
sendSMSPath = smsAPI + "/sendSms"
shadowUser = userIDPath + "/federated-identity/:provider"
)
Expand Down Expand Up @@ -140,3 +142,14 @@ func (c *Client) SendSMS(accessToken string, realmName string, smsRep keycloak.S
_, err := c.post(accessToken, nil, url.Path(sendSMSPath), url.Param("realm", realmName), body.JSON(smsRep))
return err
}

// CheckConsentCodeSMS checks a consent code previously sent by SMS to a user
func (c *Client) CheckConsentCodeSMS(accessToken string, realmName string, userID string, consentCode string) error {
return c.get(accessToken, nil, url.Path(checkSmsConsentCode), url.Param("realm", realmName), url.Param("userId", userID), url.Param("consent", consentCode))
}

// SendConsentCodeSMS sends an SMS to a user with a consent code
func (c *Client) SendConsentCodeSMS(accessToken string, realmName string, userID string) error {
_, err := c.post(accessToken, nil, url.Path(sendSmsConsentCode), url.Param("realm", realmName), url.Param("userId", userID))
return err
}

0 comments on commit ecf487d

Please sign in to comment.