Skip to content

Commit

Permalink
Removed unneeded requirements for gsf id on auth requests
Browse files Browse the repository at this point in the history
  • Loading branch information
yeriomin committed Feb 6, 2017
1 parent 017fa74 commit 13483ab
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions src/main/java/com/github/yeriomin/playstoreapi/GooglePlayAPI.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.github.yeriomin.playstoreapi;

import com.google.protobuf.InvalidProtocolBufferException;

import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;

/**
* This class provides
Expand Down Expand Up @@ -124,26 +128,24 @@ public void setGsfId(String gsfId) {
* using <code>getToken()</code> or from returned
* {@link AndroidCheckinResponse} instance.
*/
public String getGsfId(String password) throws IOException {
AndroidCheckinRequest request = this.deviceInfoProvider.generateAndroidCheckinRequest();

public String getGsfId(String ac2dmToken) throws IOException {
// this first checkin is for generating android-id
AndroidCheckinResponse checkinResponse = checkin(request.toByteArray());
this.gsfId = BigInteger.valueOf(checkinResponse.getAndroidId()).toString(16);
String securityToken = BigInteger.valueOf(checkinResponse.getSecurityToken()).toString(16);
AndroidCheckinRequest request = this.deviceInfoProvider.generateAndroidCheckinRequest();
AndroidCheckinResponse checkinResponse1 = checkin(request.toByteArray());
String securityToken = BigInteger.valueOf(checkinResponse1.getSecurityToken()).toString(16);

// this is the second checkin to match credentials with android-id
AndroidCheckinRequest.Builder checkInbuilder = AndroidCheckinRequest.newBuilder(request);
String AC2DMToken = getAC2DMToken(password);
String gsfId = BigInteger.valueOf(checkinResponse1.getAndroidId()).toString(16);
AndroidCheckinRequest build = checkInbuilder
.setId(new BigInteger(this.gsfId, 16).longValue())
.setSecurityToken(new BigInteger(securityToken, 16).longValue())
.addAccountCookie("[" + this.email + "]")
.addAccountCookie(AC2DMToken)
.build();
// this is the second checkin to match credentials with android-id
.setId(new BigInteger(gsfId, 16).longValue())
.setSecurityToken(new BigInteger(securityToken, 16).longValue())
.addAccountCookie("[" + this.email + "]")
.addAccountCookie(ac2dmToken)
.build();
checkin(build.toByteArray());

return this.gsfId;
return gsfId;
}

/**
Expand All @@ -166,7 +168,6 @@ public String getToken(String password) throws IOException {
Map<String, String> params = getDefaultLoginParams(password);
params.put("service", "androidmarket");
params.put("app", "com.android.vending");
params.put("androidId", this.gsfId);
byte[] responseBytes = getClient().post(URL_LOGIN, params, getDefaultHeaders());
Map<String, String> response = parseResponse(new String(responseBytes));
if (response.containsKey("Auth")) {
Expand Down Expand Up @@ -433,8 +434,8 @@ public void deleteReview(String packageName) throws IOException {
*/
public UploadDeviceConfigResponse uploadDeviceConfig() throws IOException {
UploadDeviceConfigRequest request = UploadDeviceConfigRequest.newBuilder()
.setDeviceConfiguration(this.deviceInfoProvider.getDeviceConfigurationProto())
.build();
.setDeviceConfiguration(this.deviceInfoProvider.getDeviceConfigurationProto())
.build();
Map<String, String> headers = getDefaultHeaders();
headers.put("X-DFE-Enabled-Experiments", "cl:billing.select_add_instrument_by_default");
headers.put("X-DFE-Unsupported-Experiments", "nocache:billing.use_charging_poller,market_emails,buyer_currency,prod_baseline,checkin.set_asset_paid_app_field,shekel_test,content_ratings,buyer_currency_in_app,nocache:encrypted_apk,recent_changes");
Expand Down Expand Up @@ -482,7 +483,7 @@ private Map<String, String> getDefaultLoginParams(String password) {
* Using Accept-Language you can fetch localized informations such as reviews and descriptions.
* Note that changing this value has no affect on localized application list that
* server provides. It depends on only your IP location.
*
*
*/
private Map<String, String> getDefaultHeaders() {
Map<String, String> headers = new HashMap<>();
Expand Down Expand Up @@ -583,10 +584,10 @@ public SearchResponse next() {
}

if (null != response
&& response.getDocCount() > 0
&& response.getDocList().get(0).hasContainerMetadata()
&& response.getDocList().get(0).getContainerMetadata().hasNextPageUrl()
) {
&& response.getDocCount() > 0
&& response.getDocList().get(0).hasContainerMetadata()
&& response.getDocList().get(0).getContainerMetadata().hasNextPageUrl()
) {
this.nextPageUrl = FDFE_URL + response.getDocList().get(0).getContainerMetadata().getNextPageUrl();
} else {
this.nextPageUrl = null;
Expand Down

0 comments on commit 13483ab

Please sign in to comment.