Get mail.ru account data

This commit is contained in:
M66B 2021-04-24 18:10:03 +02:00
parent 80f884aa93
commit 592ded9470
2 changed files with 27 additions and 2 deletions

View File

@ -70,6 +70,7 @@ import net.openid.appauth.browser.VersionedBrowserMatcher;
import org.json.JSONObject;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@ -77,6 +78,7 @@ import java.util.List;
import java.util.Map;
import javax.mail.AuthenticationFailedException;
import javax.net.ssl.HttpsURLConnection;
import static android.app.Activity.RESULT_OK;
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH;
@ -106,6 +108,8 @@ public class FragmentOAuth extends FragmentBase {
private Group grpError;
private static final int MAILRU_TIMEOUT = 20 * 1000; // milliseconds
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -470,7 +474,28 @@ public class FragmentOAuth extends FragmentBase {
if (askAccount)
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);
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

View File

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