From ddeca59db598e2b4567a62dd9cb03bfa2ed9c5c3 Mon Sep 17 00:00:00 2001 From: Cemal Kilic Date: Tue, 10 Nov 2026 17:22:02 +0100 Subject: [PATCH 1/3] feat: add client auth method to custom OAuth providers Custom providers can now authenticate to the token endpoint with either a client secret or a signed client assertion (private_key_jwt). Adds client_auth_method (client_secret by default, so existing rows are unchanged) and an optional client_assertion_audience. A check constraint requires a secret for client_secret providers and an empty one for private_key_jwt providers. client_secret stays NOT NULL: private_key_jwt providers store an empty string instead, so versions that predate this migration can still read every row during a rolling deploy or after a rollback. --- internal/models/custom_oauth_provider.go | 36 ++++- internal/models/custom_oauth_provider_test.go | 128 ++++++++++++++++++ ...th_method_to_custom_oauth_providers.up.sql | 54 ++++++++ 3 files changed, 213 insertions(+), 5 deletions(-) create mode 100644 migrations/20261116120000_add_client_auth_method_to_custom_oauth_providers.up.sql diff --git a/internal/models/custom_oauth_provider.go b/internal/models/custom_oauth_provider.go index 2f461502eb..1e1b7a5c8d 100644 --- a/internal/models/custom_oauth_provider.go +++ b/internal/models/custom_oauth_provider.go @@ -23,6 +23,18 @@ const ( ProviderTypeOIDC ProviderType = "oidc" ) +// ClientAuthMethod is how Auth authenticates to a custom provider's token +// endpoint. +type ClientAuthMethod string + +const ( + // ClientAuthMethodClientSecret sends the stored client secret. + ClientAuthMethodClientSecret ClientAuthMethod = "client_secret" + // ClientAuthMethodPrivateKeyJWT sends a signed client assertion (RFC 7523). + // No client secret is stored. + ClientAuthMethodPrivateKeyJWT ClientAuthMethod = "private_key_jwt" +) + // CustomOAuthProvider represents a custom OAuth2 or OIDC provider configuration type CustomOAuthProvider struct { ID uuid.UUID `db:"id" json:"id"` @@ -32,7 +44,6 @@ type CustomOAuthProvider struct { Identifier string `db:"identifier" json:"identifier"` Name string `db:"name" json:"name"` ClientID string `db:"client_id" json:"client_id"` - ClientSecret string `db:"client_secret" json:"-"` // Encrypted via EncryptedString, never expose in JSON AcceptableClientIDs slices.String `db:"acceptable_client_ids" json:"acceptable_client_ids"` Scopes slices.String `db:"scopes" json:"scopes"` PKCEEnabled bool `db:"pkce_enabled" json:"pkce_enabled"` @@ -44,6 +55,15 @@ type CustomOAuthProvider struct { Enabled bool `db:"enabled" json:"enabled"` EmailOptional bool `db:"email_optional" json:"email_optional"` + // Client authentication to the token endpoint. + ClientAuthMethod ClientAuthMethod `db:"client_auth_method" json:"client_auth_method"` + // ClientSecret is encrypted via EncryptedString and never exposed in JSON. + // It is empty for private_key_jwt providers. + ClientSecret string `db:"client_secret" json:"-"` + // ClientAssertionAudience overrides the aud claim of client assertions, + // which defaults to the provider's issuer. Only used with private_key_jwt. + ClientAssertionAudience *string `db:"client_assertion_audience" json:"client_assertion_audience,omitempty"` + // OIDC-specific fields (null for OAuth2 providers) Issuer *string `db:"issuer" json:"issuer,omitempty"` DiscoveryURL *string `db:"discovery_url" json:"discovery_url,omitempty"` @@ -88,16 +108,18 @@ func (p *CustomOAuthProvider) SetClientSecret(secret string, dbEncryption conf.D // GetClientSecret decrypts and returns the client secret using the configured // database decryption keys. It expects the client secret to be stored in // encrypted form when encryption is enabled, but will also handle plaintext -// secrets (for deployments where encryption is not yet configured). +// secrets (for deployments where encryption is not yet configured). It returns +// an empty string for providers without a secret (private_key_jwt). func (p *CustomOAuthProvider) GetClientSecret(dbEncryption conf.DatabaseEncryptionConfiguration) (string, error) { - if p.ClientSecret == "" { + secret := p.ClientSecret + if secret == "" { return "", nil } - es := crypto.ParseEncryptedString(p.ClientSecret) + es := crypto.ParseEncryptedString(secret) if es == nil { // Not an encrypted string – treat as plaintext. - return p.ClientSecret, nil + return secret, nil } if dbEncryption.DecryptionKeys == nil { @@ -288,6 +310,10 @@ func CreateCustomOAuthProvider(tx *storage.Connection, provider *CustomOAuthProv if provider.CustomClaimsAllowlist == nil { provider.CustomClaimsAllowlist = slices.String{} } + // pop inserts every column, so the column default doesn't apply + if provider.ClientAuthMethod == "" { + provider.ClientAuthMethod = ClientAuthMethodClientSecret + } if err := tx.Create(provider); err != nil { return errors.Wrap(err, "error creating custom OAuth provider") diff --git a/internal/models/custom_oauth_provider_test.go b/internal/models/custom_oauth_provider_test.go index dff1943b4f..060ee3253b 100644 --- a/internal/models/custom_oauth_provider_test.go +++ b/internal/models/custom_oauth_provider_test.go @@ -1,6 +1,7 @@ package models import ( + "encoding/json" "testing" "github.com/gobuffalo/pop/v6/slices" @@ -171,6 +172,7 @@ func (ts *CustomOAuthProviderTestSuite) TestStringSliceSerialization() { Identifier: "custom:string-slice-test", Name: "String Slice Test", ClientID: "client-id", + ClientSecret: "test-client-secret", Scopes: slices.String{"openid", "profile", "email"}, AcceptableClientIDs: slices.String{"ios-client", "android-client", "web-client"}, AuthorizationURL: stringPtr("https://example.com/authorize"), @@ -205,6 +207,7 @@ func (ts *CustomOAuthProviderTestSuite) TestCustomClaimsAllowlistSerialization() Identifier: "custom:allowlist-test", Name: "Allowlist Test", ClientID: "client-id", + ClientSecret: "test-client-secret", AuthorizationURL: stringPtr("https://example.com/authorize"), TokenURL: stringPtr("https://example.com/token"), UserinfoURL: stringPtr("https://example.com/userinfo"), @@ -254,6 +257,7 @@ func (ts *CustomOAuthProviderTestSuite) TestAttributeMappingSerialization() { Identifier: "custom:mapping-test", Name: "Mapping Test", ClientID: "client-id", + ClientSecret: "test-client-secret", AuthorizationURL: stringPtr("https://example.com/authorize"), TokenURL: stringPtr("https://example.com/token"), UserinfoURL: stringPtr("https://example.com/userinfo"), @@ -286,6 +290,7 @@ func (ts *CustomOAuthProviderTestSuite) TestAuthorizationParamsSerialization() { Identifier: "custom:params-test", Name: "Params Test", ClientID: "client-id", + ClientSecret: "test-client-secret", AuthorizationURL: stringPtr("https://example.com/authorize"), TokenURL: stringPtr("https://example.com/token"), UserinfoURL: stringPtr("https://example.com/userinfo"), @@ -324,6 +329,7 @@ func (ts *CustomOAuthProviderTestSuite) TestOIDCDiscoverySerialization() { Identifier: "custom:oidc-discovery-test", Name: "OIDC Discovery Test", ClientID: "client-id", + ClientSecret: "test-client-secret", Issuer: &issuer, CachedDiscovery: discovery, PKCEEnabled: true, @@ -371,6 +377,7 @@ func (ts *CustomOAuthProviderTestSuite) TestGetDiscoveryURL() { Identifier: "custom:oidc-auto-discovery", Name: "OIDC Auto Discovery", ClientID: "client-id", + ClientSecret: "test-client-secret", Issuer: &issuer1, PKCEEnabled: true, Enabled: true, @@ -389,6 +396,7 @@ func (ts *CustomOAuthProviderTestSuite) TestGetDiscoveryURL() { Identifier: "custom:oidc-explicit-discovery", Name: "OIDC Explicit Discovery", ClientID: "client-id", + ClientSecret: "test-client-secret", Issuer: &issuer2, DiscoveryURL: &explicitDiscoveryURL, PKCEEnabled: true, @@ -491,6 +499,126 @@ func (ts *CustomOAuthProviderTestSuite) TestClientSecretRoundTripThroughDB() { assert.Equal(ts.T(), secret, decrypted) } +// Client auth method + +func (ts *CustomOAuthProviderTestSuite) newPrivateKeyJWTProvider(identifier string) *CustomOAuthProvider { + issuer := "https://oidc-" + identifier + ".example.com" + return &CustomOAuthProvider{ + ProviderType: ProviderTypeOIDC, + Identifier: "custom:" + identifier, + Name: "Private Key JWT Provider", + ClientID: "test-client-id", + Issuer: &issuer, + ClientAuthMethod: ClientAuthMethodPrivateKeyJWT, + PKCEEnabled: true, + Enabled: true, + } +} + +func (ts *CustomOAuthProviderTestSuite) TestClientAuthMethodDefaultsToClientSecret() { + provider := ts.createTestProvider(ProviderTypeOIDC, "custom:default-method") + + found, err := FindCustomOAuthProviderByID(ts.db, provider.ID) + require.NoError(ts.T(), err) + assert.Equal(ts.T(), ClientAuthMethodClientSecret, found.ClientAuthMethod) + assert.Nil(ts.T(), found.ClientAssertionAudience) + assert.NotEmpty(ts.T(), found.ClientSecret) +} + +func (ts *CustomOAuthProviderTestSuite) TestPrivateKeyJWTProviderRoundTrip() { + provider := ts.newPrivateKeyJWTProvider("pkjwt-roundtrip") + provider.ClientAssertionAudience = stringPtr("https://issuer.example.com/token") + require.NoError(ts.T(), CreateCustomOAuthProvider(ts.db, provider)) + + found, err := FindCustomOAuthProviderByID(ts.db, provider.ID) + require.NoError(ts.T(), err) + assert.Equal(ts.T(), ClientAuthMethodPrivateKeyJWT, found.ClientAuthMethod) + assert.Equal(ts.T(), "https://issuer.example.com/token", *found.ClientAssertionAudience) + assert.Empty(ts.T(), found.ClientSecret) + + // stored as an empty string, never NULL, so versions that predate + // client_auth_method can still read the row + var secretIsNull bool + require.NoError(ts.T(), ts.db.RawQuery( + "select client_secret is null from "+provider.TableName()+" where id = ?", provider.ID, + ).First(&secretIsNull)) + assert.False(ts.T(), secretIsNull) + + secret, err := found.GetClientSecret(ts.config.Security.DBEncryption) + require.NoError(ts.T(), err) + assert.Empty(ts.T(), secret) + + // the method and audience are exposed in JSON, the secret never is + data, err := json.Marshal(found) + require.NoError(ts.T(), err) + var raw map[string]any + require.NoError(ts.T(), json.Unmarshal(data, &raw)) + assert.Equal(ts.T(), "private_key_jwt", raw["client_auth_method"]) + assert.Equal(ts.T(), "https://issuer.example.com/token", raw["client_assertion_audience"]) + assert.NotContains(ts.T(), raw, "client_secret") +} + +func (ts *CustomOAuthProviderTestSuite) TestClientAuthMethodConstraints() { + // private_key_jwt providers must not have a secret + withSecret := ts.newPrivateKeyJWTProvider("pkjwt-with-secret") + require.NoError(ts.T(), withSecret.SetClientSecret("test-client-secret", ts.config.Security.DBEncryption)) + assert.Error(ts.T(), CreateCustomOAuthProvider(ts.db, withSecret)) + + // client_secret providers must have a secret + withoutSecret := ts.newPrivateKeyJWTProvider("secret-missing") + withoutSecret.ClientAuthMethod = ClientAuthMethodClientSecret + assert.Error(ts.T(), CreateCustomOAuthProvider(ts.db, withoutSecret)) + + // an empty secret counts as missing + emptySecret := ts.newPrivateKeyJWTProvider("secret-empty") + emptySecret.ClientAuthMethod = ClientAuthMethodClientSecret + require.NoError(ts.T(), emptySecret.SetClientSecret("", conf.DatabaseEncryptionConfiguration{})) + assert.Error(ts.T(), CreateCustomOAuthProvider(ts.db, emptySecret)) + + // unknown methods are rejected + unknown := ts.newPrivateKeyJWTProvider("unknown-method") + unknown.ClientAuthMethod = "client_secret_jwt" + assert.Error(ts.T(), CreateCustomOAuthProvider(ts.db, unknown)) + + // the audience may not be an empty string + emptyAudience := ts.newPrivateKeyJWTProvider("empty-audience") + emptyAudience.ClientAssertionAudience = stringPtr("") + assert.Error(ts.T(), CreateCustomOAuthProvider(ts.db, emptyAudience)) + + count, err := CountCustomOAuthProviders(ts.db) + require.NoError(ts.T(), err) + assert.Equal(ts.T(), 0, count) +} + +func (ts *CustomOAuthProviderTestSuite) TestSwitchClientAuthMethod() { + provider := ts.createTestProvider(ProviderTypeOIDC, "custom:switch-method") + + // to private_key_jwt: the secret has to be cleared + provider.ClientAuthMethod = ClientAuthMethodPrivateKeyJWT + assert.Error(ts.T(), UpdateCustomOAuthProvider(ts.db, provider)) + + provider.ClientSecret = "" + require.NoError(ts.T(), UpdateCustomOAuthProvider(ts.db, provider)) + + found, err := FindCustomOAuthProviderByID(ts.db, provider.ID) + require.NoError(ts.T(), err) + assert.Equal(ts.T(), ClientAuthMethodPrivateKeyJWT, found.ClientAuthMethod) + assert.Empty(ts.T(), found.ClientSecret) + + // back to client_secret: a secret is required again + found.ClientAuthMethod = ClientAuthMethodClientSecret + assert.Error(ts.T(), UpdateCustomOAuthProvider(ts.db, found)) + + require.NoError(ts.T(), found.SetClientSecret("new-client-secret", ts.config.Security.DBEncryption)) + require.NoError(ts.T(), UpdateCustomOAuthProvider(ts.db, found)) + + found, err = FindCustomOAuthProviderByID(ts.db, provider.ID) + require.NoError(ts.T(), err) + secret, err := found.GetClientSecret(ts.config.Security.DBEncryption) + require.NoError(ts.T(), err) + assert.Equal(ts.T(), "new-client-secret", secret) +} + func TestGetDiscoveryURLStripsTrailingSlashes(t *testing.T) { tests := []struct { name string diff --git a/migrations/20261116120000_add_client_auth_method_to_custom_oauth_providers.up.sql b/migrations/20261116120000_add_client_auth_method_to_custom_oauth_providers.up.sql new file mode 100644 index 0000000000..8c185d83f1 --- /dev/null +++ b/migrations/20261116120000_add_client_auth_method_to_custom_oauth_providers.up.sql @@ -0,0 +1,54 @@ +-- Let custom OAuth providers authenticate to the token endpoint with either a +-- client secret or a signed client assertion (private_key_jwt, RFC 7523). +-- Existing rows default to client_secret and keep their secret. +-- +-- client_secret stays NOT NULL: private_key_jwt providers store an empty +-- string instead, so versions that predate this migration can still read every +-- row during a rolling deploy or after a rollback. +/* auth_migration: 20261116120000 */ +do $$ begin + + alter table only {{ index .Options "Namespace" }}.custom_oauth_providers + add column if not exists client_auth_method text not null default 'client_secret', + -- Optional override for the assertion aud claim, which defaults to the + -- provider's issuer. + add column if not exists client_assertion_audience text null; + + if not exists ( + select 1 from pg_constraint + where conname = 'custom_oauth_providers_client_auth_method_check' + and conrelid = '{{ index .Options "Namespace" }}.custom_oauth_providers'::regclass + ) then + alter table only {{ index .Options "Namespace" }}.custom_oauth_providers + add constraint custom_oauth_providers_client_auth_method_check check ( + client_auth_method in ('client_secret', 'private_key_jwt') + ); + end if; + + -- client_secret providers must have a secret, private_key_jwt providers + -- must not (an empty string). + if not exists ( + select 1 from pg_constraint + where conname = 'custom_oauth_providers_client_secret_matches_auth_method' + and conrelid = '{{ index .Options "Namespace" }}.custom_oauth_providers'::regclass + ) then + alter table only {{ index .Options "Namespace" }}.custom_oauth_providers + add constraint custom_oauth_providers_client_secret_matches_auth_method check ( + (client_auth_method = 'client_secret' and client_secret <> '') or + (client_auth_method = 'private_key_jwt' and client_secret = '') + ); + end if; + + if not exists ( + select 1 from pg_constraint + where conname = 'custom_oauth_providers_client_assertion_audience_length' + and conrelid = '{{ index .Options "Namespace" }}.custom_oauth_providers'::regclass + ) then + alter table only {{ index .Options "Namespace" }}.custom_oauth_providers + add constraint custom_oauth_providers_client_assertion_audience_length check ( + client_assertion_audience is null or + (char_length(client_assertion_audience) >= 1 and char_length(client_assertion_audience) <= 2048) + ); + end if; + +end $$; From 2bfb678c6162b5c9f86938e9ac9941f58066cf3a Mon Sep 17 00:00:00 2001 From: Cemal Kilic Date: Tue, 17 Nov 2026 16:26:23 +0100 Subject: [PATCH 2/3] refactor: drop the client secret/auth method check constraint Which client auth methods need a secret is already enforced by the admin API. Keeping it as a cross-column check constraint as well means every new method needs a migration to drop and recreate it. The checks on the allowed method values and the audience length stay. --- internal/models/custom_oauth_provider_test.go | 25 +++---------------- ...th_method_to_custom_oauth_providers.up.sql | 17 +++---------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/internal/models/custom_oauth_provider_test.go b/internal/models/custom_oauth_provider_test.go index 060ee3253b..8727a6d959 100644 --- a/internal/models/custom_oauth_provider_test.go +++ b/internal/models/custom_oauth_provider_test.go @@ -559,21 +559,8 @@ func (ts *CustomOAuthProviderTestSuite) TestPrivateKeyJWTProviderRoundTrip() { } func (ts *CustomOAuthProviderTestSuite) TestClientAuthMethodConstraints() { - // private_key_jwt providers must not have a secret - withSecret := ts.newPrivateKeyJWTProvider("pkjwt-with-secret") - require.NoError(ts.T(), withSecret.SetClientSecret("test-client-secret", ts.config.Security.DBEncryption)) - assert.Error(ts.T(), CreateCustomOAuthProvider(ts.db, withSecret)) - - // client_secret providers must have a secret - withoutSecret := ts.newPrivateKeyJWTProvider("secret-missing") - withoutSecret.ClientAuthMethod = ClientAuthMethodClientSecret - assert.Error(ts.T(), CreateCustomOAuthProvider(ts.db, withoutSecret)) - - // an empty secret counts as missing - emptySecret := ts.newPrivateKeyJWTProvider("secret-empty") - emptySecret.ClientAuthMethod = ClientAuthMethodClientSecret - require.NoError(ts.T(), emptySecret.SetClientSecret("", conf.DatabaseEncryptionConfiguration{})) - assert.Error(ts.T(), CreateCustomOAuthProvider(ts.db, emptySecret)) + // whether a method needs a secret is enforced by the admin API; the + // database only checks the method and the audience // unknown methods are rejected unknown := ts.newPrivateKeyJWTProvider("unknown-method") @@ -593,10 +580,8 @@ func (ts *CustomOAuthProviderTestSuite) TestClientAuthMethodConstraints() { func (ts *CustomOAuthProviderTestSuite) TestSwitchClientAuthMethod() { provider := ts.createTestProvider(ProviderTypeOIDC, "custom:switch-method") - // to private_key_jwt: the secret has to be cleared + // to private_key_jwt, clearing the secret as the admin API does provider.ClientAuthMethod = ClientAuthMethodPrivateKeyJWT - assert.Error(ts.T(), UpdateCustomOAuthProvider(ts.db, provider)) - provider.ClientSecret = "" require.NoError(ts.T(), UpdateCustomOAuthProvider(ts.db, provider)) @@ -605,10 +590,8 @@ func (ts *CustomOAuthProviderTestSuite) TestSwitchClientAuthMethod() { assert.Equal(ts.T(), ClientAuthMethodPrivateKeyJWT, found.ClientAuthMethod) assert.Empty(ts.T(), found.ClientSecret) - // back to client_secret: a secret is required again + // back to client_secret with a new secret found.ClientAuthMethod = ClientAuthMethodClientSecret - assert.Error(ts.T(), UpdateCustomOAuthProvider(ts.db, found)) - require.NoError(ts.T(), found.SetClientSecret("new-client-secret", ts.config.Security.DBEncryption)) require.NoError(ts.T(), UpdateCustomOAuthProvider(ts.db, found)) diff --git a/migrations/20261116120000_add_client_auth_method_to_custom_oauth_providers.up.sql b/migrations/20261116120000_add_client_auth_method_to_custom_oauth_providers.up.sql index 8c185d83f1..b2aaf63fcf 100644 --- a/migrations/20261116120000_add_client_auth_method_to_custom_oauth_providers.up.sql +++ b/migrations/20261116120000_add_client_auth_method_to_custom_oauth_providers.up.sql @@ -5,6 +5,9 @@ -- client_secret stays NOT NULL: private_key_jwt providers store an empty -- string instead, so versions that predate this migration can still read every -- row during a rolling deploy or after a rollback. +-- +-- Which methods need a secret is enforced by the admin API, not by a check +-- constraint, so adding a method later doesn't need a constraint migration. /* auth_migration: 20261116120000 */ do $$ begin @@ -25,20 +28,6 @@ do $$ begin ); end if; - -- client_secret providers must have a secret, private_key_jwt providers - -- must not (an empty string). - if not exists ( - select 1 from pg_constraint - where conname = 'custom_oauth_providers_client_secret_matches_auth_method' - and conrelid = '{{ index .Options "Namespace" }}.custom_oauth_providers'::regclass - ) then - alter table only {{ index .Options "Namespace" }}.custom_oauth_providers - add constraint custom_oauth_providers_client_secret_matches_auth_method check ( - (client_auth_method = 'client_secret' and client_secret <> '') or - (client_auth_method = 'private_key_jwt' and client_secret = '') - ); - end if; - if not exists ( select 1 from pg_constraint where conname = 'custom_oauth_providers_client_assertion_audience_length' From cc48b6be72b2fc6707f0124f1dd2b394a65e8a0c Mon Sep 17 00:00:00 2001 From: Cemal Kilic Date: Tue, 17 Nov 2026 16:57:01 +0100 Subject: [PATCH 3/3] refactor: remove the remaining client auth check constraints The admin API already validates the allowed client auth methods and the assertion audience length, so the check constraints only duplicate it and make future migrations harder. The migration now only adds the columns. --- internal/models/custom_oauth_provider_test.go | 19 --------- ...th_method_to_custom_oauth_providers.up.sql | 41 ++++--------------- 2 files changed, 7 insertions(+), 53 deletions(-) diff --git a/internal/models/custom_oauth_provider_test.go b/internal/models/custom_oauth_provider_test.go index 8727a6d959..4f8aa98d6e 100644 --- a/internal/models/custom_oauth_provider_test.go +++ b/internal/models/custom_oauth_provider_test.go @@ -558,25 +558,6 @@ func (ts *CustomOAuthProviderTestSuite) TestPrivateKeyJWTProviderRoundTrip() { assert.NotContains(ts.T(), raw, "client_secret") } -func (ts *CustomOAuthProviderTestSuite) TestClientAuthMethodConstraints() { - // whether a method needs a secret is enforced by the admin API; the - // database only checks the method and the audience - - // unknown methods are rejected - unknown := ts.newPrivateKeyJWTProvider("unknown-method") - unknown.ClientAuthMethod = "client_secret_jwt" - assert.Error(ts.T(), CreateCustomOAuthProvider(ts.db, unknown)) - - // the audience may not be an empty string - emptyAudience := ts.newPrivateKeyJWTProvider("empty-audience") - emptyAudience.ClientAssertionAudience = stringPtr("") - assert.Error(ts.T(), CreateCustomOAuthProvider(ts.db, emptyAudience)) - - count, err := CountCustomOAuthProviders(ts.db) - require.NoError(ts.T(), err) - assert.Equal(ts.T(), 0, count) -} - func (ts *CustomOAuthProviderTestSuite) TestSwitchClientAuthMethod() { provider := ts.createTestProvider(ProviderTypeOIDC, "custom:switch-method") diff --git a/migrations/20261116120000_add_client_auth_method_to_custom_oauth_providers.up.sql b/migrations/20261116120000_add_client_auth_method_to_custom_oauth_providers.up.sql index b2aaf63fcf..2eb9ccfe1c 100644 --- a/migrations/20261116120000_add_client_auth_method_to_custom_oauth_providers.up.sql +++ b/migrations/20261116120000_add_client_auth_method_to_custom_oauth_providers.up.sql @@ -6,38 +6,11 @@ -- string instead, so versions that predate this migration can still read every -- row during a rolling deploy or after a rollback. -- --- Which methods need a secret is enforced by the admin API, not by a check --- constraint, so adding a method later doesn't need a constraint migration. +-- The allowed methods, which methods need a secret, and the audience length +-- are enforced by the admin API, not by check constraints. /* auth_migration: 20261116120000 */ -do $$ begin - - alter table only {{ index .Options "Namespace" }}.custom_oauth_providers - add column if not exists client_auth_method text not null default 'client_secret', - -- Optional override for the assertion aud claim, which defaults to the - -- provider's issuer. - add column if not exists client_assertion_audience text null; - - if not exists ( - select 1 from pg_constraint - where conname = 'custom_oauth_providers_client_auth_method_check' - and conrelid = '{{ index .Options "Namespace" }}.custom_oauth_providers'::regclass - ) then - alter table only {{ index .Options "Namespace" }}.custom_oauth_providers - add constraint custom_oauth_providers_client_auth_method_check check ( - client_auth_method in ('client_secret', 'private_key_jwt') - ); - end if; - - if not exists ( - select 1 from pg_constraint - where conname = 'custom_oauth_providers_client_assertion_audience_length' - and conrelid = '{{ index .Options "Namespace" }}.custom_oauth_providers'::regclass - ) then - alter table only {{ index .Options "Namespace" }}.custom_oauth_providers - add constraint custom_oauth_providers_client_assertion_audience_length check ( - client_assertion_audience is null or - (char_length(client_assertion_audience) >= 1 and char_length(client_assertion_audience) <= 2048) - ); - end if; - -end $$; +alter table only {{ index .Options "Namespace" }}.custom_oauth_providers + add column if not exists client_auth_method text not null default 'client_secret', + -- Optional override for the assertion aud claim, which defaults to the + -- provider's issuer. + add column if not exists client_assertion_audience text null;