Skip to content
Merged

gdev #305

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ checkstyle {
checkstyleMain.doLast {
def outputFile = file(checkstyleOutputDir + "main.xml")
if (outputFile.exists() && outputFile.text.contains("<error ")) {
throw new GradleException("There were checkstyle warnings! For more info check $outputFile")
logger.warn("!!!!-----------------------------------!!!!")
logger.warn("There were checkstyle warnings! For more info check $outputFile")
logger.warn("PLEASE CORRECT BEFORE SUBMITTING A PULLREQUEST")
logger.warn("!!!!-----------------------------------!!!!")
}
}

Expand Down
31 changes: 27 additions & 4 deletions src/main/java/com/pokegoapi/auth/GoogleAutoCredentialProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo;
import com.pokegoapi.exceptions.LoginFailedException;
import com.pokegoapi.exceptions.RemoteServerException;
import com.pokegoapi.util.SystemTimeImpl;
import com.pokegoapi.util.Time;
import okhttp3.OkHttpClient;
import svarzee.gps.gpsoauth.AuthToken;
import svarzee.gps.gpsoauth.Gpsoauth;
Expand All @@ -23,9 +25,9 @@ public class GoogleAutoCredentialProvider extends CredentialProvider {

private final Gpsoauth gpsoauth;
private final String username;
private Time time;
private TokenInfo tokenInfo;


/**
* Constructs credential provider using username and password
*
Expand All @@ -34,14 +36,34 @@ public class GoogleAutoCredentialProvider extends CredentialProvider {
* @throws LoginFailedException - login failed possibly due to invalid credentials
* @throws RemoteServerException - some server/network failure
*/
@Deprecated
public GoogleAutoCredentialProvider(OkHttpClient httpClient, String username, String password)
throws LoginFailedException, RemoteServerException {
this.gpsoauth = new Gpsoauth(httpClient);
this.username = username;
this.tokenInfo = login(username, password);
this.time = new SystemTimeImpl();
}

/**
* Constructs credential provider using username and password
*
* @param username - google username
* @param password - google password
* @param Time - time object
* @throws LoginFailedException - login failed possibly due to invalid credentials
* @throws RemoteServerException - some server/network failure
*/
public GoogleAutoCredentialProvider(OkHttpClient httpClient, String username, String password, Time time)
throws LoginFailedException, RemoteServerException {
this.gpsoauth = new Gpsoauth(httpClient);
this.username = username;
this.tokenInfo = login(username, password);
this.time = time;
}

private TokenInfo login(String username, String password) throws RemoteServerException, LoginFailedException {
private TokenInfo login(String username, String password)
throws RemoteServerException, LoginFailedException {
try {
String masterToken = gpsoauth.performMasterLoginForToken(username, password, GOOGLE_LOGIN_ANDROID_ID);
AuthToken authToken = gpsoauth.performOAuthForToken(username, masterToken, GOOGLE_LOGIN_ANDROID_ID,
Expand All @@ -54,7 +76,8 @@ private TokenInfo login(String username, String password) throws RemoteServerExc
}
}

private TokenInfo refreshToken(String username, String refreshToken) throws RemoteServerException, LoginFailedException {
private TokenInfo refreshToken(String username, String refreshToken)
throws RemoteServerException, LoginFailedException {
try {
AuthToken authToken = gpsoauth.performOAuthForToken(username, refreshToken, GOOGLE_LOGIN_ANDROID_ID,
GOOGLE_LOGIN_SERVICE, GOOGLE_LOGIN_APP, GOOGLE_LOGIN_CLIENT_SIG);
Expand Down Expand Up @@ -84,7 +107,7 @@ public AuthInfo getAuthInfo() throws LoginFailedException, RemoteServerException

@Override
public boolean isTokenIdExpired() {
return tokenInfo.authToken.getExpiry() > System.currentTimeMillis() / 1000 - 60;
return tokenInfo.authToken.getExpiry() > time.currentTimeMillis() / 1000 - 60;
}

private static class TokenInfo {
Expand Down