From 21c8868189f2f019c6b3d485b5415c1e98f19a49 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 27 Oct 2020 09:01:33 +0100 Subject: [PATCH] Log token expiration --- app/src/main/java/eu/faircode/email/GmailState.java | 7 +++++++ .../main/java/eu/faircode/email/ServiceAuthenticator.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/GmailState.java b/app/src/main/java/eu/faircode/email/GmailState.java index 3772b2129c..c8c091f589 100644 --- a/app/src/main/java/eu/faircode/email/GmailState.java +++ b/app/src/main/java/eu/faircode/email/GmailState.java @@ -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 { diff --git a/app/src/main/java/eu/faircode/email/ServiceAuthenticator.java b/app/src/main/java/eu/faircode/email/ServiceAuthenticator.java index cd301d826f..cccffed80a 100644 --- a/app/src/main/java/eu/faircode/email/ServiceAuthenticator.java +++ b/app/src/main/java/eu/faircode/email/ServiceAuthenticator.java @@ -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)) {