diff --git a/configx/koanf_env.go b/configx/koanf_env.go index 0ab635c6..0129ab40 100644 --- a/configx/koanf_env.go +++ b/configx/koanf_env.go @@ -42,8 +42,16 @@ func NewKoanfEnv(prefix string, schema []byte) (*env.Env, error) { } decode := func(value string) (v interface{}) { - _ = json.Unmarshal([]byte(value), v) - return v + b := []byte(value) + var arr []interface{} + if err := json.Unmarshal(b, &arr); err == nil { + return &arr + } + h := map[string]interface{}{} + if err := json.Unmarshal(b, &h); err == nil { + return &h + } + return nil } return env.ProviderWithValue(prefix, ".", func(key string, value string) (string, interface{}) { diff --git a/configx/provider_test.go b/configx/provider_test.go index 53e4191b..56ab9cfd 100644 --- a/configx/provider_test.go +++ b/configx/provider_test.go @@ -109,6 +109,7 @@ func TestAdvancedConfigs(t *testing.T) { stub: "kratos", configs: []string{"stub/kratos/kratos.yaml"}, isValid: true, envs: [][2]string{ + {"SELFSERVICE_METHODS_OIDC_CONFIG_PROVIDERS", `[{"id":"google","provider":"google","mapper_url":"file:///etc/config/kratos/oidc.google.jsonnet","client_id":"client@example.com","client_secret":"secret"}]`}, {"DSN", "sqlite:///var/lib/sqlite/db.sqlite?_fk=true"}, }}, { diff --git a/configx/stub/kratos/expected.json b/configx/stub/kratos/expected.json index 57a6a8e3..1e666e6d 100644 --- a/configx/stub/kratos/expected.json +++ b/configx/stub/kratos/expected.json @@ -81,7 +81,18 @@ "enabled": true }, "oidc": { - "enabled": false + "enabled": true, + "config": { + "providers": [ + { + "id": "google", + "provider": "google", + "mapper_url": "file:///etc/config/kratos/oidc.google.jsonnet", + "client_id": "client@example.com", + "client_secret": "secret" + } + ] + } }, "password": { "enabled": true diff --git a/configx/stub/kratos/kratos.yaml b/configx/stub/kratos/kratos.yaml index 1e0bdb78..9848e3b2 100644 --- a/configx/stub/kratos/kratos.yaml +++ b/configx/stub/kratos/kratos.yaml @@ -18,6 +18,8 @@ selfservice: methods: password: enabled: true + oidc: + enabled: true flows: error: