29
29
Mapping ,
30
30
Optional ,
31
31
Tuple ,
32
+ Type ,
32
33
Union ,
33
34
cast ,
34
35
)
@@ -439,7 +440,7 @@ async def _get_available_ui_auth_types(self, user: UserID) -> Iterable[str]:
439
440
440
441
return ui_auth_types
441
442
442
- def get_enabled_auth_types (self ):
443
+ def get_enabled_auth_types (self ) -> Iterable [ str ] :
443
444
"""Return the enabled user-interactive authentication types
444
445
445
446
Returns the UI-Auth types which are supported by the homeserver's current
@@ -702,7 +703,7 @@ async def get_session_data(
702
703
except StoreError :
703
704
raise SynapseError (400 , "Unknown session ID: %s" % (session_id ,))
704
705
705
- async def _expire_old_sessions (self ):
706
+ async def _expire_old_sessions (self ) -> None :
706
707
"""
707
708
Invalidate any user interactive authentication sessions that have expired.
708
709
"""
@@ -1352,7 +1353,7 @@ async def validate_short_term_login_token(
1352
1353
await self .auth .check_auth_blocking (res .user_id )
1353
1354
return res
1354
1355
1355
- async def delete_access_token (self , access_token : str ):
1356
+ async def delete_access_token (self , access_token : str ) -> None :
1356
1357
"""Invalidate a single access token
1357
1358
1358
1359
Args:
@@ -1381,7 +1382,7 @@ async def delete_access_tokens_for_user(
1381
1382
user_id : str ,
1382
1383
except_token_id : Optional [int ] = None ,
1383
1384
device_id : Optional [str ] = None ,
1384
- ):
1385
+ ) -> None :
1385
1386
"""Invalidate access tokens belonging to a user
1386
1387
1387
1388
Args:
@@ -1409,7 +1410,7 @@ async def delete_access_tokens_for_user(
1409
1410
1410
1411
async def add_threepid (
1411
1412
self , user_id : str , medium : str , address : str , validated_at : int
1412
- ):
1413
+ ) -> None :
1413
1414
# check if medium has a valid value
1414
1415
if medium not in ["email" , "msisdn" ]:
1415
1416
raise SynapseError (
@@ -1480,7 +1481,7 @@ async def hash(self, password: str) -> str:
1480
1481
Hashed password.
1481
1482
"""
1482
1483
1483
- def _do_hash ():
1484
+ def _do_hash () -> str :
1484
1485
# Normalise the Unicode in the password
1485
1486
pw = unicodedata .normalize ("NFKC" , password )
1486
1487
@@ -1504,7 +1505,7 @@ async def validate_hash(
1504
1505
Whether self.hash(password) == stored_hash.
1505
1506
"""
1506
1507
1507
- def _do_validate_hash (checked_hash : bytes ):
1508
+ def _do_validate_hash (checked_hash : bytes ) -> bool :
1508
1509
# Normalise the Unicode in the password
1509
1510
pw = unicodedata .normalize ("NFKC" , password )
1510
1511
@@ -1581,7 +1582,7 @@ async def complete_sso_login(
1581
1582
client_redirect_url : str ,
1582
1583
extra_attributes : Optional [JsonDict ] = None ,
1583
1584
new_user : bool = False ,
1584
- ):
1585
+ ) -> None :
1585
1586
"""Having figured out a mxid for this user, complete the HTTP request
1586
1587
1587
1588
Args:
@@ -1627,7 +1628,7 @@ def _complete_sso_login(
1627
1628
extra_attributes : Optional [JsonDict ] = None ,
1628
1629
new_user : bool = False ,
1629
1630
user_profile_data : Optional [ProfileInfo ] = None ,
1630
- ):
1631
+ ) -> None :
1631
1632
"""
1632
1633
The synchronous portion of complete_sso_login.
1633
1634
@@ -1726,17 +1727,17 @@ def _expire_sso_extra_attributes(self) -> None:
1726
1727
del self ._extra_attributes [user_id ]
1727
1728
1728
1729
@staticmethod
1729
- def add_query_param_to_url (url : str , param_name : str , param : Any ):
1730
+ def add_query_param_to_url (url : str , param_name : str , param : Any ) -> str :
1730
1731
url_parts = list (urllib .parse .urlparse (url ))
1731
1732
query = urllib .parse .parse_qsl (url_parts [4 ], keep_blank_values = True )
1732
1733
query .append ((param_name , param ))
1733
1734
url_parts [4 ] = urllib .parse .urlencode (query )
1734
1735
return urllib .parse .urlunparse (url_parts )
1735
1736
1736
1737
1737
- @attr .s (slots = True )
1738
+ @attr .s (slots = True , auto_attribs = True )
1738
1739
class MacaroonGenerator :
1739
- hs = attr . ib ()
1740
+ hs : "HomeServer"
1740
1741
1741
1742
def generate_guest_access_token (self , user_id : str ) -> str :
1742
1743
macaroon = self ._generate_base_macaroon (user_id )
@@ -1816,15 +1817,17 @@ class PasswordProvider:
1816
1817
"""
1817
1818
1818
1819
@classmethod
1819
- def load (cls , module , config , module_api : ModuleApi ) -> "PasswordProvider" :
1820
+ def load (
1821
+ cls , module : Type , config : JsonDict , module_api : ModuleApi
1822
+ ) -> "PasswordProvider" :
1820
1823
try :
1821
1824
pp = module (config = config , account_handler = module_api )
1822
1825
except Exception as e :
1823
1826
logger .error ("Error while initializing %r: %s" , module , e )
1824
1827
raise
1825
1828
return cls (pp , module_api )
1826
1829
1827
- def __init__ (self , pp , module_api : ModuleApi ):
1830
+ def __init__ (self , pp : "PasswordProvider" , module_api : ModuleApi ):
1828
1831
self ._pp = pp
1829
1832
self ._module_api = module_api
1830
1833
@@ -1838,7 +1841,7 @@ def __init__(self, pp, module_api: ModuleApi):
1838
1841
if g :
1839
1842
self ._supported_login_types .update (g ())
1840
1843
1841
- def __str__ (self ):
1844
+ def __str__ (self ) -> str :
1842
1845
return str (self ._pp )
1843
1846
1844
1847
def get_supported_login_types (self ) -> Mapping [str , Iterable [str ]]:
@@ -1876,19 +1879,19 @@ async def check_auth(
1876
1879
"""
1877
1880
# first grandfather in a call to check_password
1878
1881
if login_type == LoginType .PASSWORD :
1879
- g = getattr (self ._pp , "check_password" , None )
1880
- if g :
1882
+ check_password = getattr (self ._pp , "check_password" , None )
1883
+ if check_password :
1881
1884
qualified_user_id = self ._module_api .get_qualified_user_id (username )
1882
- is_valid = await self . _pp . check_password (
1885
+ is_valid = await check_password (
1883
1886
qualified_user_id , login_dict ["password" ]
1884
1887
)
1885
1888
if is_valid :
1886
1889
return qualified_user_id , None
1887
1890
1888
- g = getattr (self ._pp , "check_auth" , None )
1889
- if not g :
1891
+ check_auth = getattr (self ._pp , "check_auth" , None )
1892
+ if not check_auth :
1890
1893
return None
1891
- result = await g (username , login_type , login_dict )
1894
+ result = await check_auth (username , login_type , login_dict )
1892
1895
1893
1896
# Check if the return value is a str or a tuple
1894
1897
if isinstance (result , str ):
0 commit comments