From d5ce63e6c9f7992b1b00d5474e978b1a04941208 Mon Sep 17 00:00:00 2001 From: ThetaSinner Date: Thu, 10 Oct 2024 01:18:13 +0100 Subject: [PATCH] feat: separate ory public url from browser redirect url --- auth/auth.go | 12 ++++++------ locus.go | 11 ++++++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 871e6d0..4d7e199 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -9,9 +9,9 @@ import ( ) type App struct { - Router fiber.Router - Ory *ory.APIClient - OryBase string + Router fiber.Router + Ory *ory.APIClient + OryBrowserBase string } func SessionUser(c *fiber.Ctx) interface{} { @@ -55,7 +55,7 @@ func (a *App) Prepare(app *fiber.App) { return c.Render("public/auth/login", fiber.Map{ "Flow": flow, - "RegisterUrl": fmt.Sprintf("%sself-service/registration/browser", a.OryBase), + "RegisterUrl": fmt.Sprintf("%sself-service/registration/browser", a.OryBrowserBase), }) }) @@ -109,14 +109,14 @@ func (a *App) Prepare(app *fiber.App) { app.Use(func(c *fiber.Ctx) error { cookies := c.GetReqHeaders()["Cookie"] if len(cookies) == 0 { - return c.Redirect(fmt.Sprintf("%sself-service/login/browser", a.OryBase), http.StatusSeeOther) + return c.Redirect(fmt.Sprintf("%sself-service/login/browser", a.OryBrowserBase), http.StatusSeeOther) } // check if we have a session session, _, err := a.Ory.FrontendAPI.ToSession(c.Context()).Cookie(cookies[0]).Execute() if (err != nil && session == nil) || (err == nil && !*session.Active) { // this will redirect the user to the managed Ory Login UI - return c.Redirect(fmt.Sprintf("%sself-service/login/browser", a.OryBase), http.StatusSeeOther) + return c.Redirect(fmt.Sprintf("%sself-service/login/browser", a.OryBrowserBase), http.StatusSeeOther) } c.Locals("cookies", cookies[0]) diff --git a/locus.go b/locus.go index b60ccb4..54dbf9a 100644 --- a/locus.go +++ b/locus.go @@ -29,6 +29,11 @@ func main() { } config.Servers = ory.ServerConfigurations{{URL: oryPublicUrl}} + oryPublicBrowserUrl := os.Getenv("ORY_PUBLIC_BROWSER_URL") + if oryPublicBrowserUrl == "" { + oryPublicBrowserUrl = oryPublicUrl + } + oryClient := ory.NewAPIClient(config) log.SetLevel(log.LevelInfo) @@ -53,9 +58,9 @@ func main() { } else { log.Info("Running in production mode") oryAuthApp := auth.App{ - Router: app.Group("/auth"), - Ory: oryClient, - OryBase: oryPublicUrl, + Router: app.Group("/auth"), + Ory: oryClient, + OryBrowserBase: oryPublicBrowserUrl, } oryAuthApp.Prepare(app) }