diff --git a/internal/app/app.go b/internal/app/app.go index 4ab7737b..ccd40e16 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -81,7 +81,7 @@ func initEcho(ctx context.Context, cfg *ServerConfig) *echo.Echo { SignupSecret: cfg.Config.SignupSecret, PublishedIndexHTML: publishedIndexHTML, PublishedIndexURL: cfg.Config.Published.IndexURL, - AuthSrvUIDomain: cfg.Config.AuthSrv.UIDomain, + AuthSrvUIDomain: cfg.Config.Host_Web, })) // auth srv diff --git a/internal/app/auth_server.go b/internal/app/auth_server.go index 0a2c10e8..4d490213 100644 --- a/internal/app/auth_server.go +++ b/internal/app/auth_server.go @@ -27,7 +27,7 @@ const ( ) func authEndPoints(ctx context.Context, e *echo.Echo, r *echo.Group, cfg *ServerConfig) { - userUsecase := interactor.NewUser(cfg.Repos, cfg.Gateways, cfg.Config.SignupSecret, cfg.Config.AuthSrv.UIDomain) + userUsecase := interactor.NewUser(cfg.Repos, cfg.Gateways, cfg.Config.SignupSecret, cfg.Config.Host_Web) domain, err := url.Parse(cfg.Config.AuthSrv.Domain) if err != nil { @@ -59,7 +59,7 @@ func authEndPoints(ctx context.Context, e *echo.Echo, r *echo.Group, cfg *Server ctx, &interactor.StorageConfig{ Domain: domain.String(), - ClientDomain: cfg.Config.AuthSrv.UIDomain, + ClientDomain: cfg.Config.Host_Web, Debug: cfg.Debug, DN: dn, }, diff --git a/internal/app/config.go b/internal/app/config.go index 128e265f..354f1cc4 100644 --- a/internal/app/config.go +++ b/internal/app/config.go @@ -18,6 +18,8 @@ const configPrefix = "reearth" type Config struct { Port string `default:"8080" envconfig:"PORT"` + Host string `default:"http://localhost:8080"` + Host_Web string Dev bool DB string `default:"mongodb://localhost"` Mailer string @@ -57,25 +59,32 @@ type Auth0Config struct { type AuthSrvConfig struct { Dev bool Disabled bool - Domain string `default:"http://localhost:8080"` - UIDomain string `default:"http://localhost:8080"` + Domain string Key string DN *AuthSrvDNConfig } -func (c AuthSrvConfig) AuthConfig(debug bool) *AuthConfig { +func (c AuthSrvConfig) AuthConfig(debug bool, host string) *AuthConfig { if c.Disabled { return nil } + + domain := c.Domain + if domain == "" { + domain = host + } + var aud []string - if debug { - aud = []string{"http://localhost:8080", c.Domain} + if debug && host != "" && c.Domain != "" { + aud = []string{host, c.Domain} } else { - aud = []string{c.Domain} + aud = []string{domain} } + clientID := auth.ClientID + return &AuthConfig{ - ISS: c.Domain, + ISS: domain, AUD: aud, ClientID: &clientID, } @@ -130,10 +139,16 @@ func ReadConfig(debug bool) (*Config, error) { var c Config err := envconfig.Process(configPrefix, &c) + // defailt values if debug { c.Dev = true } - if c.Dev || c.AuthSrv.Dev { + if c.Host_Web == "" { + c.Host_Web = c.Host + } + + // overwrite env vars + if !c.AuthSrv.Disabled && (c.Dev || c.AuthSrv.Dev || c.AuthSrv.Domain == "") { if _, ok := os.LookupEnv(op.OidcDevMode); !ok { _ = os.Setenv(op.OidcDevMode, "1") } @@ -170,7 +185,7 @@ func (c Config) Auths() (res []AuthConfig) { ClientID: c.Auth_ClientID, }) } - if ac := c.AuthSrv.AuthConfig(c.Dev); ac != nil { + if ac := c.AuthSrv.AuthConfig(c.Dev, c.Host); ac != nil { res = append(res, *ac) } return append(res, c.Auth...)