Skip to content

Commit

Permalink
Fix second factor auth
Browse files Browse the repository at this point in the history
  • Loading branch information
python273 committed Nov 17, 2020
1 parent e7dce49 commit e014b1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
7 changes: 6 additions & 1 deletion vk_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,16 @@ def send(self, request, **kwargs):

total = end - start

body = request.body
if body and len(body) > 1024:
body = body[:1024] + '[STRIPPED]'

print(
'{:0.2f} {} {} {} {}'.format(
'{:0.2f} {} {} {} {} {}'.format(
total,
request.method,
request.url,
repr(body),
response.status_code,
response.history
)
Expand Down
21 changes: 14 additions & 7 deletions vk_api/vk_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
RE_LOGIN_HASH = re.compile(r'name="lg_h" value="([a-z0-9]+)"')
RE_CAPTCHAID = re.compile(r"onLoginCaptcha\('(\d+)'")
RE_NUMBER_HASH = re.compile(r"al_page: '3', hash: '([a-z0-9]+)'")
RE_AUTH_HASH = re.compile(
r"\{.*?act: 'a_authcheck_code'.+?hash: '([a-z_0-9]+)'.*?\}"
)
RE_AUTH_HASH = re.compile(r"Authcheck\.init\('([a-z_0-9]+)'")
RE_TOKEN_URL = re.compile(r'location\.href = "(.*?)"\+addr;')

RE_PHONE_PREFIX = re.compile(r'label ta_r">\+(.*?)<')
Expand Down Expand Up @@ -317,19 +315,28 @@ def _pass_twofactor(self, auth_response):
:param auth_response: страница с приглашением к аутентификации
"""
code, remember_device = self.error_handlers[TWOFACTOR_CODE]()

auth_hash = search_re(RE_AUTH_HASH, auth_response.text)

if not auth_hash:
raise TwoFactorError(
'Two factor authentication can not be passed:'
' could not find "hash" value. Please create a bugreport'
)

code, remember_device = self.error_handlers[TWOFACTOR_CODE]()

values = {
'act': 'a_authcheck_code',
'al': '1',
'code': code,
'remember': int(remember_device),
'hash': auth_hash,
'remember': int(remember_device),
}

response = self.http.post('https://vk.com/al_login.php', values)
response = self.http.post(
'https://vk.com/al_login.php?act=a_authcheck_code',
values
)
data = json.loads(response.text.lstrip('<!--'))
status = data['payload'][0]

Expand Down

0 comments on commit e014b1f

Please sign in to comment.