Skip to content

Commit ed0cd32

Browse files
authored
gdev (#305)
* Checkstyle will not stop you building now, but you are still expected to correct issues before submitting a PR. fixed issue with checkstyle in google auto login. * Checkstyle fix * Added time to new provider * added time
1 parent a596307 commit ed0cd32

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/main/java/com/pokegoapi/auth/GoogleAutoCredentialProvider.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo;
44
import com.pokegoapi.exceptions.LoginFailedException;
55
import com.pokegoapi.exceptions.RemoteServerException;
6+
import com.pokegoapi.util.SystemTimeImpl;
7+
import com.pokegoapi.util.Time;
68
import okhttp3.OkHttpClient;
79
import svarzee.gps.gpsoauth.AuthToken;
810
import svarzee.gps.gpsoauth.Gpsoauth;
@@ -23,9 +25,9 @@ public class GoogleAutoCredentialProvider extends CredentialProvider {
2325

2426
private final Gpsoauth gpsoauth;
2527
private final String username;
28+
private Time time;
2629
private TokenInfo tokenInfo;
2730

28-
2931
/**
3032
* Constructs credential provider using username and password
3133
*
@@ -34,11 +36,30 @@ public class GoogleAutoCredentialProvider extends CredentialProvider {
3436
* @throws LoginFailedException - login failed possibly due to invalid credentials
3537
* @throws RemoteServerException - some server/network failure
3638
*/
39+
@Deprecated
3740
public GoogleAutoCredentialProvider(OkHttpClient httpClient, String username, String password)
3841
throws LoginFailedException, RemoteServerException {
3942
this.gpsoauth = new Gpsoauth(httpClient);
4043
this.username = username;
4144
this.tokenInfo = login(username, password);
45+
this.time = new SystemTimeImpl();
46+
}
47+
48+
/**
49+
* Constructs credential provider using username and password
50+
*
51+
* @param username - google username
52+
* @param password - google password
53+
* @param Time - time object
54+
* @throws LoginFailedException - login failed possibly due to invalid credentials
55+
* @throws RemoteServerException - some server/network failure
56+
*/
57+
public GoogleAutoCredentialProvider(OkHttpClient httpClient, String username, String password, Time time)
58+
throws LoginFailedException, RemoteServerException {
59+
this.gpsoauth = new Gpsoauth(httpClient);
60+
this.username = username;
61+
this.tokenInfo = login(username, password);
62+
this.time = time;
4263
}
4364

4465
private TokenInfo login(String username, String password)
@@ -86,7 +107,7 @@ public AuthInfo getAuthInfo() throws LoginFailedException, RemoteServerException
86107

87108
@Override
88109
public boolean isTokenIdExpired() {
89-
return tokenInfo.authToken.getExpiry() > System.currentTimeMillis() / 1000 - 60;
110+
return tokenInfo.authToken.getExpiry() > time.currentTimeMillis() / 1000 - 60;
90111
}
91112

92113
private static class TokenInfo {

0 commit comments

Comments
 (0)