mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-25 01:06:04 +00:00
Log token expiration
This commit is contained in:
parent
b0dd941d69
commit
21c8868189
2 changed files with 14 additions and 0 deletions
|
@ -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…
Reference in a new issue