diff --git a/genshin/client/components/auth/client.py b/genshin/client/components/auth/client.py index 0bde7360..0b9cd260 100644 --- a/genshin/client/components/auth/client.py +++ b/genshin/client/components/auth/client.py @@ -43,6 +43,7 @@ async def os_login_with_password( password: str, *, port: int = 5000, + encrypted: bool = False, token_type: typing.Optional[int] = 6, geetest_solver: typing.Optional[typing.Callable[[SessionMMT], typing.Awaitable[SessionMMTResult]]] = None, ) -> WebLoginResult: @@ -51,7 +52,7 @@ async def os_login_with_password( Note that this will start a webserver if captcha is triggered and `geetest_solver` is not passed. """ - result = await self._os_web_login(account, password, token_type=token_type) + result = await self._os_web_login(account, password, encrypted=encrypted, token_type=token_type) if not isinstance(result, SessionMMT): # Captcha not triggered @@ -62,7 +63,9 @@ async def os_login_with_password( else: mmt_result = await server.solve_geetest(result, port=port) - return await self._os_web_login(account, password, token_type=token_type, mmt_result=mmt_result) + return await self._os_web_login( + account, password, encrypted=encrypted, token_type=token_type, mmt_result=mmt_result + ) @base.region_specific(types.Region.CHINESE) async def cn_login_with_password( @@ -70,6 +73,7 @@ async def cn_login_with_password( account: str, password: str, *, + encrypted: bool = False, port: int = 5000, geetest_solver: typing.Optional[typing.Callable[[SessionMMT], typing.Awaitable[SessionMMTResult]]] = None, ) -> CNWebLoginResult: @@ -78,7 +82,7 @@ async def cn_login_with_password( Note that this will start a webserver if captcha is triggered and `geetest_solver` is not passed. """ - result = await self._cn_web_login(account, password) + result = await self._cn_web_login(account, password, encrypted=encrypted) if not isinstance(result, SessionMMT): # Captcha not triggered @@ -89,7 +93,7 @@ async def cn_login_with_password( else: mmt_result = await server.solve_geetest(result, port=port) - return await self._cn_web_login(account, password, mmt_result=mmt_result) + return await self._cn_web_login(account, password, encrypted=encrypted, mmt_result=mmt_result) @base.region_specific(types.Region.OVERSEAS) async def check_mobile_number_validity(self, mobile: str) -> bool: @@ -111,6 +115,7 @@ async def login_with_mobile_number( self, mobile: str, *, + encrypted: bool = False, port: int = 5000, ) -> MobileLoginResult: """Login with mobile number, returns cookies. @@ -141,6 +146,7 @@ async def login_with_app_password( account: str, password: str, *, + encrypted: bool = False, port: int = 5000, geetest_solver: typing.Optional[typing.Callable[[SessionMMT], typing.Awaitable[SessionMMTResult]]] = None, ) -> AppLoginResult: @@ -153,7 +159,7 @@ async def login_with_app_password( 2. Email verification is triggered (can happen if you first login with a new device). """ - result = await self._app_login(account, password) + result = await self._app_login(account, password, encrypted=encrypted) if isinstance(result, SessionMMT): # Captcha triggered @@ -162,7 +168,7 @@ async def login_with_app_password( else: mmt_result = await server.solve_geetest(result, port=port) - result = await self._app_login(account, password, mmt_result=mmt_result) + result = await self._app_login(account, password, encrypted=encrypted, mmt_result=mmt_result) if isinstance(result, ActionTicket): # Email verification required @@ -179,7 +185,7 @@ async def login_with_app_password( code = await server.enter_code(port=port) await self._verify_email(code, result) - result = await self._app_login(account, password, ticket=result) + result = await self._app_login(account, password, encrypted=encrypted, ticket=result) return result @@ -257,12 +263,12 @@ async def os_game_login( account: str, password: str, *, + encrypted: bool = False, port: int = 5000, geetest_solver: typing.Optional[typing.Callable[[RiskyCheckMMT], typing.Awaitable[RiskyCheckMMTResult]]] = None, ) -> GameLoginResult: """Perform a login to the game.""" - password = auth_utility.encrypt_geetest_credentials(password, 2) - result = await self._shield_login(account, password) + result = await self._shield_login(account, password, encrypted=encrypted) if isinstance(result, RiskyCheckMMT): if geetest_solver: @@ -270,7 +276,7 @@ async def os_game_login( else: mmt_result = await server.solve_geetest(result, port=port) - result = await self._shield_login(account, password, mmt_result=mmt_result) + result = await self._shield_login(account, password, encrypted=encrypted, mmt_result=mmt_result) if not result.device_grant_required: return await self._os_game_login(result.account.uid, result.account.token) diff --git a/genshin/client/components/auth/subclients/app.py b/genshin/client/components/auth/subclients/app.py index 446f0196..16f88140 100644 --- a/genshin/client/components/auth/subclients/app.py +++ b/genshin/client/components/auth/subclients/app.py @@ -32,6 +32,7 @@ async def _app_login( # noqa: D102 missing docstring in overload? account: str, password: str, *, + encrypted: bool = ..., mmt_result: SessionMMTResult, ticket: None = ..., ) -> typing.Union[AppLoginResult, ActionTicket]: ... @@ -42,6 +43,7 @@ async def _app_login( # noqa: D102 missing docstring in overload? account: str, password: str, *, + encrypted: bool = ..., mmt_result: None = ..., ticket: ActionTicket, ) -> AppLoginResult: ... @@ -52,6 +54,7 @@ async def _app_login( # noqa: D102 missing docstring in overload? account: str, password: str, *, + encrypted: bool = ..., mmt_result: None = ..., ticket: None = ..., ) -> typing.Union[AppLoginResult, SessionMMT, ActionTicket]: ... @@ -61,6 +64,7 @@ async def _app_login( account: str, password: str, *, + encrypted: bool = False, mmt_result: typing.Optional[SessionMMTResult] = None, ticket: typing.Optional[ActionTicket] = None, ) -> typing.Union[AppLoginResult, SessionMMT, ActionTicket]: @@ -83,8 +87,8 @@ async def _app_login( headers["x-rpc-verify"] = ticket.to_rpc_verify_header() payload = { - "account": auth_utility.encrypt_geetest_credentials(account, 1), - "password": auth_utility.encrypt_geetest_credentials(password, 1), + "account": account if encrypted else auth_utility.encrypt_geetest_credentials(account, 1), + "password": password if encrypted else auth_utility.encrypt_geetest_credentials(password, 1), } async with aiohttp.ClientSession() as session: diff --git a/genshin/client/components/auth/subclients/game.py b/genshin/client/components/auth/subclients/game.py index aa20f59a..1f98bdbe 100644 --- a/genshin/client/components/auth/subclients/game.py +++ b/genshin/client/components/auth/subclients/game.py @@ -47,6 +47,7 @@ async def _shield_login( # noqa: D102 missing docstring in overload? account: str, password: str, *, + encrypted: bool = ..., mmt_result: RiskyCheckMMTResult, ) -> ShieldLoginResponse: ... @@ -56,11 +57,17 @@ async def _shield_login( # noqa: D102 missing docstring in overload? account: str, password: str, *, + encrypted: bool = ..., mmt_result: None = ..., ) -> typing.Union[ShieldLoginResponse, RiskyCheckMMT]: ... async def _shield_login( - self, account: str, password: str, *, mmt_result: typing.Optional[RiskyCheckMMTResult] = None + self, + account: str, + password: str, + *, + encrypted: bool = False, + mmt_result: typing.Optional[RiskyCheckMMTResult] = None, ) -> typing.Union[ShieldLoginResponse, RiskyCheckMMT]: """Log in with the given account and password. @@ -80,7 +87,11 @@ async def _shield_login( else: headers["x-rpc-risky"] = auth_utility.generate_risky_header(check_result.id) - payload = {"account": account, "password": password, "is_crypto": True} + payload = { + "account": account, + "password": password if encrypted else auth_utility.encrypt_geetest_credentials(password, 2), + "is_crypto": True, + } async with aiohttp.ClientSession() as session: async with session.post( routes.SHIELD_LOGIN_URL.get_url(self.region, self.default_game), json=payload, headers=headers diff --git a/genshin/client/components/auth/subclients/web.py b/genshin/client/components/auth/subclients/web.py index 76201b2c..009e7ef3 100644 --- a/genshin/client/components/auth/subclients/web.py +++ b/genshin/client/components/auth/subclients/web.py @@ -28,6 +28,7 @@ async def _os_web_login( # noqa: D102 missing docstring in overload? account: str, password: str, *, + encrypted: bool = ..., token_type: typing.Optional[int] = ..., mmt_result: SessionMMTResult, ) -> WebLoginResult: ... @@ -38,6 +39,7 @@ async def _os_web_login( # noqa: D102 missing docstring in overload? account: str, password: str, *, + encrypted: bool = ..., token_type: typing.Optional[int] = ..., mmt_result: None = ..., ) -> typing.Union[SessionMMT, WebLoginResult]: ... @@ -48,6 +50,7 @@ async def _os_web_login( account: str, password: str, *, + encrypted: bool = False, token_type: typing.Optional[int] = 6, mmt_result: typing.Optional[SessionMMTResult] = None, ) -> typing.Union[SessionMMT, WebLoginResult]: @@ -60,8 +63,8 @@ async def _os_web_login( headers["x-rpc-aigis"] = mmt_result.to_aigis_header() payload = { - "account": auth_utility.encrypt_geetest_credentials(account, 1), - "password": auth_utility.encrypt_geetest_credentials(password, 1), + "account": account if encrypted else auth_utility.encrypt_geetest_credentials(account, 1), + "password": password if encrypted else auth_utility.encrypt_geetest_credentials(password, 1), "token_type": token_type, } @@ -94,6 +97,7 @@ async def _cn_web_login( # noqa: D102 missing docstring in overload? account: str, password: str, *, + encrypted: bool = ..., mmt_result: SessionMMTResult, ) -> CNWebLoginResult: ... @@ -103,6 +107,7 @@ async def _cn_web_login( # noqa: D102 missing docstring in overload? account: str, password: str, *, + encrypted: bool = ..., mmt_result: None = ..., ) -> typing.Union[SessionMMT, CNWebLoginResult]: ... @@ -112,6 +117,7 @@ async def _cn_web_login( account: str, password: str, *, + encrypted: bool = False, mmt_result: typing.Optional[SessionMMTResult] = None, ) -> typing.Union[SessionMMT, CNWebLoginResult]: """ @@ -127,8 +133,8 @@ async def _cn_web_login( headers["x-rpc-aigis"] = mmt_result.to_aigis_header() payload = { - "account": auth_utility.encrypt_geetest_credentials(account, 2), - "password": auth_utility.encrypt_geetest_credentials(password, 2), + "account": account if encrypted else auth_utility.encrypt_geetest_credentials(account, 2), + "password": password if encrypted else auth_utility.encrypt_geetest_credentials(password, 2), } async with aiohttp.ClientSession() as session: @@ -156,6 +162,7 @@ async def _send_mobile_otp( self, mobile: str, *, + encrypted: bool = False, mmt_result: typing.Optional[SessionMMTResult] = None, ) -> typing.Union[None, SessionMMT]: """Attempt to send OTP to the provided mobile number. @@ -170,7 +177,7 @@ async def _send_mobile_otp( headers["x-rpc-aigis"] = mmt_result.to_aigis_header() payload = { - "mobile": auth_utility.encrypt_geetest_credentials(mobile, 2), + "mobile": mobile if encrypted else auth_utility.encrypt_geetest_credentials(mobile, 2), "area_code": auth_utility.encrypt_geetest_credentials("+86", 2), } @@ -192,7 +199,7 @@ async def _send_mobile_otp( return None - async def _login_with_mobile_otp(self, mobile: str, otp: str) -> MobileLoginResult: + async def _login_with_mobile_otp(self, mobile: str, otp: str, *, encrypted: bool = False) -> MobileLoginResult: """Login with OTP and mobile number. Returns cookies if OTP matches the one sent, raises an error otherwise. @@ -203,7 +210,7 @@ async def _login_with_mobile_otp(self, mobile: str, otp: str) -> MobileLoginResu } payload = { - "mobile": auth_utility.encrypt_geetest_credentials(mobile, 2), + "mobile": mobile if encrypted else auth_utility.encrypt_geetest_credentials(mobile, 2), "area_code": auth_utility.encrypt_geetest_credentials("+86", 2), "captcha": otp, }