25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

64 satır
2.2 KiB

  1. # Copyright 2023 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import logging
  15. import typing
  16. from typing import Tuple
  17. from synapse.api.errors import Codes, SynapseError
  18. from synapse.http.server import HttpServer
  19. from synapse.http.servlet import RestServlet
  20. from synapse.http.site import SynapseRequest
  21. from synapse.rest.client._base import client_patterns
  22. from synapse.types import JsonDict
  23. if typing.TYPE_CHECKING:
  24. from synapse.server import HomeServer
  25. logger = logging.getLogger(__name__)
  26. class AuthIssuerServlet(RestServlet):
  27. """
  28. Advertises what OpenID Connect issuer clients should use to authorise users.
  29. """
  30. PATTERNS = client_patterns(
  31. "/org.matrix.msc2965/auth_issuer$",
  32. unstable=True,
  33. releases=(),
  34. )
  35. def __init__(self, hs: "HomeServer"):
  36. super().__init__()
  37. self._config = hs.config
  38. async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
  39. if self._config.experimental.msc3861.enabled:
  40. return 200, {"issuer": self._config.experimental.msc3861.issuer}
  41. else:
  42. # Wouldn't expect this to be reached: the servelet shouldn't have been
  43. # registered. Still, fail gracefully if we are registered for some reason.
  44. raise SynapseError(
  45. 404,
  46. "OIDC discovery has not been configured on this homeserver",
  47. Codes.NOT_FOUND,
  48. )
  49. def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
  50. # We use the MSC3861 values as they are used by multiple MSCs
  51. if hs.config.experimental.msc3861.enabled:
  52. AuthIssuerServlet(hs).register(http_server)