Skip to content

Commit

Permalink
add method ExecuteActionsEmail to users service
Browse files Browse the repository at this point in the history
  • Loading branch information
zemirco committed Feb 26, 2022
1 parent af8e857 commit dd219a9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
24 changes: 24 additions & 0 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,27 @@ func (s *UsersService) SendVerifyEmail(ctx context.Context, realm, userID string

return s.keycloak.Do(ctx, req, nil)
}

// ExecuteActionsEmailOptions ...
type ExecuteActionsEmailOptions struct {
ClientID string `url:"client_id,omitempty"`
Lifespan int `url:"lifespan,omitempty"`
RedirectUri string `url:"redirect_uri,omitempty"`
}

// ExecuteActionsEmail sends an update account email to the user.
// An email contains a link the user can click to perform a set of required actions.
func (s *UsersService) ExecuteActionsEmail(ctx context.Context, realm, userID string, opts *ExecuteActionsEmailOptions, actions []string) (*http.Response, error) {
u := fmt.Sprintf("admin/realms/%s/users/%s/execute-actions-email", realm, userID)
u, err := addOptions(u, opts)
if err != nil {
return nil, err
}

req, err := s.keycloak.NewRequest(http.MethodPut, u, actions)
if err != nil {
return nil, err
}

return s.keycloak.Do(ctx, req, nil)
}
22 changes: 22 additions & 0 deletions users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,25 @@ func TestUsersService_SendVerifyEmail(t *testing.T) {
t.Errorf("got: %d, want: %d", res.StatusCode, http.StatusNoContent)
}
}

func TestUsersService_ExecuteActionsEmail(t *testing.T) {
k := client(t)

realm := "first"

createRealm(t, k, realm)
userID := createUser(t, k, realm, "user")

opts := &ExecuteActionsEmailOptions{
Lifespan: 1000,
}

res, err := k.Users.ExecuteActionsEmail(context.Background(), realm, userID, opts, []string{"UPDATE_PROFILE"})
if err != nil {
t.Errorf("Users.ExecuteActionsEmail returned error: %v", err)
}

if res.StatusCode != http.StatusNoContent {
t.Errorf("got: %d, want: %d", res.StatusCode, http.StatusNoContent)
}
}

0 comments on commit dd219a9

Please sign in to comment.