From fb671139cdd43b1146b8799722bcd5e99e12f05c Mon Sep 17 00:00:00 2001 From: Stavros Date: Mon, 2 Feb 2026 15:46:02 +0200 Subject: [PATCH] feat: auto generate redirect url if empty --- Makefile | 4 ++++ internal/bootstrap/app_bootstrap.go | 26 ++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 55d6c93..e80607c 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,10 @@ develop-infisical: prod: docker compose -f $(PROD_COMPOSE) up --force-recreate --pull=always --remove-orphans +# Production - Infisical +prod-infisical: + infisical run --env=dev -- docker compose -f $(PROD_COMPOSE) up --force-recreate --pull=always --remove-orphans + # SQL .PHONY: sql sql: diff --git a/internal/bootstrap/app_bootstrap.go b/internal/bootstrap/app_bootstrap.go index 9da1d84..cb2c611 100644 --- a/internal/bootstrap/app_bootstrap.go +++ b/internal/bootstrap/app_bootstrap.go @@ -22,6 +22,7 @@ import ( type BootstrapApp struct { config config.Config context struct { + appUrl string uuid string cookieDomain string sessionCookieName string @@ -42,10 +43,20 @@ func NewBootstrapApp(config config.Config) *BootstrapApp { } func (app *BootstrapApp) Setup() error { + // get app url + appUrl, err := url.Parse(app.config.AppURL) + + if err != nil { + return err + } + + app.context.appUrl = appUrl.Scheme + "://" + appUrl.Host + // validate session config if app.config.Auth.SessionMaxLifetime != 0 && app.config.Auth.SessionMaxLifetime < app.config.Auth.SessionExpiry { return fmt.Errorf("session max lifetime cannot be less than session expiry") } + // Parse users users, err := utils.GetUsers(app.config.Auth.Users, app.config.Auth.UsersFile) @@ -62,16 +73,12 @@ func (app *BootstrapApp) Setup() error { secret := utils.GetSecret(provider.ClientSecret, provider.ClientSecretFile) provider.ClientSecret = secret provider.ClientSecretFile = "" - app.context.oauthProviders[name] = provider - } - for id := range config.OverrideProviders { - if provider, exists := app.context.oauthProviders[id]; exists { - if provider.RedirectURL == "" { - provider.RedirectURL = app.config.AppURL + "/api/oauth/callback/" + id - app.context.oauthProviders[id] = provider - } + if provider.RedirectURL == "" { + provider.RedirectURL = app.context.appUrl + "/api/oauth/callback/" + name } + + app.context.oauthProviders[name] = provider } for id, provider := range app.context.oauthProviders { @@ -92,7 +99,7 @@ func (app *BootstrapApp) Setup() error { } // Get cookie domain - cookieDomain, err := utils.GetCookieDomain(app.config.AppURL) + cookieDomain, err := utils.GetCookieDomain(app.context.appUrl) if err != nil { return err @@ -101,7 +108,6 @@ func (app *BootstrapApp) Setup() error { app.context.cookieDomain = cookieDomain // Cookie names - appUrl, _ := url.Parse(app.config.AppURL) // Already validated app.context.uuid = utils.GenerateUUID(appUrl.Hostname()) cookieId := strings.Split(app.context.uuid, "-")[0] app.context.sessionCookieName = fmt.Sprintf("%s-%s", config.SessionCookieName, cookieId)