Get mail.ru account data

pull/198/head
M66B 4 years ago
parent 80f884aa93
commit 592ded9470

@ -70,6 +70,7 @@ import net.openid.appauth.browser.VersionedBrowserMatcher;
import org.json.JSONObject; import org.json.JSONObject;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -77,6 +78,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import javax.mail.AuthenticationFailedException; import javax.mail.AuthenticationFailedException;
import javax.net.ssl.HttpsURLConnection;
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH; import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH;
@ -106,6 +108,8 @@ public class FragmentOAuth extends FragmentBase {
private Group grpError; private Group grpError;
private static final int MAILRU_TIMEOUT = 20 * 1000; // milliseconds
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -470,7 +474,28 @@ public class FragmentOAuth extends FragmentBase {
if (askAccount) if (askAccount)
identities.add(new Pair<>(address, personal)); identities.add(new Pair<>(address, personal));
else else if ("mailru".equals(id)) {
URL url = new URL("https://oauth.mail.ru/userinfo?access_token=" + token);
Log.i("GET " + url);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setReadTimeout(MAILRU_TIMEOUT);
connection.setConnectTimeout(MAILRU_TIMEOUT);
connection.connect();
try {
String json = Helper.readStream(connection.getInputStream());
Log.i("json=" + json);
JSONObject data = new JSONObject(json);
name = data.getString("name");
address = data.getString("email");
username = address;
identities.add(new Pair<>(address, name));
} finally {
connection.disconnect();
}
} else
throw new IllegalArgumentException("Unknown provider=" + id); throw new IllegalArgumentException("Unknown provider=" + id);
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

@ -495,7 +495,7 @@
port="465" port="465"
starttls="false" /> starttls="false" />
<oauth <oauth
askAccount="true" askAccount="false"
authorizationEndpoint="https://oauth.mail.ru/login" authorizationEndpoint="https://oauth.mail.ru/login"
clientId="ce54d27dc1574b3a8b50e6789cd1a44a" clientId="ce54d27dc1574b3a8b50e6789cd1a44a"
clientSecret="5f1525783e1d4defb3bc9c2c4b7d0c54" clientSecret="5f1525783e1d4defb3bc9c2c4b7d0c54"

Loading…
Cancel
Save