Skip to content

Commit b6d150d

Browse files
committed
feat(scim): generate scim_users, scim_tokens ids app-side
1 parent 5eecd2f commit b6d150d

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

internal/api/scim/helpers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ func grantToken(t *testing.T, db *storage.Connection, provider string) string {
9191

9292
token, digest := NewToken()
9393
require.NoError(t, db.RawQuery(
94-
"INSERT INTO scim_tokens (sso_provider_id, token_hash, prefix) VALUES (?, ?, ?)",
95-
provider, digest, token[:12],
94+
"INSERT INTO scim_tokens (id, sso_provider_id, token_hash, prefix) VALUES (?, ?, ?, ?)",
95+
uuid.Must(uuid.NewV4()), provider, digest, token[:12],
9696
).Exec())
9797

9898
return token

internal/api/scim/user_repository.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strconv"
99
"strings"
1010

11+
"github.com/gofrs/uuid"
1112
"github.com/jackc/pgconn"
1213
"github.com/jackc/pgerrcode"
1314
"github.com/supabase/auth/internal/api/scim/core"
@@ -95,7 +96,7 @@ func (r *userRepository) Create(ctx context.Context, user *core.User) (*core.Use
9596
}
9697

9798
var rows []scimUser
98-
if err := r.db.WithContext(ctx).RawQuery("INSERT INTO scim_users (sso_provider_id, resource) VALUES (?, ?) RETURNING id, resource, active, created_at, updated_at", r.tenant(ctx), resource).All(&rows); err != nil {
99+
if err := r.db.WithContext(ctx).RawQuery("INSERT INTO scim_users (id, sso_provider_id, resource) VALUES (?, ?, ?) RETURNING id, resource, active, created_at, updated_at", uuid.Must(uuid.NewV4()), r.tenant(ctx), resource).All(&rows); err != nil {
99100
return nil, r.buildError("creating", err)
100101
}
101102
return r.mapFrom(&rows[0])

internal/api/scim_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func TestSCIM(t *testing.T) {
202202

203203
t.Run("Authentication", func(t *testing.T) {
204204
provider, token := createProvider(t, conn)
205-
require.NoError(t, conn.RawQuery("INSERT INTO scim_users (sso_provider_id, resource) VALUES (?, ?)", provider, `{"userName":"bjensen@example.com"}`).Exec())
205+
require.NoError(t, conn.RawQuery("INSERT INTO scim_users (id, sso_provider_id, resource) VALUES (?, ?, ?)", uuid.Must(uuid.NewV4()), provider, `{"userName":"bjensen@example.com"}`).Exec())
206206

207207
get := func(t *testing.T, authorization string) *httptest.ResponseRecorder {
208208
t.Helper()
@@ -271,7 +271,7 @@ func createProvider(t *testing.T, conn *storage.Connection) (provider, token str
271271
})
272272

273273
token, digest := scim.NewToken()
274-
require.NoError(t, conn.RawQuery("INSERT INTO scim_tokens (sso_provider_id, token_hash, prefix) VALUES (?, ?, ?)", provider, digest, token[:12]).Exec())
274+
require.NoError(t, conn.RawQuery("INSERT INTO scim_tokens (id, sso_provider_id, token_hash, prefix) VALUES (?, ?, ?, ?)", uuid.Must(uuid.NewV4()), provider, digest, token[:12]).Exec())
275275

276276
return provider, token
277277
}

0 commit comments

Comments
 (0)