mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #3977 from deltachat/adb/remove-oauth
remove deprecated oauth code
This commit is contained in:
@@ -239,18 +239,6 @@
|
||||
android:windowSoftInputMode="stateUnchanged"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
|
||||
<!-- this scheme is used as the redirect_url for getOauth2Url()
|
||||
and should be whitelisted by the supported oauth2 services -->
|
||||
<data android:scheme="chat.delta" android:path="/${applicationId}/auth" tools:ignore="AppLinkUrlError"/>
|
||||
<data android:scheme="chat.delta" android:path="/auth" tools:ignore="AppLinkUrlError"/>
|
||||
|
||||
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".proxy.ProxySettingsActivity"
|
||||
|
||||
@@ -71,9 +71,6 @@ public class DcContext {
|
||||
public final static int DC_QR_REVIVE_VERIFYGROUP = 512;
|
||||
public final static int DC_QR_LOGIN = 520;
|
||||
|
||||
public final static int DC_LP_AUTH_OAUTH2 = 0x2;
|
||||
public final static int DC_LP_AUTH_NORMAL = 0x4;
|
||||
|
||||
public final static int DC_SOCKET_AUTO = 0;
|
||||
public final static int DC_SOCKET_SSL = 1;
|
||||
public final static int DC_SOCKET_STARTTLS = 2;
|
||||
@@ -145,7 +142,6 @@ public class DcContext {
|
||||
public native String getInfo ();
|
||||
public native int getConnectivity ();
|
||||
public native String getConnectivityHtml ();
|
||||
public native String getOauth2Url (String addr, String redirectUrl);
|
||||
public native String initiateKeyTransfer ();
|
||||
public native void imex (int what, String dir);
|
||||
public native String imexHasBackup (String dir);
|
||||
@@ -246,15 +242,6 @@ public class DcContext {
|
||||
setConfigInt("is_muted", muted? 1 : 0);
|
||||
}
|
||||
|
||||
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/");
|
||||
}
|
||||
|
||||
public void restartIo() {
|
||||
stopIo();
|
||||
startIo();
|
||||
|
||||
@@ -133,19 +133,6 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
Prefs.setStringPreference(this, Prefs.LAST_DEVICE_MSG_LABEL, deviceMsgLabel);
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
@@ -94,7 +94,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve
|
||||
|
||||
Spinner imapSecurity;
|
||||
Spinner smtpSecurity;
|
||||
Spinner authMethod;
|
||||
Spinner certCheck;
|
||||
|
||||
private SwitchCompat proxySwitch;
|
||||
@@ -125,7 +124,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve
|
||||
|
||||
imapSecurity = findViewById(R.id.imap_security);
|
||||
smtpSecurity = findViewById(R.id.smtp_security);
|
||||
authMethod = findViewById(R.id.auth_method);
|
||||
certCheck = findViewById(R.id.cert_check);
|
||||
|
||||
proxySwitch = findViewById(R.id.proxy_settings);
|
||||
@@ -216,21 +214,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve
|
||||
smtpSecurity.setSelection(ViewUtil.checkBounds(intVal, smtpSecurity));
|
||||
expandAdvanced = expandAdvanced || intVal != 0;
|
||||
|
||||
int serverFlags = DcHelper.getInt(this, CONFIG_SERVER_FLAGS);
|
||||
int sel = 0;
|
||||
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(ViewUtil.checkBounds(sel, authMethod));
|
||||
expandAdvanced = expandAdvanced || sel != 0;
|
||||
|
||||
int imapCertificateChecks = DcHelper.getInt(this, "imap_certificate_checks");
|
||||
if (imapCertificateChecks == 3) {
|
||||
imapCertificateChecks = 2; // 3 is a deprecated alias for 2
|
||||
@@ -287,7 +270,8 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.do_register) {
|
||||
do_register();
|
||||
updateProviderInfo();
|
||||
onLogin();
|
||||
return true;
|
||||
} else if (id == android.R.id.home) {
|
||||
// handle close button click here
|
||||
@@ -297,26 +281,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void do_register() {
|
||||
// "log in" button clicked - even if oauth2DeclinedByUser is true,
|
||||
// we will ask for oauth2 to allow reverting the decision.
|
||||
checkOauth2start().addListener(new ListenableFuture.Listener<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(Boolean oauth2started) {
|
||||
if(!oauth2started) {
|
||||
updateProviderInfo();
|
||||
onLogin();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(ExecutionException e) {
|
||||
updateProviderInfo();
|
||||
onLogin();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
@@ -335,23 +299,7 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve
|
||||
switch (type) {
|
||||
case EMAIL:
|
||||
verifyEmail(inputEditText);
|
||||
if (!oauth2DeclinedByUser) {
|
||||
checkOauth2start().addListener(new ListenableFuture.Listener<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(Boolean oauth2started) {
|
||||
if (!oauth2started) {
|
||||
updateProviderInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(ExecutionException e) {
|
||||
updateProviderInfo();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
updateProviderInfo();
|
||||
}
|
||||
updateProviderInfo();
|
||||
break;
|
||||
case SERVER:
|
||||
verifyServer(inputEditText);
|
||||
@@ -363,86 +311,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve
|
||||
}
|
||||
}
|
||||
|
||||
private long oauth2Requested = 0;
|
||||
|
||||
// this flag is set, if the user has declined oauth2 at some point;
|
||||
// if so, we won't bother em on focus changes again,
|
||||
// however, to allow reverting the decision, we will always ask on clicking the login button.
|
||||
private boolean oauth2DeclinedByUser = false;
|
||||
|
||||
// this function checks if oauth2 is available for a given email address
|
||||
// and and asks the user if one wants to start oauth2.
|
||||
// the function returns the future "true" if oauth2 was started and "false" otherwise.
|
||||
private ListenableFuture<Boolean> checkOauth2start() {
|
||||
SettableFuture<Boolean> oauth2started = new SettableFuture<>();
|
||||
|
||||
String email = emailInput.getText().toString();
|
||||
if (!TextUtils.isEmpty(email) ) {
|
||||
new PrecheckOauth2AsyncTask(this, email, oauth2started).execute();
|
||||
}
|
||||
else {
|
||||
oauth2started.set(false);
|
||||
}
|
||||
|
||||
return oauth2started;
|
||||
}
|
||||
|
||||
private static class PrecheckOauth2AsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
private final WeakReference<RegistrationActivity> activityWeakReference;
|
||||
private final String email;
|
||||
private final SettableFuture<Boolean> oauth2started;
|
||||
private final DcContext dcContext;
|
||||
private @NonNull String oauth2url = "";
|
||||
|
||||
public PrecheckOauth2AsyncTask(RegistrationActivity activity, String email, SettableFuture<Boolean> oauth2started) {
|
||||
super();
|
||||
this.activityWeakReference = new WeakReference<>(activity);
|
||||
this.email = email;
|
||||
this.oauth2started = oauth2started;
|
||||
this.dcContext = DcHelper.getContext(activity);
|
||||
}
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
// the redirect-uri is also used as intent-filter in the manifest
|
||||
// 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
RegistrationActivity activity = activityWeakReference.get();
|
||||
if (activity!=null && !TextUtils.isEmpty(oauth2url)) {
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.login_info_oauth2_title)
|
||||
.setMessage(R.string.login_info_oauth2_text)
|
||||
.setNegativeButton(R.string.cancel, (dialog, which)->{
|
||||
activity.oauth2DeclinedByUser = true;
|
||||
oauth2started.set(false);
|
||||
})
|
||||
.setPositiveButton(R.string.perm_continue, (dialog, which)-> {
|
||||
// pass control to browser, we'll be back in business at (**)
|
||||
activity.oauth2Requested = System.currentTimeMillis();
|
||||
IntentUtils.showInBrowser(activity, oauth2url);
|
||||
oauth2started.set(true);
|
||||
})
|
||||
.setCancelable(false)
|
||||
.show();
|
||||
} else {
|
||||
oauth2started.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateProviderInfo() {
|
||||
Util.runOnBackground(() -> {
|
||||
provider = getContext(this).getProviderFromEmailWithDns(emailInput.getText().toString());
|
||||
@@ -495,27 +363,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
if(Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||
Uri uri = intent.getData();
|
||||
String path = uri.getPath();
|
||||
if(!(path.startsWith("/"+BuildConfig.APPLICATION_ID)||path.startsWith("/auth"))
|
||||
|| System.currentTimeMillis()-oauth2Requested > 3*60*60*1000) {
|
||||
return; // timeout after some hours or a request belonging to a bad path.
|
||||
}
|
||||
|
||||
// back in business after we passed control to the browser in (**)
|
||||
String code = uri.getQueryParameter("code");
|
||||
if(!TextUtils.isEmpty(code)) {
|
||||
passwordInput.setText(code);
|
||||
authMethod.setSelection(1/*OAuth2*/);
|
||||
onLogin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyEmail(TextInputEditText view) {
|
||||
String error = getString(R.string.login_error_mail);
|
||||
String email = view.getText().toString();
|
||||
@@ -634,7 +481,6 @@ public class RegistrationActivity extends BaseActionBarActivity implements DcEve
|
||||
param.smtpUser = getParam(R.id.smtp_login_text, false);
|
||||
param.smtpPassword = getParam(R.id.smtp_password_text, false);
|
||||
param.certificateChecks = certificateChecksFromInt(certCheck.getSelectedItemPosition());
|
||||
param.oauth2 = authMethod.getSelectedItemPosition() == 1;
|
||||
|
||||
new Thread(() -> {
|
||||
Rpc rpc = DcHelper.getRpc(this);
|
||||
|
||||
@@ -131,7 +131,7 @@
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
app:constraint_referenced_ids="inbox, imap_login, imap_server, imap_port, imap_security_label, imap_security, outbox_view_spacer_top,
|
||||
outbox, smtp_login, smtp_password, smtp_server, smtp_port, smtp_security_label, smtp_security, auth_method_label, auth_method, cert_check_label, cert_check, view_log_button, proxy_settings" />
|
||||
outbox, smtp_login, smtp_password, smtp_server, smtp_port, smtp_security_label, smtp_security, cert_check_label, cert_check, view_log_button, proxy_settings" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/advanced_icon"
|
||||
@@ -357,26 +357,6 @@
|
||||
app:layout_constraintStart_toStartOf="@id/guideline_root_start"
|
||||
app:layout_constraintTop_toBottomOf="@id/smtp_security_label" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/auth_method_label"
|
||||
style="@style/TextAppearance.AppCompat.Caption"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="16dp"
|
||||
android:text="@string/login_auth_method"
|
||||
app:layout_constraintEnd_toEndOf="@id/guideline_root_end"
|
||||
app:layout_constraintStart_toStartOf="@id/guideline_root_start"
|
||||
app:layout_constraintTop_toBottomOf="@id/smtp_security" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/auth_method"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:entries="@array/auth_methods"
|
||||
app:layout_constraintEnd_toEndOf="@id/guideline_root_end"
|
||||
app:layout_constraintStart_toStartOf="@id/guideline_root_start"
|
||||
app:layout_constraintTop_toBottomOf="@id/auth_method_label" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cert_check_label"
|
||||
style="@style/TextAppearance.AppCompat.Caption"
|
||||
@@ -385,7 +365,7 @@
|
||||
android:text="@string/login_certificate_checks"
|
||||
app:layout_constraintEnd_toEndOf="@id/guideline_root_end"
|
||||
app:layout_constraintStart_toStartOf="@id/guideline_root_start"
|
||||
app:layout_constraintTop_toBottomOf="@id/auth_method" />
|
||||
app:layout_constraintTop_toBottomOf="@id/smtp_security" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/cert_check"
|
||||
|
||||
@@ -654,6 +654,7 @@
|
||||
<string name="login_smtp_server">SMTP Server</string>
|
||||
<string name="login_smtp_port">SMTP Port</string>
|
||||
<string name="login_smtp_security">SMTP Security</string>
|
||||
<!-- deprecated -->
|
||||
<string name="login_auth_method">Authorization Method</string>
|
||||
<!-- the word "Proxy" might be left untranslated unless the destination language has a well-known term for a "Proxy Server", acting intermediary between the app and the server -->
|
||||
<string name="proxy_settings">Proxy</string>
|
||||
@@ -671,7 +672,9 @@
|
||||
<string name="proxy_enabled">Proxy Enabled</string>
|
||||
<string name="proxy_enabled_hint">You are using a proxy. If you\'re having trouble connecting, try a different proxy.</string>
|
||||
|
||||
<!-- deprecated -->
|
||||
<string name="login_info_oauth2_title">Continue with simplified setup?</string>
|
||||
<!-- deprecated -->
|
||||
<string name="login_info_oauth2_text">The entered address supports a simplified setup (OAuth 2.0).\n\nIn the next step, please allow Delta Chat to send and receive messages.\n\nDelta Chat does not collect user data, everything stays on your device.</string>
|
||||
<string name="login_certificate_checks">Certificate Checks</string>
|
||||
<string name="login_error_mail">Please enter a valid e-mail address</string>
|
||||
|
||||
Reference in New Issue
Block a user