From dcc45e79e1ac1a1eee036fe0a8fda87dba2c9544 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 14 Aug 2024 15:25:34 +0200 Subject: [PATCH] remove gmail-oauth2 - add a device message for existing profiles potentially using gmail - reset oauth2 method for existing profiles on opening login screen - do not offer gmail-oauth2 for new profiles --- .../java/com/b44t/messenger/DcContext.java | 9 +++++++++ .../securesms/ConversationListActivity.java | 16 ++++++++++++++++ .../securesms/RegistrationActivity.java | 18 +++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/b44t/messenger/DcContext.java b/src/main/java/com/b44t/messenger/DcContext.java index a194fca737..df59a248d5 100644 --- a/src/main/java/com/b44t/messenger/DcContext.java +++ b/src/main/java/com/b44t/messenger/DcContext.java @@ -260,6 +260,15 @@ public void assumeMultiDevice() { } } + public boolean isGmailOauth2Addr(String addr) { + final String oauth2url = getOauth2Url(addr, "chat.delta:/foo"); + return isGmailOauth2Url(oauth2url); + } + + public boolean isGmailOauth2Url(String oauth2url) { + return oauth2url.startsWith("https://accounts.google.com/"); + } + /** * @return true if at least one chat has location streaming enabled */ diff --git a/src/main/java/org/thoughtcrime/securesms/ConversationListActivity.java b/src/main/java/org/thoughtcrime/securesms/ConversationListActivity.java index 852298cad0..1e1e7aaa8d 100644 --- a/src/main/java/org/thoughtcrime/securesms/ConversationListActivity.java +++ b/src/main/java/org/thoughtcrime/securesms/ConversationListActivity.java @@ -18,6 +18,8 @@ import static org.thoughtcrime.securesms.ConversationActivity.CHAT_ID_EXTRA; import static org.thoughtcrime.securesms.ConversationActivity.STARTING_POSITION_EXTRA; +import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_ADDRESS; +import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_SERVER_FLAGS; import static org.thoughtcrime.securesms.util.RelayUtil.acquireRelayMessageContent; import static org.thoughtcrime.securesms.util.RelayUtil.getDirectSharingChatId; import static org.thoughtcrime.securesms.util.RelayUtil.getSharedTitle; @@ -141,6 +143,20 @@ protected void onCreate(Bundle icicle, boolean ready) { } // /add info + + // remove gmail oauth2 + final int serverFlags = dcContext.getConfigInt(CONFIG_SERVER_FLAGS); + if ((serverFlags & DcContext.DC_LP_AUTH_OAUTH2)!=0) { + Util.runOnAnyBackgroundThread(() -> { + if (dcContext.isGmailOauth2Addr(dcContext.getConfig(CONFIG_ADDRESS))) { + final DcMsg msg = new DcMsg(dcContext, DcMsg.DC_MSG_TEXT); + msg.setText("⚠️ GMail Users: If you have problems using GMail, go to \"Settings / Advanced / Password and Account\".\n\nThere, login again using an \"App Password\"."); + dcContext.addDeviceMsg("info_about_gmail_oauth2_removal8", msg); + } + }); + } + // /remove gmail oauth2 + } catch(Exception e) { e.printStackTrace(); } diff --git a/src/main/java/org/thoughtcrime/securesms/RegistrationActivity.java b/src/main/java/org/thoughtcrime/securesms/RegistrationActivity.java index b5fff107fb..f152ec172b 100644 --- a/src/main/java/org/thoughtcrime/securesms/RegistrationActivity.java +++ b/src/main/java/org/thoughtcrime/securesms/RegistrationActivity.java @@ -231,7 +231,16 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { } int serverFlags = DcHelper.getInt(this, CONFIG_SERVER_FLAGS); int sel = 0; - if((serverFlags&DcContext.DC_LP_AUTH_OAUTH2)!=0) sel = 1; + if((serverFlags&DcContext.DC_LP_AUTH_OAUTH2)!=0) { + sel = 1; + + // remove gmail oauth2 + if (DcHelper.getContext(this).isGmailOauth2Addr(email)) { // this is a blocking call, not perfect, but as rarely used and temporary, good enough + sel = 0; + updateProviderInfo(); // we refer to the hints in the device message, show them immediately + } + // /remove gmail oauth2 + } authMethod.setSelection(sel); expandAdvanced = expandAdvanced || sel != 0; @@ -424,6 +433,13 @@ protected Void doInBackground(Void... voids) { // and should be whitelisted by the supported oauth2 services String redirectUrl = "chat.delta:/"+BuildConfig.APPLICATION_ID+"/auth"; oauth2url = dcContext.getOauth2Url(email, redirectUrl); + + // remove gmail oauth2 + if (dcContext.isGmailOauth2Url(oauth2url)) { + oauth2url = null; + } + // /remove gmail oauth2 + return null; }