Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

saml: Define a TypedDict for the type of IdP settings dict.

Mateusz Mandera00c7ac15df23
diff --git a/zerver/lib/types.py b/zerver/lib/types.py
index 73cf876945a..df9b2132245 100644
--- a/zerver/lib/types.py
+++ b/zerver/lib/types.py
@@ -51,3 +51,19 @@ class LinkifierDict(TypedDict):
pattern: str
url_format: str
id: int
+
+
+class SAMLIdPConfigDict(TypedDict, total=False):
+ entity_id: str
+ url: str
+ attr_user_permanent_id: str
+ attr_first_name: str
+ attr_last_name: str
+ attr_username: str
+ attr_email: str
+ attr_org_membership: str
+ display_name: str
+ display_icon: str
+ limit_to_subdomains: List[str]
+ x509cert: str
+ x509cert_path: str
diff --git a/zproject/default_settings.py b/zproject/default_settings.py
index 6b9c374af90..bfbf69426c6 100644
--- a/zproject/default_settings.py
+++ b/zproject/default_settings.py
@@ -9,6 +9,8 @@ if TYPE_CHECKING:
from django_auth_ldap.config import LDAPSearch
from typing_extensions import TypedDict
+ from zerver.lib.types import SAMLIdPConfigDict
+
if PRODUCTION:
from .prod_settings import EXTERNAL_HOST, ZULIP_ADMINISTRATOR
else:
@@ -81,7 +83,7 @@ SOCIAL_AUTH_SAML_SP_PRIVATE_KEY = ""
SOCIAL_AUTH_SAML_ORG_INFO: Optional[Dict[str, Dict[str, str]]] = None
SOCIAL_AUTH_SAML_TECHNICAL_CONTACT: Optional[Dict[str, str]] = None
SOCIAL_AUTH_SAML_SUPPORT_CONTACT: Optional[Dict[str, str]] = None
-SOCIAL_AUTH_SAML_ENABLED_IDPS: Dict[str, Dict[str, str]] = {}
+SOCIAL_AUTH_SAML_ENABLED_IDPS: Dict[str, "SAMLIdPConfigDict"] = {}
SOCIAL_AUTH_SAML_SECURITY_CONFIG: Dict[str, Any] = {}
# Set this to True to enforce that any configured IdP needs to specify
# the limit_to_subdomains setting to be considered valid:
diff --git a/zproject/prod_settings_template.py b/zproject/prod_settings_template.py
index e9e527119e8..ba9ccf829fb 100644
--- a/zproject/prod_settings_template.py
+++ b/zproject/prod_settings_template.py
@@ -394,7 +394,7 @@ SOCIAL_AUTH_SAML_ORG_INFO = {
"url": "{}{}".format("https://", EXTERNAL_HOST),
},
}
-SOCIAL_AUTH_SAML_ENABLED_IDPS = {
+SOCIAL_AUTH_SAML_ENABLED_IDPS: Dict[str, Any] = {
## The fields are explained in detail here:
## https://python-social-auth.readthedocs.io/en/latest/backends/saml.html
"idp_name": {
diff --git a/zproject/test_extra_settings.py b/zproject/test_extra_settings.py
index 78002f0a63f..3888f25fd57 100644
--- a/zproject/test_extra_settings.py
+++ b/zproject/test_extra_settings.py
@@ -5,6 +5,7 @@ import ldap
from django_auth_ldap.config import LDAPSearch
from zerver.lib.db import TimeTrackingConnection
+from zerver.lib.types import SAMLIdPConfigDict
from .config import DEPLOY_ROOT, get_from_file_if_exists
from .settings import (
@@ -244,7 +245,7 @@ SOCIAL_AUTH_SAML_SUPPORT_CONTACT = {
"emailAddress": "[email protected]",
}
-SOCIAL_AUTH_SAML_ENABLED_IDPS = {
+SOCIAL_AUTH_SAML_ENABLED_IDPS: Dict[str, SAMLIdPConfigDict] = {
"test_idp": {
"entity_id": "https://idp.testshib.org/idp/shibboleth",
"url": "https://idp.testshib.org/idp/profile/SAML2/Redirect/SSO",