Fix authentication with external browser does not grant admin scope
This commit is contained in:
parent
58dcdbf050
commit
72f123d26b
|
@ -49,7 +49,7 @@ public class LoginActivity extends BaseActivity {
|
||||||
public static Account.API apiLogin;
|
public static Account.API apiLogin;
|
||||||
public static String currentInstanceLogin, client_idLogin, client_secretLogin, softwareLogin;
|
public static String currentInstanceLogin, client_idLogin, client_secretLogin, softwareLogin;
|
||||||
private final int PICK_IMPORT = 5557;
|
private final int PICK_IMPORT = 5557;
|
||||||
private boolean requestedAdmin;
|
public static boolean requestedAdmin;
|
||||||
|
|
||||||
private void manageItent(Intent intent) {
|
private void manageItent(Intent intent) {
|
||||||
|
|
||||||
|
@ -114,19 +114,11 @@ public class LoginActivity extends BaseActivity {
|
||||||
setContentView(new FrameLayout(this));
|
setContentView(new FrameLayout(this));
|
||||||
FragmentLoginMain fragmentLoginMain = new FragmentLoginMain();
|
FragmentLoginMain fragmentLoginMain = new FragmentLoginMain();
|
||||||
Helper.addFragment(getSupportFragmentManager(), android.R.id.content, fragmentLoginMain, null, null, null);
|
Helper.addFragment(getSupportFragmentManager(), android.R.id.content, fragmentLoginMain, null, null, null);
|
||||||
requestedAdmin = false;
|
|
||||||
//The activity handles a redirect URI, it will extract token code and will proceed to authentication
|
//The activity handles a redirect URI, it will extract token code and will proceed to authentication
|
||||||
//That happens when the user wants to use an external browser
|
//That happens when the user wants to use an external browser
|
||||||
manageItent(getIntent());
|
manageItent(getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requestedAdmin() {
|
|
||||||
return requestedAdmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean setAdmin(boolean askAdmin) {
|
|
||||||
return requestedAdmin = askAdmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import static app.fedilab.android.activities.LoginActivity.apiLogin;
|
||||||
import static app.fedilab.android.activities.LoginActivity.client_idLogin;
|
import static app.fedilab.android.activities.LoginActivity.client_idLogin;
|
||||||
import static app.fedilab.android.activities.LoginActivity.client_secretLogin;
|
import static app.fedilab.android.activities.LoginActivity.client_secretLogin;
|
||||||
import static app.fedilab.android.activities.LoginActivity.currentInstanceLogin;
|
import static app.fedilab.android.activities.LoginActivity.currentInstanceLogin;
|
||||||
|
import static app.fedilab.android.activities.LoginActivity.requestedAdmin;
|
||||||
import static app.fedilab.android.activities.LoginActivity.softwareLogin;
|
import static app.fedilab.android.activities.LoginActivity.softwareLogin;
|
||||||
import static app.fedilab.android.helper.Helper.PREF_USER_TOKEN;
|
import static app.fedilab.android.helper.Helper.PREF_USER_TOKEN;
|
||||||
|
|
||||||
|
@ -69,7 +70,6 @@ public class WebviewConnectActivity extends BaseActivity {
|
||||||
private ActivityWebviewConnectBinding binding;
|
private ActivityWebviewConnectBinding binding;
|
||||||
private AlertDialog alert;
|
private AlertDialog alert;
|
||||||
private String login_url;
|
private String login_url;
|
||||||
private boolean requestedAdmin;
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
|
|
@ -19,6 +19,7 @@ import static app.fedilab.android.activities.LoginActivity.apiLogin;
|
||||||
import static app.fedilab.android.activities.LoginActivity.client_idLogin;
|
import static app.fedilab.android.activities.LoginActivity.client_idLogin;
|
||||||
import static app.fedilab.android.activities.LoginActivity.client_secretLogin;
|
import static app.fedilab.android.activities.LoginActivity.client_secretLogin;
|
||||||
import static app.fedilab.android.activities.LoginActivity.currentInstanceLogin;
|
import static app.fedilab.android.activities.LoginActivity.currentInstanceLogin;
|
||||||
|
import static app.fedilab.android.activities.LoginActivity.requestedAdmin;
|
||||||
import static app.fedilab.android.activities.LoginActivity.softwareLogin;
|
import static app.fedilab.android.activities.LoginActivity.softwareLogin;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -49,7 +50,6 @@ import java.net.URLEncoder;
|
||||||
|
|
||||||
import app.fedilab.android.BaseMainActivity;
|
import app.fedilab.android.BaseMainActivity;
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.activities.LoginActivity;
|
|
||||||
import app.fedilab.android.activities.ProxyActivity;
|
import app.fedilab.android.activities.ProxyActivity;
|
||||||
import app.fedilab.android.activities.WebviewConnectActivity;
|
import app.fedilab.android.activities.WebviewConnectActivity;
|
||||||
import app.fedilab.android.client.entities.app.Account;
|
import app.fedilab.android.client.entities.app.Account;
|
||||||
|
@ -190,7 +190,7 @@ public class FragmentLoginMain extends Fragment {
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
||||||
boolean embedded_browser = sharedpreferences.getBoolean(getString(R.string.SET_EMBEDDED_BROWSER), true);
|
boolean embedded_browser = sharedpreferences.getBoolean(getString(R.string.SET_EMBEDDED_BROWSER), true);
|
||||||
customTabItem.setChecked(!embedded_browser);
|
customTabItem.setChecked(!embedded_browser);
|
||||||
adminTabItem.setChecked(((LoginActivity) requireActivity()).requestedAdmin());
|
adminTabItem.setChecked(requestedAdmin);
|
||||||
popupMenu.setOnMenuItemClickListener(item -> {
|
popupMenu.setOnMenuItemClickListener(item -> {
|
||||||
int itemId = item.getItemId();
|
int itemId = item.getItemId();
|
||||||
if (itemId == R.id.action_proxy) {
|
if (itemId == R.id.action_proxy) {
|
||||||
|
@ -216,9 +216,9 @@ public class FragmentLoginMain extends Fragment {
|
||||||
});
|
});
|
||||||
editor.apply();
|
editor.apply();
|
||||||
} else if (itemId == R.id.action_request_admin) {
|
} else if (itemId == R.id.action_request_admin) {
|
||||||
boolean checked = !((LoginActivity) requireActivity()).requestedAdmin();
|
|
||||||
((LoginActivity) requireActivity()).setAdmin(checked);
|
|
||||||
item.setChecked(!item.isChecked());
|
item.setChecked(!item.isChecked());
|
||||||
|
requestedAdmin = item.isChecked();
|
||||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
||||||
item.setActionView(new View(requireContext()));
|
item.setActionView(new View(requireContext()));
|
||||||
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
||||||
|
@ -257,7 +257,7 @@ public class FragmentLoginMain extends Fragment {
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
currentInstanceLogin = host;
|
currentInstanceLogin = host;
|
||||||
}
|
}
|
||||||
String scopes = ((LoginActivity) requireActivity()).requestedAdmin() ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES;
|
String scopes = requestedAdmin ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES;
|
||||||
AppsVM appsVM = new ViewModelProvider(requireActivity()).get(AppsVM.class);
|
AppsVM appsVM = new ViewModelProvider(requireActivity()).get(AppsVM.class);
|
||||||
appsVM.createApp(currentInstanceLogin, getString(R.string.app_name),
|
appsVM.createApp(currentInstanceLogin, getString(R.string.app_name),
|
||||||
Helper.REDIRECT_CONTENT_WEB,
|
Helper.REDIRECT_CONTENT_WEB,
|
||||||
|
@ -267,13 +267,13 @@ public class FragmentLoginMain extends Fragment {
|
||||||
if (app != null) {
|
if (app != null) {
|
||||||
client_idLogin = app.client_id;
|
client_idLogin = app.client_id;
|
||||||
client_secretLogin = app.client_secret;
|
client_secretLogin = app.client_secret;
|
||||||
String redirectUrl = MastodonHelper.authorizeURL(currentInstanceLogin, client_idLogin, ((LoginActivity) requireActivity()).requestedAdmin());
|
String redirectUrl = MastodonHelper.authorizeURL(currentInstanceLogin, client_idLogin, requestedAdmin);
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
||||||
boolean embedded_browser = sharedpreferences.getBoolean(getString(R.string.SET_EMBEDDED_BROWSER), true);
|
boolean embedded_browser = sharedpreferences.getBoolean(getString(R.string.SET_EMBEDDED_BROWSER), true);
|
||||||
if (embedded_browser) {
|
if (embedded_browser) {
|
||||||
Intent i = new Intent(requireActivity(), WebviewConnectActivity.class);
|
Intent i = new Intent(requireActivity(), WebviewConnectActivity.class);
|
||||||
i.putExtra("login_url", redirectUrl);
|
i.putExtra("login_url", redirectUrl);
|
||||||
i.putExtra("requestedAdmin", ((LoginActivity) requireActivity()).requestedAdmin());
|
i.putExtra("requestedAdmin", requestedAdmin);
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
requireActivity().finish();
|
requireActivity().finish();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue