|
23 | 23 | from synapse.python_dependencies import DependencyException, check_requirements |
24 | 24 | from synapse.types import Collection, JsonDict |
25 | 25 | from synapse.util.module_loader import load_module |
| 26 | +from synapse.util.stringutils import parse_and_validate_mxc_uri |
26 | 27 |
|
27 | 28 | from ._base import Config, ConfigError |
28 | 29 |
|
@@ -68,6 +69,10 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs): |
68 | 69 | # idp_name: A user-facing name for this identity provider, which is used to |
69 | 70 | # offer the user a choice of login mechanisms. |
70 | 71 | # |
| 72 | + # idp_icon: An optional icon for this identity provider, which is presented |
| 73 | + # by identity picker pages. If given, must be an MXC URI of the format |
| 74 | + # mxc://<server-name>/<media-id> |
| 75 | + # |
71 | 76 | # discover: set to 'false' to disable the use of the OIDC discovery mechanism |
72 | 77 | # to discover endpoints. Defaults to true. |
73 | 78 | # |
@@ -209,6 +214,7 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs): |
209 | 214 | "properties": { |
210 | 215 | "idp_id": {"type": "string", "minLength": 1, "maxLength": 128}, |
211 | 216 | "idp_name": {"type": "string"}, |
| 217 | + "idp_icon": {"type": "string"}, |
212 | 218 | "discover": {"type": "boolean"}, |
213 | 219 | "issuer": {"type": "string"}, |
214 | 220 | "client_id": {"type": "string"}, |
@@ -338,9 +344,20 @@ def _parse_oidc_config_dict( |
338 | 344 | config_path + ("idp_id",), |
339 | 345 | ) |
340 | 346 |
|
| 347 | + # MSC2858 also specifies that the idp_icon must be a valid MXC uri |
| 348 | + idp_icon = oidc_config.get("idp_icon") |
| 349 | + if idp_icon is not None: |
| 350 | + try: |
| 351 | + parse_and_validate_mxc_uri(idp_icon) |
| 352 | + except ValueError as e: |
| 353 | + raise ConfigError( |
| 354 | + "idp_icon must be a valid MXC URI", config_path + ("idp_icon",) |
| 355 | + ) from e |
| 356 | + |
341 | 357 | return OidcProviderConfig( |
342 | 358 | idp_id=idp_id, |
343 | 359 | idp_name=oidc_config.get("idp_name", "OIDC"), |
| 360 | + idp_icon=idp_icon, |
344 | 361 | discover=oidc_config.get("discover", True), |
345 | 362 | issuer=oidc_config["issuer"], |
346 | 363 | client_id=oidc_config["client_id"], |
@@ -368,6 +385,9 @@ class OidcProviderConfig: |
368 | 385 | # user-facing name for this identity provider. |
369 | 386 | idp_name = attr.ib(type=str) |
370 | 387 |
|
| 388 | + # Optional MXC URI for icon for this IdP. |
| 389 | + idp_icon = attr.ib(type=Optional[str]) |
| 390 | + |
371 | 391 | # whether the OIDC discovery mechanism is used to discover endpoints |
372 | 392 | discover = attr.ib(type=bool) |
373 | 393 |
|
|
0 commit comments