Skip to content

Commit e51bc6c

Browse files
authored
feat: read env in auth.additional_redirect_urls values (#2760)
2 parents 54c9d20 + d69776f commit e51bc6c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

pkg/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,11 @@ func (c *baseConfig) Validate(fsys fs.FS) error {
833833
if c.Auth.SiteUrl, err = maybeLoadEnv(c.Auth.SiteUrl); err != nil {
834834
return err
835835
}
836+
for i, url := range c.Auth.AdditionalRedirectUrls {
837+
if c.Auth.AdditionalRedirectUrls[i], err = maybeLoadEnv(url); err != nil {
838+
return errors.Errorf("Invalid config for auth.additional_redirect_urls[%d]: %v", i, err)
839+
}
840+
}
836841
// Validate email config
837842
for name, tmpl := range c.Auth.Email.Template {
838843
if len(tmpl.ContentPath) > 0 {

pkg/config/config_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@ func TestConfigParsing(t *testing.T) {
4141
t.Setenv("AZURE_SECRET", "this is cool")
4242
t.Setenv("AUTH_SEND_SMS_SECRETS", "v1,whsec_aWxpa2VzdXBhYmFzZXZlcnltdWNoYW5kaWhvcGV5b3Vkb3Rvbw==")
4343
t.Setenv("SENDGRID_API_KEY", "sendgrid")
44+
t.Setenv("AUTH_CALLBACK_URL", "http://localhost:3000/auth/callback")
4445
assert.NoError(t, config.Load("", fsys))
4546
// Check error
4647
assert.Equal(t, "hello", config.Auth.External["azure"].ClientId)
4748
assert.Equal(t, "this is cool", config.Auth.External["azure"].Secret)
49+
assert.Equal(t, []string{
50+
"https://127.0.0.1:3000",
51+
"http://localhost:3000/auth/callback",
52+
}, config.Auth.AdditionalRedirectUrls)
4853
})
4954

5055
t.Run("config file with environment variables fails when unset", func(t *testing.T) {
@@ -70,6 +75,7 @@ func TestConfigParsing(t *testing.T) {
7075
t.Setenv("AZURE_SECRET", "this is cool")
7176
t.Setenv("AUTH_SEND_SMS_SECRETS", "v1,whsec_aWxpa2VzdXBhYmFzZXZlcnltdWNoYW5kaWhvcGV5b3Vkb3Rvbw==")
7277
t.Setenv("SENDGRID_API_KEY", "sendgrid")
78+
t.Setenv("AUTH_CALLBACK_URL", "http://localhost:3000/auth/callback")
7379
assert.NoError(t, config.Load("", fsys))
7480
// Check the default value in the config
7581
assert.Equal(t, "http://127.0.0.1:3000", config.Auth.SiteUrl)

pkg/config/testdata/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ enabled = true
9494
# in emails.
9595
site_url = "http://127.0.0.1:3000"
9696
# A list of *exact* URLs that auth providers are permitted to redirect to post authentication.
97-
additional_redirect_urls = ["https://127.0.0.1:3000"]
97+
additional_redirect_urls = ["https://127.0.0.1:3000", "env(AUTH_CALLBACK_URL)"]
9898
# How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 (1 week).
9999
jwt_expiry = 3600
100100
# If disabled, the refresh token will never expire.

0 commit comments

Comments
 (0)