Revert "Outlook MSAL"

This reverts commit 1c9c136e2a.
pull/162/head
M66B 5 years ago
parent 1c9c136e2a
commit 9caefc1a0f

@ -49,7 +49,6 @@ android {
exclude 'META-INF/LICENSE.txt' exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/README.md' exclude 'META-INF/README.md'
exclude 'META-INF/CHANGES' exclude 'META-INF/CHANGES'
exclude 'META-INF/jersey-module-version'
} }
signingConfigs { signingConfigs {
@ -313,9 +312,5 @@ dependencies {
// https://github.com/noties/Markwon // https://github.com/noties/Markwon
implementation "io.noties.markwon:core:$markwon_version" implementation "io.noties.markwon:core:$markwon_version"
// https://github.com/QuadFlask/colorpicker
implementation project(':qcolorpicker') implementation project(':qcolorpicker')
// https://github.com/AzureAD/microsoft-authentication-library-for-android
implementation "com.microsoft.identity.client:msal:1.0.+"
} }

@ -73,12 +73,6 @@
-keepnames class biweekly.** {*;} -keepnames class biweekly.** {*;}
-dontwarn biweekly.io.json.** -dontwarn biweekly.io.json.**
#MSAL
#-keep class com.microsoft.aad.adal.** {*;}
-keep class com.microsoft.identity.common.** {*;}
-dontwarn com.nimbusds.jose.**
-keepclassmembers enum * {*;} #GSON
#Notes #Notes
-dontnote com.google.android.material.** -dontnote com.google.android.material.**
-dontnote com.sun.mail.** -dontnote com.sun.mail.**

@ -205,20 +205,6 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="com.microsoft.identity.client.BrowserTabActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="eu.faircode.email"
android:path="/F7oVwa9V2SX5i5nOpDddTN9MF0s="
android:scheme="msauth" />
</intent-filter>
</activity>
<activity <activity
android:name=".ActivityBilling" android:name=".ActivityBilling"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"

@ -66,12 +66,6 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
import com.microsoft.identity.client.AuthenticationCallback;
import com.microsoft.identity.client.IAuthenticationResult;
import com.microsoft.identity.client.IMultipleAccountPublicClientApplication;
import com.microsoft.identity.client.IPublicClientApplication;
import com.microsoft.identity.client.PublicClientApplication;
import com.microsoft.identity.client.exception.MsalException;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -83,9 +77,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.spec.KeySpec; import java.security.spec.KeySpec;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -126,7 +117,6 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
static final int REQUEST_DONE = 6; static final int REQUEST_DONE = 6;
static final String ACTION_QUICK_GMAIL = BuildConfig.APPLICATION_ID + ".ACTION_QUICK_GMAIL"; static final String ACTION_QUICK_GMAIL = BuildConfig.APPLICATION_ID + ".ACTION_QUICK_GMAIL";
static final String ACTION_QUICK_OUTLOOK = BuildConfig.APPLICATION_ID + ".ACTION_QUICK_OUTLOOK";
static final String ACTION_QUICK_SETUP = BuildConfig.APPLICATION_ID + ".ACTION_QUICK_SETUP"; static final String ACTION_QUICK_SETUP = BuildConfig.APPLICATION_ID + ".ACTION_QUICK_SETUP";
static final String ACTION_VIEW_ACCOUNTS = BuildConfig.APPLICATION_ID + ".ACTION_VIEW_ACCOUNTS"; static final String ACTION_VIEW_ACCOUNTS = BuildConfig.APPLICATION_ID + ".ACTION_VIEW_ACCOUNTS";
static final String ACTION_VIEW_IDENTITIES = BuildConfig.APPLICATION_ID + ".ACTION_VIEW_IDENTITIES"; static final String ACTION_VIEW_IDENTITIES = BuildConfig.APPLICATION_ID + ".ACTION_VIEW_IDENTITIES";
@ -309,7 +299,6 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
IntentFilter iff = new IntentFilter(); IntentFilter iff = new IntentFilter();
iff.addAction(ACTION_QUICK_GMAIL); iff.addAction(ACTION_QUICK_GMAIL);
iff.addAction(ACTION_QUICK_OUTLOOK);
iff.addAction(ACTION_QUICK_SETUP); iff.addAction(ACTION_QUICK_SETUP);
iff.addAction(ACTION_VIEW_ACCOUNTS); iff.addAction(ACTION_VIEW_ACCOUNTS);
iff.addAction(ACTION_VIEW_IDENTITIES); iff.addAction(ACTION_VIEW_IDENTITIES);
@ -1052,199 +1041,12 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
return channel; return channel;
} }
private void onGmail(Intent intent) { private void onViewGmail(Intent intent) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new FragmentGmail()).addToBackStack("quick"); fragmentTransaction.replace(R.id.content_frame, new FragmentGmail()).addToBackStack("quick");
fragmentTransaction.commit(); fragmentTransaction.commit();
} }
private void onOutlook(Intent intent) {
PublicClientApplication.createMultipleAccountPublicClientApplication(
this,
R.raw.msal_config,
new IPublicClientApplication.IMultipleAccountApplicationCreatedListener() {
@Override
public void onCreated(IMultipleAccountPublicClientApplication msal) {
Log.i("MSAL app created");
msal.acquireToken(
ActivitySetup.this,
// "openid", "offline_access", "profile", "email"
// https://docs.microsoft.com/en-us/graph/permissions-reference
new String[]{"User.ReadBasic.All", "Mail.ReadWrite", "Mail.Send"},
new AuthenticationCallback() {
@Override
public void onSuccess(IAuthenticationResult result) {
Log.i("MSAL got token");
Bundle args = new Bundle();
args.putString("token", result.getAccessToken());
new SimpleTask<JSONObject>() {
@Override
protected JSONObject onExecute(Context context, Bundle args) throws Throwable {
String token = args.getString("token");
// https://docs.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=http#http-request
URL url = new URL("https://graph.microsoft.com/v1.0/me" +
"?$select=displayName,otherMails");
Log.i("MSAL fetching " + url);
HttpURLConnection request = (HttpURLConnection) url.openConnection();
request.setReadTimeout(15 * 1000);
request.setConnectTimeout(15 * 1000);
request.setRequestMethod("GET");
request.setDoInput(true);
request.setRequestProperty("Authorization", "Bearer " + token);
request.setRequestProperty("Content-Type", "application/json");
request.connect();
try {
Log.i("MSAL getting response");
String json = Helper.readStream(request.getInputStream(), StandardCharsets.UTF_8.name());
return new JSONObject(json);
} finally {
request.disconnect();
}
}
@Override
protected void onExecuted(Bundle args, JSONObject data) {
Log.i("MSAL " + data);
try {
JSONArray otherMails = data.getJSONArray("otherMails");
args.putString("displayName", data.getString("displayName"));
args.putString("email", (String) otherMails.get(0));
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
String token = args.getString("token");
String email = args.getString("email");
String displayName = args.getString("displayName");
List<EntityFolder> folders;
// https://msdn.microsoft.com/en-us/windows/desktop/dn440163
String host = "imap-mail.outlook.com";
int port = 993;
boolean starttls = false;
String user = email;
String password = token;
try (MailService iservice = new MailService(context, "imaps", null, false, true)) {
iservice.connect(host, port, MailService.AUTH_TYPE_OUTLOOK, user, password);
folders = iservice.getFolders();
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityAccount primary = db.account().getPrimaryAccount();
// Create account
EntityAccount account = new EntityAccount();
account.host = host;
account.starttls = starttls;
account.port = port;
account.auth_type = MailService.AUTH_TYPE_OUTLOOK;
account.user = user;
account.password = password;
account.name = "OutLook";
account.synchronize = true;
account.primary = (primary == null);
account.created = new Date().getTime();
account.last_connected = account.created;
account.id = db.account().insertAccount(account);
args.putLong("account", account.id);
EntityLog.log(context, "OutLook account=" + account.name);
// Create folders
for (EntityFolder folder : folders) {
folder.account = account.id;
folder.id = db.folder().insertFolder(folder);
EntityLog.log(context, "OutLook folder=" + folder.name + " type=" + folder.type);
}
// Set swipe left/right folder
for (EntityFolder folder : folders)
if (EntityFolder.TRASH.equals(folder.type))
account.swipe_left = folder.id;
else if (EntityFolder.ARCHIVE.equals(folder.type))
account.swipe_right = folder.id;
db.account().updateAccount(account);
// Create identity
EntityIdentity identity = new EntityIdentity();
identity.name = displayName;
identity.email = user;
identity.account = account.id;
identity.host = "smtp-mail.outlook.com";
identity.starttls = true;
identity.port = 587;
identity.auth_type = MailService.AUTH_TYPE_OUTLOOK;
identity.user = user;
identity.password = password;
identity.synchronize = true;
identity.primary = true;
identity.id = db.identity().insertIdentity(identity);
args.putLong("identity", identity.id);
EntityLog.log(context, "Gmail identity=" + identity.name + " email=" + identity.email);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
}
}.execute(ActivitySetup.this, args, "outlook:account");
} catch (JSONException ex) {
Log.e(ex);
}
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getSupportFragmentManager(), ex);
}
}.execute(ActivitySetup.this, args, "graph:profile");
}
@Override
public void onError(MsalException ex) {
Log.e(ex);
}
@Override
public void onCancel() {
Log.w("MSAL cancelled");
}
});
}
@Override
public void onError(MsalException ex) {
Log.e("MSAL", ex);
}
});
}
private void onViewQuickSetup(Intent intent) { private void onViewQuickSetup(Intent intent) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new FragmentQuickSetup()).addToBackStack("quick"); fragmentTransaction.replace(R.id.content_frame, new FragmentQuickSetup()).addToBackStack("quick");
@ -1358,9 +1160,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
String action = intent.getAction(); String action = intent.getAction();
if (ACTION_QUICK_GMAIL.equals(action)) if (ACTION_QUICK_GMAIL.equals(action))
onGmail(intent); onViewGmail(intent);
else if (ACTION_QUICK_OUTLOOK.equals(action))
onOutlook(intent);
else if (ACTION_QUICK_SETUP.equals(action)) else if (ACTION_QUICK_SETUP.equals(action))
onViewQuickSetup(intent); onViewQuickSetup(intent);
else if (ACTION_VIEW_ACCOUNTS.equals(action)) else if (ACTION_VIEW_ACCOUNTS.equals(action))

