-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
113 lines (97 loc) · 4.16 KB
/
auth.py
File metadata and controls
113 lines (97 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import requests
import json
import zlib
from hashlib import md5
from pykov import constants
from pykov import Harvester
from random import uniform
from time import sleep
# Object used to login and store session info
class Auth:
def __init__(self, hwid):
self.rsp = None
self.sess = None
self.hwid = hwid
# Login to launcher with POST request; use 2fa if needed
def login(self, email, password):
url = "{}/launcher/login?launcherVersion={}&branch=live".format(
constants.LAUNCHER_ENDPOINT, constants.LAUNCHER_VERSION
)
password = md5(password.encode('utf-8')).hexdigest()
url = url.rstrip()
self.hwid = self.hwid.rstrip()
body = {"email":email, "pass":password, "hwCode":self.hwid, "captcha":""}
headers = {
'User-Agent': 'BSG Launcher {}'.format(constants.LAUNCHER_VERSION),
'Content-Type': 'application/json',
'Content-Encoding': 'gzip' }
cookies = {}
self.rsp = requests.post(url, json=body, headers=headers, cookies=cookies)
print("Login response code: {}".format(self.rsp.status_code))
if self.rsp.status_code == 200:
con = zlib.decompress(self.rsp.content).decode()
if "Need confirm" in con:
print("Need to authorize connection with 2fa")
sleep(uniform(3.5,10.5))
self.sess = self.login_2fa(email)
self.rsp = requests.post(url, json=body, headers=headers, cookies=cookies)
elif "Wrong parameters" in con:
print("Incorrect parameters in POST")
exit(-1)
elif "captcha" in con:
print("Need to bypass captcha...")
sleep(uniform(3.5,10.5))
login_captcha()
else:
print("Successfully logged in")
rsp = zlib.decompress(self.rsp.content).decode()
return json.loads(rsp)
# Bypass the captcha if required
def login_captcha(self):
h = Harvester.harvest("6LexEI4UAAAAAIFtNZALcloZfEgHhB8rEUqC1LwV",
"https://launcher.escapefromtarkov.com/launcher/login",
"127.0.0.1")
h.signin()
h.solve()
# Complete login if two-factor authentication is required; prompt user for input
def login_2fa(self, email):
code = input("Enter the 2fa code: ")
url = "{}/launcher/hardwareCode/activate?launcherVersion={}".format(
constants.LAUNCHER_ENDPOINT, constants.LAUNCHER_VERSION
)
body = {"email":email, "hwCode":self.hwid, "activateCode":code}
headers = {
'User-Agent': 'BSG Launcher {}'.format(constants.LAUNCHER_VERSION),
'Content-Type': 'application/json' }
rsp = requests.post(url, json=body, headers=headers)
content = zlib.decompress(rsp.content).decode()
print("Activation response code: {}".format(rsp.status_code))
print("Activation response: {}".format(content))
return rsp
# Setup a session once we have a connection
def exchange_access_token(self, access_token, hwid):
url = "{}/launcher/game/start?launcherVersion={}&branch=live".format(
constants.PROD_ENDPOINT, constants.LAUNCHER_VERSION
)
body = {"version": {"major":constants.GAME_VERSION, "backend":"6"}, "hwCode":hwid}
headers = {
'Content-Type': 'application/json',
'User-Agent': 'BSG Launcher {}'.format(constants.LAUNCHER_VERSION),
'Authorization': access_token }
content = None
rsp = requests.post(url, json=body, headers=headers)
try:
content = zlib.decompress(rsp.content).decode()
except:
pass
if not content:
print("exchange_access_token failed; {}".format(rsp.status_code))
elif "errmsg" in content and '"err":0,' not in content:
print("Error while authorizing: {}".format(content))
else:
print("Successfully authorized")
return json.loads(content)
print("Unable to complete authorization, exiting")
print(rsp.status_code)
print(content)
exit(-1)