From 4e1f582b17370e72a22a5b4de1c4d72ed068b06b Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 15 Oct 2020 11:43:35 +0200 Subject: [PATCH] Call sign_in during sign_up if needed to send the code --- telethon/client/auth.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/telethon/client/auth.py b/telethon/client/auth.py index 8c91a694..8e9cb0ef 100644 --- a/telethon/client/auth.py +++ b/telethon/client/auth.py @@ -427,6 +427,23 @@ class AuthMethods: if me: return me + # To prevent abuse, one has to try to sign in before signing up. This + # is the current way in which Telegram validates the code to sign up. + # + # `sign_in` will set `_tos`, so if it's set we don't need to call it + # because the user already tried to sign in. + # + # We're emulating pre-layer 104 behaviour so except the right error: + if not self._tos: + try: + return await self.sign_in( + phone=phone, + code=code, + phone_code_hash=phone_code_hash, + ) + except errors.PhoneNumberUnoccupiedError: + pass # code is correct and was used, now need to sign in + if self._tos and self._tos.text: if self.parse_mode: t = self.parse_mode.unparse(self._tos.text, self._tos.entities)