outpost/embedded: fix login URL not being set correctly from outpost config

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-08-11 12:39:23 +02:00
parent c079f9e339
commit 7e62b82d56
2 changed files with 11 additions and 6 deletions

View File

@ -25,6 +25,7 @@ const ConfigErrorReportingEnvironment = "error_reporting_environment"
// APIController main controller which connects to the authentik api via http and ws
type APIController struct {
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))

View File

@ -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