@ -164,8 +164,7 @@ public class FragmentSetup extends FragmentBase {
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), btnQuick); PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), btnQuick);
popupMenu.getMenu().add(Menu.NONE, R.string.title_setup_gmail, 1, R.string.title_setup_gmail); popupMenu.getMenu().add(Menu.NONE, R.string.title_setup_gmail, 1, R.string.title_setup_gmail);
popupMenu.getMenu().add(Menu.NONE, R.string.title_setup_outlook, 2, R.string.title_setup_outlook); popupMenu.getMenu().add(Menu.NONE, R.string.title_setup_other, 2, R.string.title_setup_other);
popupMenu.getMenu().add(Menu.NONE, R.string.title_setup_other, 3, R.string.title_setup_other);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override @Override
@ -178,9 +177,6 @@ public class FragmentSetup extends FragmentBase {
else else
ToastEx.makeText(getContext(), R.string.title_setup_gmail_support, Toast.LENGTH_LONG).show(); ToastEx.makeText(getContext(), R.string.title_setup_gmail_support, Toast.LENGTH_LONG).show();
return true; return true;
case R.string.title_setup_outlook:
lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_QUICK_OUTLOOK));
return true;
case R.string.title_setup_other: case R.string.title_setup_other:
lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_QUICK_SETUP)); lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_QUICK_SETUP));
return true; return true;

