Updated socializer to support again two factor verification

This commit is contained in:
Manuel Cortez 2020-06-29 09:51:55 -05:00
parent f43e9ffccf
commit e3db177d1a
3 changed files with 19 additions and 3 deletions

View File

@ -6,6 +6,10 @@
* the spelling correction module is able to add words to the dictionary so it will learn which words should start to ignore. * the spelling correction module is able to add words to the dictionary so it will learn which words should start to ignore.
### bugfixes
* Now it is possible to perform authentication in accounts using two factor verification again. This issue was caused due to a recent change in the VK workflow for two factor verification processes.
### Changes ### Changes
* The spelling correction module has been rewritten to take advantage of the newest enchant Python module which is more stable and can be added properly to the distribution, as opposed to the first enchant module we have tried. * The spelling correction module has been rewritten to take advantage of the newest enchant Python module which is more stable and can be added properly to the distribution, as opposed to the first enchant module we have tried.

View File

@ -1,7 +1,8 @@
#! /usr/bin/env python #! /usr/bin/env python
""" Upload socializer to the ftp server. This script has been created to be executed from a continuous integrations system. """ Upload socializer to the ftp server. This script has been created to be executed from a continuous integrations system.
Important note: for this script to work, the following conditions should be met: Important note: for this script to work, the following conditions should be met:
* There must be ftp server data, via environment variables (FTP_SERVER, FTP_USERNAME and FTP_PASSWORD) or via arguments to the script call (in the prior order). Connection to this server is done via default ftp port. * There must be ftp server data, via environment variables (FTP_SERVER, FTP_USERNAME and FTP_PASSWORD) or via arguments to the script call (in the prior order). Connection to this server is done via default ftp port via TLS.
* this code assumes it's going to connect to an FTP via TLS.
* If the version to upload is alpha, there's not need of an extra variable. Otherwise, CI_COMMIT_TAG should point to a version as vx.x, where v is a literal and x are numbers, example may be v0.18, v0.25, v0.3. This variable should be set in the environment. * If the version to upload is alpha, there's not need of an extra variable. Otherwise, CI_COMMIT_TAG should point to a version as vx.x, where v is a literal and x are numbers, example may be v0.18, v0.25, v0.3. This variable should be set in the environment.
* Inside the ftp server, the following directory structure will be expected: socializer.su/static/files/. The script will create the <version> folder or alpha if needed. * Inside the ftp server, the following directory structure will be expected: socializer.su/static/files/. The script will create the <version> folder or alpha if needed.
* The script will upload all .exe, .zip and .json files located in the root directory from where it was called. The json files are uploaded to socializer.su/static/files/update and other files are going to socializer.su/static/files/<version>. * The script will upload all .exe, .zip and .json files located in the root directory from where it was called. The json files are uploaded to socializer.su/static/files/update and other files are going to socializer.su/static/files/<version>.
@ -40,7 +41,7 @@ version = os.environ.get("CI_COMMIT_TAG") or "alpha"
version = version.replace("v", "") version = version.replace("v", "")
print("Uploading files to the Socializer server...") print("Uploading files to the Socializer server...")
connection = ftplib.FTP(ftp_server) connection = ftplib.FTP_TLS(ftp_server)
print("Connected to FTP server {}".format(ftp_server,)) print("Connected to FTP server {}".format(ftp_server,))
connection.login(user=ftp_username, passwd=ftp_password) connection.login(user=ftp_username, passwd=ftp_password)
print("Logged in successfully") print("Logged in successfully")

View File

@ -1,5 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" Set of methods used to retrieve access tokens by simulating the official VK application for Android. """ """ Set of methods used to retrieve access tokens by simulating the official VK application for Android.
This is a Python port of the PHP module developed by Vodka2 to retrieve VK audio tokens. More info at https://github.com/vodka2/vk-audio-token
This module, as a Python port, just tries to get the tokens by using the Official VK app's tokens. I did not implemented the Kate mobile functionality as it involves a lot of more work and is not giving any advantage over the official way.
there are a lot of features pending to be applied. Hopefully later I can make it working more efficiently and OOP based.
"""
import random import random
import requests import requests
import logging import logging
@ -60,12 +64,19 @@ def get_non_refreshed(login, password, scope=scope):
params["2fa_supported"] = 1 params["2fa_supported"] = 1
headers = {'User-Agent': user_agent} headers = {'User-Agent': user_agent}
r = requests.get(url, params=params, headers=headers) r = requests.get(url, params=params, headers=headers)
# Let's print this into logs as exceptions so we can catch future errors.
log.exception(r.json()) log.exception(r.json())
# If a 401 error is raised, we need to use 2FA here. # If a 401 error is raised, we need to use 2FA here.
# see https://vk.com/dev/auth_direct (switch lang to russian, english docs are very incomplete in the matter) # see https://vk.com/dev/auth_direct (switch lang to russian, english docs are very incomplete in the matter)
# ToDo: this needs testing after implemented official VK tokens. # ToDo: this needs testing after implemented official VK tokens.
if r.status_code == 401 and "phone_mask" in r.text: if r.status_code == 401 and "phone_mask" in r.text:
t = r.json() t = r.json()
log.exception(t)
validation_sid = t["validation_sid"]
url = "https://api.vk.com/method/auth.validatePhone"
params = dict(v="5.95", sid=validation_sid)
validated = requests.get(url, params=params, headers=headers)
log.exception(validated.json())
code, remember = two_factor_auth() code, remember = two_factor_auth()
url = "https://oauth.vk.com/token" url = "https://oauth.vk.com/token"
params = dict(grant_type="password", lang="en", params = dict(grant_type="password", lang="en",