Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 73b0372

Browse files
authored
Fix error messages from OIDC config parsing (#9153)
Make sure we report the correct config path for errors in the OIDC configs.
1 parent de45bf5 commit 73b0372

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

changelog.d/9153.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for multiple SSO Identity Providers.

synapse/config/oidc_config.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616

1717
import string
18-
from typing import Iterable, Optional, Type
18+
from typing import Iterable, Optional, Tuple, Type
1919

2020
import attr
2121

@@ -280,8 +280,8 @@ def _parse_oidc_provider_configs(config: JsonDict) -> Iterable["OidcProviderConf
280280
"""
281281
validate_config(MAIN_CONFIG_SCHEMA, config, ())
282282

283-
for p in config.get("oidc_providers") or []:
284-
yield _parse_oidc_config_dict(p)
283+
for i, p in enumerate(config.get("oidc_providers") or []):
284+
yield _parse_oidc_config_dict(p, ("oidc_providers", "<item %i>" % (i,)))
285285

286286
# for backwards-compatibility, it is also possible to provide a single "oidc_config"
287287
# object with an "enabled: True" property.
@@ -291,10 +291,12 @@ def _parse_oidc_provider_configs(config: JsonDict) -> Iterable["OidcProviderConf
291291
# it matches OIDC_PROVIDER_CONFIG_SCHEMA (see the comments on OIDC_CONFIG_SCHEMA
292292
# above), so now we need to validate it.
293293
validate_config(OIDC_PROVIDER_CONFIG_SCHEMA, oidc_config, ("oidc_config",))
294-
yield _parse_oidc_config_dict(oidc_config)
294+
yield _parse_oidc_config_dict(oidc_config, ("oidc_config",))
295295

296296

297-
def _parse_oidc_config_dict(oidc_config: JsonDict) -> "OidcProviderConfig":
297+
def _parse_oidc_config_dict(
298+
oidc_config: JsonDict, config_path: Tuple[str, ...]
299+
) -> "OidcProviderConfig":
298300
"""Take the configuration dict and parse it into an OidcProviderConfig
299301
300302
Raises:
@@ -305,7 +307,7 @@ def _parse_oidc_config_dict(oidc_config: JsonDict) -> "OidcProviderConfig":
305307
ump_config.setdefault("config", {})
306308

307309
(user_mapping_provider_class, user_mapping_provider_config,) = load_module(
308-
ump_config, ("oidc_config", "user_mapping_provider")
310+
ump_config, config_path + ("user_mapping_provider",)
309311
)
310312

311313
# Ensure loaded user mapping module has defined all necessary methods
@@ -320,9 +322,9 @@ def _parse_oidc_config_dict(oidc_config: JsonDict) -> "OidcProviderConfig":
320322
]
321323
if missing_methods:
322324
raise ConfigError(
323-
"Class specified by oidc_config."
324-
"user_mapping_provider.module is missing required "
325-
"methods: %s" % (", ".join(missing_methods),)
325+
"Class %s is missing required "
326+
"methods: %s" % (user_mapping_provider_class, ", ".join(missing_methods),),
327+
config_path + ("user_mapping_provider", "module"),
326328
)
327329

328330
# MSC2858 will appy certain limits in what can be used as an IdP id, so let's
@@ -331,7 +333,10 @@ def _parse_oidc_config_dict(oidc_config: JsonDict) -> "OidcProviderConfig":
331333
valid_idp_chars = set(string.ascii_letters + string.digits + "-._~")
332334

333335
if any(c not in valid_idp_chars for c in idp_id):
334-
raise ConfigError('idp_id may only contain A-Z, a-z, 0-9, "-", ".", "_", "~"')
336+
raise ConfigError(
337+
'idp_id may only contain A-Z, a-z, 0-9, "-", ".", "_", "~"',
338+
config_path + ("idp_id",),
339+
)
335340

336341
return OidcProviderConfig(
337342
idp_id=idp_id,

0 commit comments

Comments
 (0)