Added Yandex OAuth

pull/172/head
M66B 5 years ago
parent d5198043e6
commit 26a244ff15

@ -136,6 +136,7 @@ public class EmailProvider {
} else if ("oauth".equals(name)) {
provider.oauth = new OAuth();
provider.oauth.enabled = xml.getAttributeBooleanValue(null, "enabled", false);
provider.oauth.askAccount = xml.getAttributeBooleanValue(null, "askAccount", false);
provider.oauth.clientId = xml.getAttributeValue(null, "clientId");
provider.oauth.clientSecret = xml.getAttributeValue(null, "clientSecret");
provider.oauth.scopes = xml.getAttributeValue(null, "scopes").split(",");
@ -674,6 +675,7 @@ public class EmailProvider {
public static class OAuth {
boolean enabled;
boolean askAccount;
String clientId;
String clientSecret;
String[] scopes;

@ -28,6 +28,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Pair;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -35,6 +36,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;
@ -78,11 +80,14 @@ import static android.app.Activity.RESULT_OK;
public class FragmentOAuth extends FragmentBase {
private String id;
private String name;
private boolean askAccount;
private ViewGroup view;
private ScrollView scroll;
private TextView tvGrantHint;
private EditText etName;
private EditText etEmail;
private Button btnOAuth;
private ContentLoadingProgressBar pbOAuth;
private TextView tvAuthorized;
@ -103,6 +108,7 @@ public class FragmentOAuth extends FragmentBase {
Bundle args = getArguments();
id = args.getString("id");
name = args.getString("name");
askAccount = args.getBoolean("askAccount", false);
}
@Override
@ -116,6 +122,8 @@ public class FragmentOAuth extends FragmentBase {
// Get controls
tvGrantHint = view.findViewById(R.id.tvGrantHint);
etName = view.findViewById(R.id.etName);
etEmail = view.findViewById(R.id.etEmail);
btnOAuth = view.findViewById(R.id.btnOAuth);
pbOAuth = view.findViewById(R.id.pbOAuth);
tvAuthorized = view.findViewById(R.id.tvAuthorized);
@ -145,6 +153,8 @@ public class FragmentOAuth extends FragmentBase {
// Initialize
tvGrantHint.setText(getString(R.string.title_setup_oauth_rationale, name));
etName.setVisibility(askAccount ? View.VISIBLE : View.GONE);
etEmail.setVisibility(askAccount ? View.VISIBLE : View.GONE);
pbOAuth.setVisibility(View.GONE);
tvAuthorized.setVisibility(View.GONE);
tvGmailHint.setVisibility("gmail".equals(id) ? View.VISIBLE : View.GONE);
@ -198,6 +208,19 @@ public class FragmentOAuth extends FragmentBase {
private void onAuthorize() {
try {
if (askAccount) {
String name = etName.getText().toString().trim();
String email = etEmail.getText().toString().trim();
if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(getString(R.string.title_no_name));
if (TextUtils.isEmpty(email))
throw new IllegalArgumentException(getString(R.string.title_no_email));
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches())
throw new IllegalArgumentException(getString(R.string.title_email_invalid, email));
}
btnOAuth.setEnabled(false);
pbOAuth.setVisibility(View.VISIBLE);
hideError();
@ -243,6 +266,9 @@ public class FragmentOAuth extends FragmentBase {
.setState(provider.id)
.setAdditionalParameters(params);
if (askAccount)
authRequestBuilder.setLoginHint(etEmail.getText().toString().trim());
// For offline access
if ("gmail".equals(provider.id))
authRequestBuilder.setPrompt("consent");
@ -326,6 +352,8 @@ public class FragmentOAuth extends FragmentBase {
args.putString("name", name);
args.putString("token", accessToken);
args.putString("state", state.jsonSerializeString());
args.putString("personal", etName.getText().toString().trim());
args.putString("address", etEmail.getText().toString().trim());
new SimpleTask<Void>() {
@Override
@ -334,6 +362,8 @@ public class FragmentOAuth extends FragmentBase {
String name = args.getString("name");
String token = args.getString("token");
String state = args.getString("state");
String personal = args.getString("personal");
String address = args.getString("address");
String primaryEmail = null;
List<Pair<String, String>> identities = new ArrayList<>();
@ -413,6 +443,9 @@ public class FragmentOAuth extends FragmentBase {
identities.add(new Pair<>(email, displayName));
}
}
} else if ("yandex".equals(id)) {
primaryEmail = address;
identities.add(new Pair<>(address, personal));
} else
throw new IllegalArgumentException("Unknown provider=" + id);

@ -176,7 +176,8 @@ public class FragmentSetup extends FragmentBase {
.add(Menu.NONE, -1, order++, getString(R.string.title_setup_oauth, provider.name))
.setIntent(new Intent(ActivitySetup.ACTION_QUICK_OAUTH)
.putExtra("id", provider.id)
.putExtra("name", provider.name));
.putExtra("name", provider.name)
.putExtra("askAccount", provider.oauth.askAccount));
popupMenu.getMenu().add(Menu.NONE, R.string.title_setup_activesync, order++, R.string.title_setup_activesync);
popupMenu.getMenu().add(Menu.NONE, R.string.title_setup_other, order++, R.string.title_setup_other);

@ -23,6 +23,35 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/etName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autofillHints="name"
android:hint="@string/title_identity_name"
android:imeOptions="actionNext"
android:inputType="textPersonName|textCapWords"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvGrantHint">
<requestFocus />
</EditText>
<EditText
android:id="@+id/etEmail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autofillHints="emailAddress"
android:hint="@string/title_identity_email"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
<Button
android:id="@+id/btnOAuth"
android:layout_width="wrap_content"
@ -31,7 +60,7 @@
android:tag="disable"
android:text="@string/title_setup_oauth_authorize"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvGrantHint" />
app:layout_constraintTop_toBottomOf="@id/etEmail" />
<eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbOAuth"

@ -201,6 +201,7 @@
</provider>
<provider
name="Yandex"
id="yandex"
link="https://yandex.com/support/mail/mail-clients.html#imap">
<imap
host="imap.yandex.com"
@ -211,10 +212,11 @@
port="465"
starttls="false" />
<oauth
askAccount="true"
authorizationEndpoint="https://oauth.yandex.com/authorize"
clientId=""
clientSecret=""
enabled="false"
clientId="a41b1a433d5041c39edebda5b866d2fc"
clientSecret="03e6fb9c27374d5b81c612add522f6a0"
enabled="true"
redirectUri="https://oauth.faircode.eu/"
scopes="mail:imap_full,mail:smtp"
tokenEndpoint="https://oauth.yandex.com/token" />

Loading…
Cancel
Save