From bf10ec1fc65b4958d817078346ad521162e01d9b Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 5 Mar 2023 08:42:25 +0100 Subject: [PATCH] Debug: OAuth tokens --- app/src/main/java/eu/faircode/email/Log.java | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java index e7629bffed..9e828a18a5 100644 --- a/app/src/main/java/eu/faircode/email/Log.java +++ b/app/src/main/java/eu/faircode/email/Log.java @@ -111,6 +111,9 @@ import com.sun.mail.iap.ProtocolException; import com.sun.mail.util.FolderClosedIOException; import com.sun.mail.util.MailConnectException; +import net.openid.appauth.AuthState; +import net.openid.appauth.TokenResponse; + import org.json.JSONException; import org.json.JSONObject; @@ -2405,6 +2408,27 @@ public class Log { size += write(os, "\r\n"); } + for (EntityAccount account : accounts) + if (account.synchronize) + try { + String info = null; + if (account.auth_type == ServiceAuthenticator.AUTH_TYPE_OAUTH || + account.auth_type == ServiceAuthenticator.AUTH_TYPE_GRAPH) + info = getTokenInfo(account.password, account.auth_type); + size += write(os, String.format("%s %s\r\n", account.name, info)); + + List identities = db.identity().getSynchronizingIdentities(account.id); + for (EntityIdentity identity : identities) + if (identity.auth_type == ServiceAuthenticator.AUTH_TYPE_OAUTH || + identity.auth_type == ServiceAuthenticator.AUTH_TYPE_GRAPH) + size += write(os, String.format("- %s %s\r\n", + identity.name, getTokenInfo(identity.password, identity.auth_type))); + } catch (Throwable ex) { + size += write(os, ex.toString() + "\r\n"); + } + + size += write(os, "\r\n"); + Map unified = new HashMap<>(); for (EntityFolder folder : db.folder().getFoldersByType(EntityFolder.INBOX)) unified.put(folder.id, folder); @@ -3201,6 +3225,19 @@ public class Log { db.attachment().setDownloaded(attachment.id, target.length()); } + static String getTokenInfo(String password, int auth_type) throws JSONException { + AuthState authState = AuthState.jsonDeserialize(password); + Long expiration = authState.getAccessTokenExpirationTime(); + TokenResponse t = authState.getLastTokenResponse(); + Set scopeSet = (t == null ? null : t.getScopeSet()); + String[] scopes = (scopeSet == null ? new String[0] : scopeSet.toArray(new String[0])); + return String.format("%s expire=%s need=%b %s", + ServiceAuthenticator.getAuthTypeName(auth_type), + (expiration == null ? null : new Date(expiration)), + authState.getNeedsTokenRefresh(), + TextUtils.join(",", scopes)); + } + static SpannableStringBuilder getCiphers() { SpannableStringBuilder ssb = new SpannableStringBuilderEx();