Log token expiration

pull/187/head
M66B 4 years ago
parent b0dd941d69
commit 21c8868189

@ -53,6 +53,13 @@ public class GmailState {
return token;
}
Long getAccessTokenExpirationTime() {
if (token == null || acquired == 0)
return null;
else
return acquired + TOKEN_LIFETIME;
}
void refresh(@NonNull Context context, @NonNull String user, boolean expire) throws AuthenticatorException, OperationCanceledException, IOException {
if (expire || acquired + TOKEN_LIFETIME < new Date().getTime())
try {

@ -33,6 +33,7 @@ import net.openid.appauth.NoClientAuthentication;
import org.json.JSONException;
import java.io.IOException;
import java.util.Date;
import java.util.Objects;
import java.util.concurrent.Semaphore;
@ -84,6 +85,9 @@ public class ServiceAuthenticator extends Authenticator {
if (auth == AUTH_TYPE_GMAIL) {
GmailState authState = GmailState.jsonDeserialize(password);
authState.refresh(context, user, expire);
Long expiration = authState.getAccessTokenExpirationTime();
if (expiration != null)
EntityLog.log(context, user + " token expiration=" + new Date(expiration));
String newPassword = authState.jsonSerializeString();
if (!Objects.equals(password, newPassword)) {
@ -96,6 +100,9 @@ public class ServiceAuthenticator extends Authenticator {
} else if (auth == AUTH_TYPE_OAUTH) {
AuthState authState = AuthState.jsonDeserialize(password);
OAuthRefresh(context, provider, authState);
Long expiration = authState.getAccessTokenExpirationTime();
if (expiration != null)
EntityLog.log(context, user + " token expiration=" + new Date(expiration));
String newPassword = authState.jsonSerializeString();
if (!Objects.equals(password, newPassword)) {

Loading…
Cancel
Save