Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix: errors when auth srv domain is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Apr 6, 2022
1 parent 3e6dff1 commit 10691ac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/app/app.go
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/app/auth_server.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
Expand Down
33 changes: 24 additions & 9 deletions internal/app/config.go
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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...)
Expand Down

0 comments on commit 10691ac

Please sign in to comment.