Update to latest synapse provider spec

master
Andrew Morgan 5 years ago
parent 2be3b40e9c
commit fbdd91a2c3

@ -14,14 +14,20 @@
# limitations under the License. # limitations under the License.
import re import re
import attr
import string import string
import saml2.response import saml2.response
__version__ = "0.0.1" __version__ = "0.0.1"
@attr.s
class SamlConfig(object):
mxid_source_attribute = attr.ib()
class SamlMappingProvider(object): class SamlMappingProvider(object):
def __init__(self, parsed_config): def __init__(self, parsed_config: SamlConfig):
"""A Mozilla-flavoured, Synapse user mapping provider """A Mozilla-flavoured, Synapse user mapping provider
Args: Args:
@ -101,33 +107,27 @@ class SamlMappingProvider(object):
return username return username
@staticmethod @staticmethod
def parse_config(config: dict): def parse_config(config: dict) -> SamlConfig:
"""Parse the dict provided by the homeserver's config """Parse the dict provided by the homeserver's config
Args: Args:
config: A dictionary containing configuration options for this provider config: A dictionary containing configuration options for this provider
Returns: Returns:
_SamlConfig: A custom config object SamlConfig: A custom config object
""" """
pass mxid_source_attribute = config.get("mxid_source_attribute", "uid")
return SamlConfig(mxid_source_attribute)
class _SamlConfig(object):
pass
saml_config = _SamlConfig()
saml_config.mxid_source_attribute = config["mxid_source_attribute"]
return saml_config
@staticmethod @staticmethod
def get_required_saml_attributes(config: dict): def get_saml_attributes(config: SamlConfig) -> tuple[set:set]:
"""Returns the required attributes of a SAML """Returns the required and optional attributes of a SAML auth response object
Args: Args:
config: A dictionary containing configuration options for this provider config: A SamlConfig object containing configuration options for this provider
Returns: Returns:
tuple[set,set]: The first set equates to the saml auth response attributes that tuple[set,set]: The first set equates to the saml auth response
are required for the module to function, whereas the second set consists of attributes that are required for the module to function, whereas the
those attributes which can be used if available, but are not necessary second set consists of those attributes which can be used if
available, but are not necessary
""" """
saml_config = SamlMappingProvider.parse_config(config) return {"uid", config.mxid_source_attribute}, {"displayName"}
return {"uid", saml_config.mxid_source_attribute}, {"displayName"}

@ -45,6 +45,7 @@ setup(
py_modules=["matrix-synapse-saml-moz"], py_modules=["matrix-synapse-saml-moz"],
description="An Mozilla-flavoured SAML MXID mapper for Synapse", description="An Mozilla-flavoured SAML MXID mapper for Synapse",
install_requires=[ install_requires=[
"attr>=0.3.1",
"pysaml2>=4.5.0", "pysaml2>=4.5.0",
], ],
long_description=read_file(("README.md",)), long_description=read_file(("README.md",)),

Loading…
Cancel
Save