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

Commit

Permalink
Ditch the account management URL in new endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed Dec 5, 2023
1 parent 2970bbf commit 3074249
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
11 changes: 0 additions & 11 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,3 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
self.msc4069_profile_inhibit_propagation = experimental.get(
"msc4069_profile_inhibit_propagation", False
)

def get_msc2965_discovery_data(self) -> Optional[JsonDict]:
# We use the MSC3861 values as they are used by multiple MSCs
if not self.msc3861.enabled:
return None

result = {"issuer": self.msc3861.issuer}
if self.msc3861.account_management_url is not None:
result["account"] = self.msc3861.account_management_url

return result
6 changes: 3 additions & 3 deletions synapse/rest/client/auth_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ def __init__(self, hs: "HomeServer"):
self._config = hs.config

async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
discovery_data = self._config.experimental.get_msc2965_discovery_data()
if discovery_data is None:
if self._config.experimental.msc3861.enabled:
return 200, {"issuer": self._config.experimental.msc3861.issuer}
else:
# Wouldn't expect this to be reached: the servelet shouldn't have been
# registered. Still, fail gracefully if we are registered for some reason.
raise SynapseError(
404,
"OIDC discovery has not been configured on this homeserver",
Codes.NOT_FOUND,
)
return 200, discovery_data


def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
Expand Down
12 changes: 9 additions & 3 deletions synapse/rest/well_known.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ def get_well_known(self) -> Optional[JsonDict]:
"base_url": self._config.registration.default_identity_server
}

discovery_data = self._config.experimental.get_msc2965_discovery_data()
if discovery_data is not None:
result["org.matrix.msc2965.authentication"] = discovery_data
# We use the MSC3861 values as they are used by multiple MSCs
if self._config.experimental.msc3861.enabled:
result["org.matrix.msc2965.authentication"] = {
"issuer": self._config.experimental.msc3861.issuer
}
if self._config.experimental.msc3861.account_management_url is not None:
result["org.matrix.msc2965.authentication"][
"account"
] = self._config.experimental.msc3861.account_management_url

if self._config.server.extra_well_known_client_content:
for (
Expand Down
8 changes: 2 additions & 6 deletions tests/rest/client/test_auth_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from tests.unittest import HomeserverTestCase, override_config

ISSUER = "https://account.example.com/"
ACCOUNT_MANAGEMENT_URL = "https://account.example.com/myaccount/"


class AuthIssuerTestCase(HomeserverTestCase):
Expand All @@ -41,21 +40,18 @@ def test_returns_404_when_msc3861_disabled(self) -> None:
"msc3861": {
"enabled": True,
"issuer": ISSUER,
"account_management_url": ACCOUNT_MANAGEMENT_URL,
"client_id": "David Lister",
"client_auth_method": "client_secret_post",
"client_secret": "Who shot Mister Burns?",
}
},
}
)
def test_returns_discovery_data_when_oidc_enabled(self) -> None:
def test_returns_issuer_when_oidc_enabled(self) -> None:
# Make an unauthenticated request for the discovery info.
channel = self.make_request(
"GET",
"/_matrix/client/unstable/org.matrix.msc2965/auth_issuer",
)
self.assertEqual(channel.code, HTTPStatus.OK)
self.assertEqual(
channel.json_body, {"issuer": ISSUER, "account": ACCOUNT_MANAGEMENT_URL}
)
self.assertEqual(channel.json_body, {"issuer": ISSUER})

0 comments on commit 3074249

Please sign in to comment.