Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions sso_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ type OutputGetSSOIntegration struct {
AudienceURL string `json:"audience_url,omitempty"`
}

// GetSSOIntegration always sends si=true: without it SendGrid omits
// completed_integration from the response, which would decode as false.
//
// see: https://docs.sendgrid.com/api-reference/single-sign-on-settings/get-an-sso-integration
func (c *Client) GetSSOIntegration(ctx context.Context, id string) (*OutputGetSSOIntegration, error) {
path := fmt.Sprintf("/sso/integrations/%s", id)
path := fmt.Sprintf("/sso/integrations/%s?si=true", id)

req, err := c.NewRequest("GET", path, nil)
if err != nil {
Expand Down Expand Up @@ -62,6 +65,7 @@ func (c *Client) GetSSOIntegrations(ctx context.Context, input *InputGetSSOInteg
if input.Si {
q.Set("si", strconv.FormatBool(input.Si))
}
u.RawQuery = q.Encode()

req, err := c.NewRequest("GET", u.String(), nil)
if err != nil {
Expand Down Expand Up @@ -135,9 +139,12 @@ type OutputUpdateSSOIntegration struct {
AudienceURL string `json:"audience_url,omitempty"`
}

// UpdateSSOIntegration always sends si=true so that the response includes
// completed_integration, as GetSSOIntegration does.
//
// see: https://docs.sendgrid.com/api-reference/single-sign-on-settings/update-an-sso-integration
func (c *Client) UpdateSSOIntegration(ctx context.Context, id string, input *InputUpdateSSOIntegration) (*OutputUpdateSSOIntegration, error) {
path := fmt.Sprintf("/sso/integrations/%s", id)
path := fmt.Sprintf("/sso/integrations/%s?si=true", id)

req, err := c.NewRequest("PATCH", path, input)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions sso_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func TestGetSSOIntegration(t *testing.T) {
defer teardown()

mux.HandleFunc("/sso/integrations/abcdef", func(w http.ResponseWriter, r *http.Request) {
if got := r.URL.Query().Get("si"); got != "true" {
t.Errorf("si query = %q, want %q", got, "true")
}
if _, err := fmt.Fprint(w, `{
"id": "abcdef",
"name": "dummy",
Expand Down Expand Up @@ -77,6 +80,9 @@ func TestGetSSOIntegrations(t *testing.T) {
defer teardown()

mux.HandleFunc("/sso/integrations", func(w http.ResponseWriter, r *http.Request) {
if got := r.URL.Query().Get("si"); got != "true" {
t.Errorf("si query = %q, want %q", got, "true")
}
if _, err := fmt.Fprint(w, `[
{
"id": "abcdef",
Expand Down Expand Up @@ -213,6 +219,9 @@ func TestUpdateSSOIntegration(t *testing.T) {
defer teardown()

mux.HandleFunc("/sso/integrations/abcdef", func(w http.ResponseWriter, r *http.Request) {
if got := r.URL.Query().Get("si"); got != "true" {
t.Errorf("si query = %q, want %q", got, "true")
}
if _, err := fmt.Fprint(w, `{
"id": "abcdef",
"name": "dummy",
Expand Down
Loading