@ -44,7 +44,6 @@ public class MailService implements AutoCloseable {
static final int AUTH_TYPE_PASSWORD = 1; static final int AUTH_TYPE_PASSWORD = 1;
static final int AUTH_TYPE_GMAIL = 2; static final int AUTH_TYPE_GMAIL = 2;
static final int AUTH_TYPE_OUTLOOK = 3;
private final static int CONNECT_TIMEOUT = 20 * 1000; // milliseconds private final static int CONNECT_TIMEOUT = 20 * 1000; // milliseconds
private final static int WRITE_TIMEOUT = 60 * 1000; // milliseconds private final static int WRITE_TIMEOUT = 60 * 1000; // milliseconds
@ -179,7 +178,7 @@ public class MailService implements AutoCloseable {
public String connect(String host, int port, int auth, String user, String password) throws MessagingException { public String connect(String host, int port, int auth, String user, String password) throws MessagingException {
try { try {
if (auth == AUTH_TYPE_GMAIL || auth == AUTH_TYPE_OUTLOOK) if (auth == AUTH_TYPE_GMAIL)
properties.put("mail." + protocol + ".auth.mechanisms", "XOAUTH2"); properties.put("mail." + protocol + ".auth.mechanisms", "XOAUTH2");
//if (BuildConfig.DEBUG) //if (BuildConfig.DEBUG)

@ -1,14 +0,0 @@
{
"client_id" : "3514cf2c-e7a3-45a2-80d4-6a3c3498eca0",
"authorization_user_agent" : "DEFAULT",
"redirect_uri" : "msauth://eu.faircode.email/F7oVwa9V2SX5i5nOpDddTN9MF0s%3D",
"authorities" : [
{
"type": "AAD",
"audience": {
"type": "AzureADMultipleOrgs",
"tenant_id": "organizations"
}
}
]
}

@ -138,7 +138,6 @@
<string name="title_setup_wizard">Wizard</string> <string name="title_setup_wizard">Wizard</string>
<string name="title_setup_wizard_remark">Go \'back\' to go to the inbox</string> <string name="title_setup_wizard_remark">Go \'back\' to go to the inbox</string>
<string name="title_setup_gmail" translatable="false">Gmail</string> <string name="title_setup_gmail" translatable="false">Gmail</string>
<string name="title_setup_outlook" translatable="false">Outlook</string>
<string name="title_setup_other">Other provider</string> <string name="title_setup_other">Other provider</string>
<string name="title_setup_gmail_support">Authorizing Google accounts will work in official versions only because Android checks the app signature</string> <string name="title_setup_gmail_support">Authorizing Google accounts will work in official versions only because Android checks the app signature</string>
<string name="title_setup_gmail_rationale">Please grant permissions to select an account and read your name</string> <string name="title_setup_gmail_rationale">Please grant permissions to select an account and read your name</string>

Loading…
Cancel
Save