__init__.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2021 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from typing import TYPE_CHECKING, Mapping
  16. from twisted.web.resource import Resource
  17. from synapse.rest.synapse.client.new_user_consent import NewUserConsentResource
  18. from synapse.rest.synapse.client.pick_idp import PickIdpResource
  19. from synapse.rest.synapse.client.pick_username import pick_username_resource
  20. from synapse.rest.synapse.client.sso_register import SsoRegisterResource
  21. if TYPE_CHECKING:
  22. from synapse.server import HomeServer
  23. def build_synapse_client_resource_tree(hs: "HomeServer") -> Mapping[str, Resource]:
  24. """Builds a resource tree to include synapse-specific client resources
  25. These are resources which should be loaded on all workers which expose a C-S API:
  26. ie, the main process, and any generic workers so configured.
  27. Returns:
  28. map from path to Resource.
  29. """
  30. resources = {
  31. # SSO bits. These are always loaded, whether or not SSO login is actually
  32. # enabled (they just won't work very well if it's not)
  33. "/_synapse/client/pick_idp": PickIdpResource(hs),
  34. "/_synapse/client/pick_username": pick_username_resource(hs),
  35. "/_synapse/client/new_user_consent": NewUserConsentResource(hs),
  36. "/_synapse/client/sso_register": SsoRegisterResource(hs),
  37. }
  38. # provider-specific SSO bits. Only load these if they are enabled, since they
  39. # rely on optional dependencies.
  40. if hs.config.oidc_enabled:
  41. from synapse.rest.synapse.client.oidc import OIDCResource
  42. resources["/_synapse/client/oidc"] = OIDCResource(hs)
  43. if hs.config.saml2_enabled:
  44. from synapse.rest.synapse.client.saml2 import SAML2Resource
  45. resources["/_synapse/client/saml2"] = SAML2Resource(hs)
  46. return resources
  47. __all__ = ["build_synapse_client_resource_tree"]