Skip to content

Commit 8d577b7

Browse files
feat(auth): add OAuth server configuration support (#4207)
* feat(auth): add OAuth server configuration support * Update internal/start/start.go Co-authored-by: Han Qiao <[email protected]> * chore: `authorization_url` -> `authorization_url_path` * feat: update testdata * fix: commit missing change --------- Co-authored-by: Han Qiao <[email protected]>
1 parent d81798f commit 8d577b7

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

internal/start/start.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,15 @@ EOF
699699
}
700700
env = append(env, fmt.Sprintf("GOTRUE_EXTERNAL_WEB3_SOLANA_ENABLED=%v", utils.Config.Auth.Web3.Solana.Enabled))
701701

702+
// OAuth server configuration
703+
if utils.Config.Auth.OAuthServer.Enabled {
704+
env = append(env,
705+
fmt.Sprintf("GOTRUE_OAUTH_SERVER_ENABLED=%v", utils.Config.Auth.OAuthServer.Enabled),
706+
"GOTRUE_OAUTH_SERVER_AUTHORIZATION_PATH="+utils.Config.Auth.OAuthServer.AuthorizationUrlPath,
707+
fmt.Sprintf("GOTRUE_OAUTH_SERVER_ALLOW_DYNAMIC_REGISTRATION=%v", utils.Config.Auth.OAuthServer.AllowDynamicRegistration),
708+
)
709+
}
710+
702711
if _, err := utils.DockerStart(
703712
ctx,
704713
container.Config{

pkg/config/auth.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,16 @@ type (
162162
SigningKeysPath string `toml:"signing_keys_path"`
163163
SigningKeys []JWK `toml:"-"`
164164

165-
RateLimit rateLimit `toml:"rate_limit"`
166-
Captcha *captcha `toml:"captcha"`
167-
Hook hook `toml:"hook"`
168-
MFA mfa `toml:"mfa"`
169-
Sessions sessions `toml:"sessions"`
170-
Email email `toml:"email"`
171-
Sms sms `toml:"sms"`
172-
External external `toml:"external"`
173-
Web3 web3 `toml:"web3"`
165+
RateLimit rateLimit `toml:"rate_limit"`
166+
Captcha *captcha `toml:"captcha"`
167+
Hook hook `toml:"hook"`
168+
MFA mfa `toml:"mfa"`
169+
Sessions sessions `toml:"sessions"`
170+
Email email `toml:"email"`
171+
Sms sms `toml:"sms"`
172+
External external `toml:"external"`
173+
Web3 web3 `toml:"web3"`
174+
OAuthServer OAuthServer `toml:"oauth_server"`
174175

175176
// Custom secrets can be injected from .env file
176177
PublishableKey Secret `toml:"publishable_key"`
@@ -368,6 +369,12 @@ type (
368369
Solana solana `toml:"solana"`
369370
Ethereum ethereum `toml:"ethereum"`
370371
}
372+
373+
OAuthServer struct {
374+
Enabled bool `toml:"enabled"`
375+
AllowDynamicRegistration bool `toml:"allow_dynamic_registration"`
376+
AuthorizationUrlPath string `toml:"authorization_url_path"`
377+
}
371378
)
372379

373380
func (a *auth) ToUpdateAuthConfigBody() v1API.UpdateAuthConfigBody {
@@ -399,6 +406,7 @@ func (a *auth) ToUpdateAuthConfigBody() v1API.UpdateAuthConfigBody {
399406
a.Sms.toAuthConfigBody(&body)
400407
a.External.toAuthConfigBody(&body)
401408
a.Web3.toAuthConfigBody(&body)
409+
a.OAuthServer.toAuthConfigBody(&body)
402410
return body
403411
}
404412

@@ -426,6 +434,7 @@ func (a *auth) FromRemoteAuthConfig(remoteConfig v1API.AuthConfigResponse) {
426434
a.Sms.fromAuthConfig(remoteConfig)
427435
a.External.fromAuthConfig(remoteConfig)
428436
a.Web3.fromAuthConfig(remoteConfig)
437+
a.OAuthServer.fromAuthConfig(remoteConfig)
429438
}
430439

431440
func (r rateLimit) toAuthConfigBody(body *v1API.UpdateAuthConfigBody) {
@@ -1338,6 +1347,18 @@ func (w *web3) fromAuthConfig(remoteConfig v1API.AuthConfigResponse) {
13381347
}
13391348
}
13401349

1350+
func (o OAuthServer) toAuthConfigBody(body *v1API.UpdateAuthConfigBody) {
1351+
// TODO(cemal) :: implement me
1352+
// OAuth server configuration is behind a feature flag in the remote API
1353+
// Will be implemented when the feature reaches GA
1354+
}
1355+
1356+
func (o *OAuthServer) fromAuthConfig(remoteConfig v1API.AuthConfigResponse) {
1357+
// TODO(cemal) :: implement me
1358+
// OAuth server configuration is behind a feature flag in the remote API
1359+
// Will be implemented when the feature reaches GA
1360+
}
1361+
13411362
func (a *auth) DiffWithRemote(remoteConfig v1API.AuthConfigResponse, filter ...func(string) bool) ([]byte, error) {
13421363
copy := a.Clone()
13431364
copy.FromRemoteAuthConfig(remoteConfig)

pkg/config/templates/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ FROM darthsim/imgproxy:v3.8.0 AS imgproxy
1010
FROM supabase/edge-runtime:v1.69.12 AS edgeruntime
1111
FROM timberio/vector:0.28.1-alpine AS vector
1212
FROM supabase/supavisor:2.7.0 AS supavisor
13-
FROM supabase/gotrue:v2.179.0 AS gotrue
13+
FROM supabase/gotrue:v2.180.0 AS gotrue
1414
FROM supabase/realtime:v2.51.3 AS realtime
1515
FROM supabase/storage-api:v1.27.4 AS storage
1616
FROM supabase/logflare:1.22.3 AS logflare

pkg/config/templates/config.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ enabled = false
304304
# Obtain from https://clerk.com/setup/supabase
305305
# domain = "example.clerk.accounts.dev"
306306

307+
# OAuth server configuration
308+
[auth.oauth_server]
309+
# Enable OAuth server functionality
310+
enabled = false
311+
# Path for OAuth consent flow UI
312+
authorization_url_path = "/oauth/consent"
313+
# Allow dynamic client registration
314+
allow_dynamic_registration = false
315+
307316
[edge_runtime]
308317
enabled = true
309318
# Supported request policies: `oneshot`, `per_worker`.

pkg/config/testdata/config.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ minimum_password_length = 6
144144
# are: `letters_digits`, `lower_upper_letters_digits`, `lower_upper_letters_digits_symbols`
145145
password_requirements = ""
146146

147+
# OAuth server configuration
148+
[auth.oauth_server]
149+
# Enable OAuth server functionality
150+
enabled = true
151+
# Path for OAuth consent flow UI
152+
authorization_url_path = "/oauth/consent"
153+
# Allow dynamic client registration
154+
allow_dynamic_registration = true
155+
147156
[auth.rate_limit]
148157
# Number of emails that can be sent per hour. Requires auth.email.smtp to be enabled.
149158
email_sent = 2

0 commit comments

Comments
 (0)