From f300639db5cd4fbc5819828f58a628b2ef1a1c4c Mon Sep 17 00:00:00 2001 From: gabrielmeloc22 Date: Thu, 16 Jul 2026 11:16:43 -0300 Subject: [PATCH 1/3] feat(scimdirectory): add Credentials method for pull-provider credential upload --- scimdirectory/api.go | 7 +++++++ scimdirectory/client.go | 21 +++++++++++++++++++++ scimdirectory/client_test.go | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/scimdirectory/api.go b/scimdirectory/api.go index a3ca273e..87f50c99 100644 --- a/scimdirectory/api.go +++ b/scimdirectory/api.go @@ -39,6 +39,13 @@ func RotateAPIKey(ctx context.Context, id string) (*clerk.SCIMDirectory, error) return getClient().RotateAPIKey(ctx, id) } +// Credentials uploads pull-provider credentials (e.g. a Google service-account +// key and subject email) for a SCIM directory. They are validated and sealed +// server-side; on success the directory is enabled. +func Credentials(ctx context.Context, id string, params *CredentialsParams) (*clerk.SCIMDirectory, error) { + return getClient().Credentials(ctx, id, params) +} + func getClient() *Client { return &Client{ Backend: clerk.GetBackend(), diff --git a/scimdirectory/client.go b/scimdirectory/client.go index f2fd821c..fbb1345f 100644 --- a/scimdirectory/client.go +++ b/scimdirectory/client.go @@ -130,3 +130,24 @@ func (c *Client) RotateAPIKey(ctx context.Context, id string) (*clerk.SCIMDirect err = c.Backend.Call(ctx, req, resource) return resource, err } + +type CredentialsParams struct { + clerk.APIParams + ServiceAccountJSON *string `json:"service_account_json,omitempty"` + SubjectEmail *string `json:"subject_email,omitempty"` +} + +// Credentials uploads pull-provider credentials (e.g. a Google service-account +// key and subject email) for a SCIM directory. They are validated and sealed +// server-side; on success the directory is enabled. +func (c *Client) Credentials(ctx context.Context, id string, params *CredentialsParams) (*clerk.SCIMDirectory, error) { + path, err := clerk.JoinPath(path, id, "credentials") + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodPost, path) + req.SetParams(params) + resource := &clerk.SCIMDirectory{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} diff --git a/scimdirectory/client_test.go b/scimdirectory/client_test.go index 54ee0499..c6e32c24 100644 --- a/scimdirectory/client_test.go +++ b/scimdirectory/client_test.go @@ -364,3 +364,39 @@ func TestRotateAPIKey(t *testing.T) { assert.Equal(t, "Test SCIM Directory", scimDirectory.Name) assert.Equal(t, "sk_new_rotated_key", *scimDirectory.APIKey) } + +func TestCredentials(t *testing.T) { + t.Parallel() + + response := map[string]interface{}{ + "object": "scim_directory", + "id": "scim_test123", + "name": "Test SCIM Directory", + "enterprise_connection_id": "entc_123", + "provider": "google", + "enabled": true, + "created_at": 1640995200, + "updated_at": 1640995200, + } + + responseJSON, _ := json.Marshal(response) + + config := &clerk.ClientConfig{} + config.HTTPClient = &http.Client{ + Transport: &clerktest.RoundTripper{ + T: t, + Out: json.RawMessage(responseJSON), + Method: http.MethodPost, + Path: "/v1/scim_directories/scim_test123/credentials", + }, + } + + client := NewClient(config) + scimDirectory, err := client.Credentials(context.Background(), "scim_test123", &CredentialsParams{ + ServiceAccountJSON: clerk.String(`{"type":"service_account"}`), + SubjectEmail: clerk.String("admin@example.com"), + }) + require.NoError(t, err) + assert.Equal(t, "scim_test123", scimDirectory.ID) + assert.True(t, scimDirectory.Enabled) +} From e0a3c512043b4125ad14a6d37ebe9d3cae8936b0 Mon Sep 17 00:00:00 2001 From: Gabriel Melo Date: Mon, 20 Jul 2026 11:14:43 -0300 Subject: [PATCH 2/3] Update scimdirectory/client.go Co-authored-by: nicolas lopes <57234795+NicolasLopes7@users.noreply.github.com> --- scimdirectory/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scimdirectory/client.go b/scimdirectory/client.go index fbb1345f..dee3ba24 100644 --- a/scimdirectory/client.go +++ b/scimdirectory/client.go @@ -137,10 +137,10 @@ type CredentialsParams struct { SubjectEmail *string `json:"subject_email,omitempty"` } -// Credentials uploads pull-provider credentials (e.g. a Google service-account +// AddCredentials adds pull-provider credentials (e.g. a Google service-account // key and subject email) for a SCIM directory. They are validated and sealed // server-side; on success the directory is enabled. -func (c *Client) Credentials(ctx context.Context, id string, params *CredentialsParams) (*clerk.SCIMDirectory, error) { +func (c *Client) AddCredentials(ctx context.Context, id string, params *CredentialsParams) (*clerk.SCIMDirectory, error) { path, err := clerk.JoinPath(path, id, "credentials") if err != nil { return nil, err From 7807f80f22ebf10e82fe6075d0b5016057c3dad6 Mon Sep 17 00:00:00 2001 From: gabrielmeloc22 Date: Wed, 22 Jul 2026 13:17:38 -0300 Subject: [PATCH 3/3] fix(scimdirectory): regenerate api.go and test after AddCredentials rename The e0a3c51 rename of Client.Credentials -> AddCredentials left the generated package-level wrapper in api.go and the client test calling the old method, which broke the build (and lint/test in CI). Regenerate api.go and update the test to the new name. --- scimdirectory/api.go | 6 +++--- scimdirectory/client_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scimdirectory/api.go b/scimdirectory/api.go index 87f50c99..222ae5d4 100644 --- a/scimdirectory/api.go +++ b/scimdirectory/api.go @@ -39,11 +39,11 @@ func RotateAPIKey(ctx context.Context, id string) (*clerk.SCIMDirectory, error) return getClient().RotateAPIKey(ctx, id) } -// Credentials uploads pull-provider credentials (e.g. a Google service-account +// AddCredentials adds pull-provider credentials (e.g. a Google service-account // key and subject email) for a SCIM directory. They are validated and sealed // server-side; on success the directory is enabled. -func Credentials(ctx context.Context, id string, params *CredentialsParams) (*clerk.SCIMDirectory, error) { - return getClient().Credentials(ctx, id, params) +func AddCredentials(ctx context.Context, id string, params *CredentialsParams) (*clerk.SCIMDirectory, error) { + return getClient().AddCredentials(ctx, id, params) } func getClient() *Client { diff --git a/scimdirectory/client_test.go b/scimdirectory/client_test.go index c6e32c24..6ad4f2cc 100644 --- a/scimdirectory/client_test.go +++ b/scimdirectory/client_test.go @@ -365,7 +365,7 @@ func TestRotateAPIKey(t *testing.T) { assert.Equal(t, "sk_new_rotated_key", *scimDirectory.APIKey) } -func TestCredentials(t *testing.T) { +func TestAddCredentials(t *testing.T) { t.Parallel() response := map[string]interface{}{ @@ -392,7 +392,7 @@ func TestCredentials(t *testing.T) { } client := NewClient(config) - scimDirectory, err := client.Credentials(context.Background(), "scim_test123", &CredentialsParams{ + scimDirectory, err := client.AddCredentials(context.Background(), "scim_test123", &CredentialsParams{ ServiceAccountJSON: clerk.String(`{"type":"service_account"}`), SubjectEmail: clerk.String("admin@example.com"), })