Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

47 linhas
1.7 KiB

  1. # Copyright 2015 Niklas Riekenbrauck
  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. from typing import Any
  15. from synapse.types import JsonDict
  16. from synapse.util.check_dependencies import check_requirements
  17. from ._base import Config
  18. class JWTConfig(Config):
  19. section = "jwt"
  20. def read_config(self, config: JsonDict, **kwargs: Any) -> None:
  21. jwt_config = config.get("jwt_config", None)
  22. if jwt_config:
  23. self.jwt_enabled = jwt_config.get("enabled", False)
  24. self.jwt_secret = jwt_config["secret"]
  25. self.jwt_algorithm = jwt_config["algorithm"]
  26. self.jwt_subject_claim = jwt_config.get("subject_claim", "sub")
  27. # The issuer and audiences are optional, if provided, it is asserted
  28. # that the claims exist on the JWT.
  29. self.jwt_issuer = jwt_config.get("issuer")
  30. self.jwt_audiences = jwt_config.get("audiences")
  31. check_requirements("jwt")
  32. else:
  33. self.jwt_enabled = False
  34. self.jwt_secret = None
  35. self.jwt_algorithm = None
  36. self.jwt_subject_claim = None
  37. self.jwt_issuer = None
  38. self.jwt_audiences = None