Added auth headers

c21ac5eaf5
This commit is contained in:
Domenico Iezzi 2018-01-26 19:46:23 +01:00
parent 23937e6cb8
commit c4ba7f80b3
No known key found for this signature in database
GPG Key ID: 7AC94D5DDA2FB7EE
2 changed files with 43 additions and 24 deletions

View File

@ -91,7 +91,16 @@ class DeviceBuilder(object):
platform_v=self.device.get('build.version.release'),
model=self.device.get('build.model'),
build_id=self.device.get('build.id'),
supported_abis=self.device.get('platforms'))
supported_abis=self.device.get('platforms').replace(',', ';'))
def getAuthHeaders(self, gsfid):
headers = {"User-Agent": ("GoogleAuth/1.4 ("
"{device} {id}"
")").format(device=self.device.get('build.device'),
id=self.device.get('build.id'))}
if gsfid is not None:
headers['device'] = "{0:x}".format(gsfid)
return headers
def getAuthParams(self, email, passwd):
return {"Email": email,
@ -105,9 +114,9 @@ class DeviceBuilder(object):
"lang": self.locale,
"sdk_version": self.device['build.version.sdk_int']}
def getLoginParams(self, email, encryptedPass):
def getLoginParams(self, email, encrypted_passwd):
return {"Email": email,
"EncryptedPasswd": encryptedPass,
"EncryptedPasswd": encrypted_passwd,
"service": "ac2dm",
"add_account": "1",
"accountType": ACCOUNT,
@ -116,7 +125,7 @@ class DeviceBuilder(object):
"source": "android",
"device_country": self.locale[0:2],
"lang": self.locale,
"sdk_version": self.device['build.version.sdk_int']}
"sdk_version": self.device.get('build.version.sdk_int')}
def getAndroidCheckinRequest(self):
request = googleplay_pb2.AndroidCheckinRequest()

View File

@ -196,7 +196,11 @@ class GooglePlayAPI(object):
def getAuthSubToken(self, email, passwd):
requestParams = self.deviceBuilder.getAuthParams(email, passwd)
response = requests.post(self.AUTHURL, data=requestParams, verify=ssl_verify,
headers = self.deviceBuilder.getAuthHeaders(self.gsfId)
response = requests.post(self.AUTHURL,
data=requestParams,
verify=ssl_verify,
headers=headers,
proxies=self.proxies_config)
data = response.text.split()
params = {}
@ -209,25 +213,27 @@ class GooglePlayAPI(object):
firstToken = params["token"]
if self.debug:
print('Master token: %s' % firstToken)
secondToken = self.getSecondRoundToken(requestParams, firstToken)
secondToken = self.getSecondRoundToken(firstToken, requestParams)
self.setAuthSubToken(secondToken)
elif "error" in params:
raise LoginError("server says: " + params["error"])
else:
raise LoginError("Auth token not found.")
raise LoginError("auth token not found.")
def getSecondRoundToken(self, previousParams, firstToken):
previousParams['Token'] = firstToken
previousParams['service'] = 'androidmarket'
previousParams['check_email'] = '1'
previousParams['token_request_options'] = 'CAA4AQ=='
previousParams['system_partition'] = '1'
previousParams['_opt_is_called_from_account_manager'] = '1'
previousParams['google_play_services_version'] = '11518448'
previousParams.pop('Email')
previousParams.pop('EncryptedPasswd')
def getSecondRoundToken(self, first_token, params):
params['Token'] = first_token
params['service'] = 'androidmarket'
params['check_email'] = '1'
params['token_request_options'] = 'CAA4AQ=='
params['system_partition'] = '1'
params['_opt_is_called_from_account_manager'] = '1'
params['google_play_services_version'] = '11518448'
params.pop('Email')
params.pop('EncryptedPasswd')
headers = self.deviceBuilder.getAuthHeaders(self.gsfId)
response = requests.post(self.AUTHURL,
data=previousParams,
data=params,
headers=headers,
verify=ssl_verify,
proxies=self.proxies_config)
data = response.text.split()
@ -255,12 +261,15 @@ class GooglePlayAPI(object):
url = self.FDFE + path
if datapost is not None:
response = requests.post(url, data=str(datapost),
headers=headers, verify=ssl_verify,
response = requests.post(url,
data=str(datapost),
headers=headers,
verify=ssl_verify,
timeout=60,
proxies=self.proxies_config)
else:
response = requests.get(url, headers=headers,
response = requests.get(url,
headers=headers,
verify=ssl_verify,
timeout=60,
proxies=self.proxies_config)
@ -326,7 +335,8 @@ class GooglePlayAPI(object):
headers = self.getDefaultHeaders()
url = self.FDFE + path
response = requests.get(url, headers=headers,
response = requests.get(url,
headers=headers,
verify=ssl_verify,
timeout=60,
proxies=self.proxies_config)
@ -510,7 +520,7 @@ class GooglePlayAPI(object):
if versionCode is None:
# pick up latest version
versionCode = self.details(packageName)['versionCode']
versionCode = self.details(packageName).get('versionCode')
path = "delivery"
params = {'ot': str(offerType),
@ -577,7 +587,7 @@ class GooglePlayAPI(object):
if versionCode is None:
# pick up latest version
versionCode = self.details(packageName)['versionCode']
versionCode = self.details(packageName).get('versionCode')
path = "purchase"
headers = self.getDefaultHeaders()