diff --git a/internal/outpost/ak/api.go b/internal/outpost/ak/api.go index 4578178d5..2c6103868 100644 --- a/internal/outpost/ak/api.go +++ b/internal/outpost/ak/api.go @@ -24,8 +24,9 @@ const ConfigErrorReportingEnvironment = "error_reporting_environment" // APIController main controller which connects to the authentik api via http and ws type APIController struct { - Client *api.APIClient - token string + Client *api.APIClient + Outpost api.Outpost + token string Server Outpost @@ -72,6 +73,7 @@ func NewAPIController(akURL url.URL, token string) *APIController { reloadOffset: time.Duration(rand.Intn(10)) * time.Second, instanceUUID: uuid.New(), + Outpost: outpost, } ac.logger.Debugf("HA Reload offset: %s", ac.reloadOffset) ac.initWS(akURL, strfmt.UUID(outpost.Pk)) diff --git a/internal/outpost/proxy/api_bundle.go b/internal/outpost/proxy/api_bundle.go index 41b4f5194..324801009 100644 --- a/internal/outpost/proxy/api_bundle.go +++ b/internal/outpost/proxy/api_bundle.go @@ -2,7 +2,6 @@ package proxy import ( "crypto/tls" - "fmt" "net" "net/http" "net/url" @@ -37,9 +36,13 @@ func intToPointer(i int) *int { } func (pb *providerBundle) replaceLocal(url string) string { - if strings.Contains(url, "localhost:8000") { - f := strings.ReplaceAll(url, "localhost:8000", pb.s.ak.Client.GetConfig().Host) - f = strings.ReplaceAll(f, "http://", fmt.Sprintf("%s://", pb.s.ak.Client.GetConfig().Scheme)) + if strings.HasPrefix(url, "http://localhost:8000") { + authentikHost, c := pb.s.ak.Outpost.Config["authentik_host"] + if !c { + pb.log.Warning("Outpost has localhost API Connection but no authentik_host is configured.") + return url + } + f := strings.ReplaceAll(url, "http://localhost:8000", authentikHost.(string)) return f } return url