From 5b8ea4a1441200f6c41a6b2792530c91eee30c32 Mon Sep 17 00:00:00 2001 From: olivier Date: Mon, 9 Dec 2024 10:58:30 +0100 Subject: [PATCH] fix mypy --- synapse_sso_proconnect/proconnect_mapping.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/synapse_sso_proconnect/proconnect_mapping.py b/synapse_sso_proconnect/proconnect_mapping.py index 3203b8d..0282514 100644 --- a/synapse_sso_proconnect/proconnect_mapping.py +++ b/synapse_sso_proconnect/proconnect_mapping.py @@ -1,8 +1,8 @@ import string import attr -from authlib.oidc.core import UserInfo -from typing import Any, Dict, List, Optional, Tuple +from authlib.oidc.core import UserInfo # type: ignore +from typing import Any, Dict, List from synapse.handlers.oidc import OidcMappingProvider, Token, UserAttributeDict from synapse.handlers.sso import MappingException @@ -27,7 +27,9 @@ def parse_config(config: Dict[str, Any]) -> ProConnectMappingConfig: return ProConnectMappingConfig(**config) def get_remote_user_id(self, userinfo: UserInfo) -> str: - return userinfo.sub + if not hasattr(userinfo, 'sub') or not userinfo.sub: + raise MappingException("The 'sub' attribute is missing or empty in the provided UserInfo object.") + return str(userinfo.sub) async def map_user_attributes( self, userinfo: UserInfo, token: Token, failures: int @@ -71,7 +73,7 @@ async def map_user_attributes( {}, ) - return UserAttributeDict( + return UserAttributeDict( # type: ignore localpart=localpart, emails=[userinfo.email], confirm_localpart=False, @@ -79,7 +81,8 @@ async def map_user_attributes( ) # Search user ID by its email, retrying with replacements if necessary. - async def search_user_id_by_threepid(self, email: str): + async def search_user_id_by_threepid(self, email: str + )-> str | None: # Try to find the user ID using the provided email userId = await self.module_api._store.get_user_id_by_threepid("email", email)