@@ -162,14 +162,8 @@ def authenticate(self, user: UserInfo, password: str = None) -> SessionInfo:
162162 if self ._portaswitch_settings .ALLOWED_ADDONS :
163163 self ._check_allowed_addons (account_info )
164164
165- version = self ._admin_api .get_version ()
166- actual_portaswitch_mr = [int (d ) for d in re .findall (r'\d+' , version )]
167- expected_portaswitch_mr_with_token_support = [int (d ) for d in
168- re .findall (r'\d+' , PORTASWITCH_VERSION_WITH_TOKEN )]
169-
170- token = account_info ["password" ]
171- session_data = self ._account_api .login (account_info ["login" ], account_info ["password" ],
172- token if actual_portaswitch_mr < expected_portaswitch_mr_with_token_support else None )
165+ token = account_info ["password" ] if self ._is_portaswitch_version_with_token () else None
166+ session_data = self ._account_api .login (account_info ["login" ], account_info ["password" ], token )
173167
174168 return SessionInfo (
175169 user_id = UserId (str (account_info ["i_account" ])),
@@ -1428,4 +1422,14 @@ def _emulate_account_login(self, i_account: str) -> dict:
14281422 """Emulate a login for a PortaSwitch account."""
14291423 account_info = self ._admin_api .get_account_info (i_account = i_account ).get ("account_info" )
14301424
1431- return self ._account_api .login (account_info ["login" ], account_info ["password" ])
1425+ token = account_info ["password" ] if self ._is_portaswitch_version_with_token () else None
1426+ return self ._account_api .login (account_info ["login" ], account_info ["password" ], token )
1427+
1428+ def _is_portaswitch_version_with_token (self ) -> bool :
1429+ """Check if the actual version of PortaSwitch is a version with token support."""
1430+ version = self ._admin_api .get_version ()
1431+ actual_portaswitch_mr = [int (d ) for d in re .findall (r'\d+' , version )]
1432+ expected_portaswitch_mr_with_token_support = [int (d ) for d in
1433+ re .findall (r'\d+' , PORTASWITCH_VERSION_WITH_TOKEN )]
1434+
1435+ return actual_portaswitch_mr < expected_portaswitch_mr_with_token_support
0 commit comments