Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions vkmax/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,35 @@ async def sign_in(self, sms_token: str, sms_code: int):
}
)

if "error" in verification_response["payload"]:
raise Exception(verification_response["payload"]["error"])

if "passwordChallenge" in verification_response["payload"]:
# TODO: smh indicate that 2fa required
return verification_response

try:
phone = verification_response["payload"]["profile"]["contact"]["phone"]
except:
phone = '[?]'
_logger.warning('Got no phone number in server response')
_logger.info(f'Successfully logged in as {phone}')

self._is_logged_in = True
await self._start_keepalive_task()

return verification_response

@ensure_connected
async def continue_2fa(self, track_id: str, password: str):
verification_response = await self.invoke_method(
opcode=115,
payload={
"trackId": track_id,
"password": password
}
)

if "error" in verification_response["payload"]:
raise Exception(verification_response["payload"]["error"])

Expand Down Expand Up @@ -263,6 +292,10 @@ async def login_by_token(self, token: str, device_id: Optional[str] = None):

return login_response

@ensure_connected
async def logout(self):
await self.invoke_method(opcode=20)

@property
def device_id(self) -> Optional[str]:
return self._device_id