1515from aiohttp import ClientSession , FormData
1616from botocore .client import BaseClient
1717from botocore .config import Config
18+ from botocore .exceptions import ClientError
1819from warrant_lite import WarrantLite
1920
2021from pyoverkiz .auth .base import AuthContext , AuthStrategy
@@ -212,17 +213,6 @@ async def _request_access_token(
212213class CozytouchAuthStrategy (SessionLoginStrategy ):
213214 """Authentication strategy using Cozytouch session-based login."""
214215
215- def __init__ (
216- self ,
217- credentials : UsernamePasswordCredentials ,
218- session : ClientSession ,
219- server : ServerConfig ,
220- ssl_context : ssl .SSLContext | bool ,
221- api_type : APIType ,
222- ) -> None :
223- """Initialize CozytouchAuthStrategy with given parameters."""
224- super ().__init__ (credentials , session , server , ssl_context , api_type )
225-
226216 async def login (self ) -> None :
227217 """Perform login using Cozytouch username and password."""
228218 form = FormData (
@@ -265,20 +255,9 @@ async def login(self) -> None:
265255class NexityAuthStrategy (SessionLoginStrategy ):
266256 """Authentication strategy using Nexity session-based login."""
267257
268- def __init__ (
269- self ,
270- credentials : UsernamePasswordCredentials ,
271- session : ClientSession ,
272- server : ServerConfig ,
273- ssl_context : ssl .SSLContext | bool ,
274- api_type : APIType ,
275- ) -> None :
276- """Initialize NexityAuthStrategy with given parameters."""
277- super ().__init__ (credentials , session , server , ssl_context , api_type )
278-
279258 async def login (self ) -> None :
280259 """Perform login using Nexity username and password."""
281- loop = asyncio .get_event_loop ()
260+ loop = asyncio .get_running_loop ()
282261
283262 def _client () -> BaseClient :
284263 return boto3 .client (
@@ -296,8 +275,11 @@ def _client() -> BaseClient:
296275
297276 try :
298277 tokens = await loop .run_in_executor (None , aws .authenticate_user )
299- except Exception as error :
300- raise NexityBadCredentialsException () from error
278+ except ClientError as error :
279+ code = error .response .get ("Error" , {}).get ("Code" )
280+ if code in {"NotAuthorizedException" , "UserNotFoundException" }:
281+ raise NexityBadCredentialsException () from error
282+ raise
301283
302284 id_token = tokens ["AuthenticationResult" ]["IdToken" ]
303285
0 commit comments