GoogleAuth removed
This commit is contained in:
@@ -39,7 +39,6 @@ import de.sebse.fuplanner.fragments.moddetails.ModDetailFragment;
|
|||||||
import de.sebse.fuplanner.services.Canteen.CanteenBrowser;
|
import de.sebse.fuplanner.services.Canteen.CanteenBrowser;
|
||||||
import de.sebse.fuplanner.services.Canteen.types.Canteen;
|
import de.sebse.fuplanner.services.Canteen.types.Canteen;
|
||||||
import de.sebse.fuplanner.services.Canteen.types.CanteenListener;
|
import de.sebse.fuplanner.services.Canteen.types.CanteenListener;
|
||||||
import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
|
||||||
import de.sebse.fuplanner.services.kvv.KVV;
|
import de.sebse.fuplanner.services.kvv.KVV;
|
||||||
import de.sebse.fuplanner.services.kvv.KVVListener;
|
import de.sebse.fuplanner.services.kvv.KVVListener;
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
||||||
@@ -76,7 +75,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
private static final int DOUBLE_CLICK_TO_EXIT_MILLIS = 2000;
|
private static final int DOUBLE_CLICK_TO_EXIT_MILLIS = 2000;
|
||||||
|
|
||||||
private FragmentManager mFragmentManager;
|
private FragmentManager mFragmentManager;
|
||||||
private GoogleAuth mGoogleAuth;
|
|
||||||
private KVV mKVV;
|
private KVV mKVV;
|
||||||
private NewsManager mNewsManager;
|
private NewsManager mNewsManager;
|
||||||
private CanteenBrowser mCanteenBrowser;
|
private CanteenBrowser mCanteenBrowser;
|
||||||
@@ -268,11 +266,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
case R.id.nav_logout:
|
case R.id.nav_logout:
|
||||||
getKVV().account().logout(true);
|
getKVV().account().logout(true);
|
||||||
getKVV().modules().list().delete();
|
getKVV().modules().list().delete();
|
||||||
this.getGoogleAuth().getLoginState(credentials -> {
|
|
||||||
if (credentials != null) {
|
|
||||||
this.getGoogleAuth().deleteLoginState(credentials.getUsername(), credentials.getPassword());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -288,12 +281,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
this.getGoogleAuth().onActivityResult(requestCode, resultCode, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle savedInstanceState) {
|
protected void onSaveInstanceState(Bundle savedInstanceState) {
|
||||||
if (mFragmentPage != FRAGMENT_STARTUP && mFragmentPage != FRAGMENT_NONE) {
|
if (mFragmentPage != FRAGMENT_STARTUP && mFragmentPage != FRAGMENT_NONE) {
|
||||||
@@ -321,13 +308,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
/* --------------------------------------------*/
|
/* --------------------------------------------*/
|
||||||
/* --------------------------------------------*/
|
/* --------------------------------------------*/
|
||||||
|
|
||||||
public GoogleAuth getGoogleAuth() {
|
|
||||||
if (this.mGoogleAuth == null) {
|
|
||||||
this.mGoogleAuth = new GoogleAuth(this);
|
|
||||||
}
|
|
||||||
return this.mGoogleAuth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NewsManager getNewsManager() {
|
public NewsManager getNewsManager() {
|
||||||
if (this.mNewsManager == null) {
|
if (this.mNewsManager == null) {
|
||||||
this.mNewsManager = new NewsManager(this);
|
this.mNewsManager = new NewsManager(this);
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.GoogleAuth;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by sebastian on 07.11.17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public interface ConnectedListener {
|
|
||||||
void connected();
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.GoogleAuth;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Sebastian on 06.11.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class Credentials {
|
|
||||||
private final String username;
|
|
||||||
private final String password;
|
|
||||||
|
|
||||||
public Credentials(String username, String password) {
|
|
||||||
this.username = username;
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.GoogleAuth;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Sebastian on 06.11.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public interface CredentialsListener {
|
|
||||||
void onCredentials(Credentials credentials);
|
|
||||||
}
|
|
||||||
@@ -1,224 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.GoogleAuth;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentSender;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.google.android.gms.auth.api.credentials.Credential;
|
|
||||||
import com.google.android.gms.auth.api.credentials.CredentialRequest;
|
|
||||||
import com.google.android.gms.auth.api.credentials.CredentialsClient;
|
|
||||||
import com.google.android.gms.auth.api.credentials.CredentialsOptions;
|
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
|
||||||
import com.google.android.gms.common.GoogleApiAvailability;
|
|
||||||
import com.google.android.gms.common.api.ApiException;
|
|
||||||
import com.google.android.gms.common.api.CommonStatusCodes;
|
|
||||||
import com.google.android.gms.common.api.ResolvableApiException;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Sebastian on 06.11.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class GoogleAuth {
|
|
||||||
// https://developers.google.com/identity/smartlock-passwords/android/retrieve-credentials
|
|
||||||
|
|
||||||
private static final String TAG = "GoogleAuth";
|
|
||||||
private final FragmentActivity activity;
|
|
||||||
private static final String FU_PLANNER_PROVIDER = "FUPlanner";
|
|
||||||
private CredentialsClient mCredentialsClient;
|
|
||||||
private boolean mIsResolving;
|
|
||||||
@Nullable
|
|
||||||
private CredentialsListener mCredentialsListener;
|
|
||||||
private boolean isConnected = false;
|
|
||||||
|
|
||||||
public GoogleAuth(FragmentActivity activity) {
|
|
||||||
this.activity = activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void connect() {
|
|
||||||
if (this.isUnavailable()) {
|
|
||||||
Log.w(TAG, "STATUS: Google auth not available!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.mCredentialsClient = getClient();
|
|
||||||
this.isConnected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void getLoginState(final CredentialsListener credentialsListener) {
|
|
||||||
if (this.isUnavailable()) {
|
|
||||||
Log.w(TAG, "STATUS: Google auth not available!");
|
|
||||||
credentialsListener.onCredentials(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!this.isConnected)
|
|
||||||
connect();
|
|
||||||
CredentialRequest request = new CredentialRequest.Builder()
|
|
||||||
.setPasswordLoginSupported(true)
|
|
||||||
.setAccountTypes(FU_PLANNER_PROVIDER)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
|
|
||||||
mCredentialsClient.request(request).addOnCompleteListener(task -> {
|
|
||||||
if (task.isSuccessful()) {
|
|
||||||
// Successfully read the credential without any user interaction, this
|
|
||||||
// means there was only a single credential and the user has auto
|
|
||||||
// sign-in enabled.
|
|
||||||
Credential credential = task.getResult().getCredential();
|
|
||||||
credentialsListener.onCredentials(new Credentials(credential.getId(), credential.getPassword()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Exception e = task.getException();
|
|
||||||
if (e instanceof ResolvableApiException) {
|
|
||||||
// This is most likely the case where the user has multiple saved
|
|
||||||
// credentials and needs to pick one. This requires showing UI to
|
|
||||||
// resolve the read request.
|
|
||||||
GoogleAuth.this.mCredentialsListener = credentialsListener;
|
|
||||||
ResolvableApiException rae = (ResolvableApiException) e;
|
|
||||||
resolveResult(rae, RequestCode.RC_READ);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e instanceof ApiException) {
|
|
||||||
ApiException ae = (ApiException) e;
|
|
||||||
if (ae.getStatusCode() == CommonStatusCodes.SIGN_IN_REQUIRED) {
|
|
||||||
// This means only a hint is available, but we are handling that
|
|
||||||
// elsewhere so no need to act here.
|
|
||||||
} else {
|
|
||||||
credentialsListener.onCredentials(null);
|
|
||||||
Log.w(TAG, "Unexpected status code: " + ae.getStatusCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLoginState(String username, String password) {
|
|
||||||
if (this.isUnavailable()) {
|
|
||||||
Log.w(TAG, "STATUS: Google auth not available!");
|
|
||||||
Toast.makeText(activity, "Google auth not available!", Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!this.isConnected)
|
|
||||||
connect();
|
|
||||||
Credential credential = new Credential.Builder(username)
|
|
||||||
.setPassword(password)
|
|
||||||
.build();
|
|
||||||
mCredentialsClient.save(credential).addOnCompleteListener(task -> {
|
|
||||||
if (task.isSuccessful()) {
|
|
||||||
showToast("Credential saved.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Exception e = task.getException();
|
|
||||||
if (e instanceof ResolvableApiException) {
|
|
||||||
// The first time a credential is saved, the user is shown UI
|
|
||||||
// to confirm the action. This requires resolution.
|
|
||||||
ResolvableApiException rae = (ResolvableApiException) e;
|
|
||||||
resolveResult(rae, RequestCode.RC_SAVE);
|
|
||||||
} else {
|
|
||||||
// Save failure cannot be resolved.
|
|
||||||
Log.w(TAG, "Save failed.", e);
|
|
||||||
showToast("Credential Save Failed");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteLoginState(String username, String password) {
|
|
||||||
if (this.isUnavailable()) {
|
|
||||||
Log.w(TAG, "STATUS: Google auth not available!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!this.isConnected)
|
|
||||||
connect();
|
|
||||||
Credential credential = new Credential.Builder(username)
|
|
||||||
.setPassword(password)
|
|
||||||
.build();
|
|
||||||
mCredentialsClient.delete(credential).addOnCompleteListener(task -> {
|
|
||||||
if (task.isSuccessful()) {
|
|
||||||
// Credential was deleted successfully
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isUnavailable() {
|
|
||||||
return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this.activity) != ConnectionResult.SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CredentialsClient getClient() {
|
|
||||||
CredentialsOptions options = new CredentialsOptions.Builder()
|
|
||||||
.forceEnableSaveDialog()
|
|
||||||
.build();
|
|
||||||
return com.google.android.gms.auth.api.credentials.Credentials.getClient(this.activity, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
Log.w(TAG, "onActivityResult:" + requestCode + ":" + resultCode + ":" + data);
|
|
||||||
|
|
||||||
switch (requestCode) {
|
|
||||||
case RequestCode.RC_HINT:
|
|
||||||
// Drop into handling for RC_READ
|
|
||||||
case RequestCode.RC_READ:
|
|
||||||
if (resultCode == RESULT_OK) {
|
|
||||||
boolean isHint = (requestCode == RequestCode.RC_HINT);
|
|
||||||
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
|
|
||||||
if (mCredentialsListener != null)
|
|
||||||
this.mCredentialsListener.onCredentials(new Credentials(credential.getId(), credential.getPassword()));
|
|
||||||
else
|
|
||||||
Log.w(TAG, "No Credentials Listener");
|
|
||||||
} else {
|
|
||||||
if (mCredentialsListener != null)
|
|
||||||
this.mCredentialsListener.onCredentials(null);
|
|
||||||
else
|
|
||||||
Log.w(TAG, "No Credentials Listener");
|
|
||||||
Log.e(TAG, "Credential Read: NOT OK");
|
|
||||||
showToast("Credential Read Failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
mIsResolving = false;
|
|
||||||
break;
|
|
||||||
case RequestCode.RC_SAVE:
|
|
||||||
if (resultCode == RESULT_OK) {
|
|
||||||
Log.w(TAG, "Credential Save: OK");
|
|
||||||
showToast("Credential Save Success");
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "Credential Save: NOT OK");
|
|
||||||
showToast("Credential Save Failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
mIsResolving = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void resolveResult(ResolvableApiException rae, int requestCode) {
|
|
||||||
// We don't want to fire multiple resolutions at once since that can result
|
|
||||||
// in stacked dialogs after rotation or another similar event.
|
|
||||||
if (mIsResolving) {
|
|
||||||
Log.w(TAG, "resolveResult: already resolving.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.w(TAG, "Resolving: " + rae);
|
|
||||||
try {
|
|
||||||
rae.startResolutionForResult(this.activity, requestCode);
|
|
||||||
mIsResolving = true;
|
|
||||||
} catch (IntentSender.SendIntentException e) {
|
|
||||||
Log.e(TAG, "STATUS: Failed to send resolution.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Display a short Toast message **/
|
|
||||||
private void showToast(String msg) {
|
|
||||||
Toast.makeText(this.activity, msg, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.GoogleAuth;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by sebastian on 07.11.17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class RequestCode {
|
|
||||||
public static final int RC_SAVE = 1;
|
|
||||||
public static final int RC_HINT = 2;
|
|
||||||
public static final int RC_READ = 3;
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ package de.sebse.fuplanner.tools;
|
|||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.Canteen.CanteenBrowser;
|
import de.sebse.fuplanner.services.Canteen.CanteenBrowser;
|
||||||
import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
|
||||||
import de.sebse.fuplanner.services.kvv.KVV;
|
import de.sebse.fuplanner.services.kvv.KVV;
|
||||||
import de.sebse.fuplanner.services.News.NewsManager;
|
import de.sebse.fuplanner.services.News.NewsManager;
|
||||||
|
|
||||||
@@ -18,8 +17,6 @@ public interface MainActivityListener {
|
|||||||
|
|
||||||
KVV getKVV();
|
KVV getKVV();
|
||||||
|
|
||||||
GoogleAuth getGoogleAuth();
|
|
||||||
|
|
||||||
CanteenBrowser getCanteenBrowser();
|
CanteenBrowser getCanteenBrowser();
|
||||||
|
|
||||||
NewsManager getNewsManager();
|
NewsManager getNewsManager();
|
||||||
|
|||||||
@@ -17,3 +17,12 @@ org.gradle.jvmargs=-Xmx1536m
|
|||||||
# This option should only be used with decoupled projects. More details, visit
|
# This option should only be used with decoupled projects. More details, visit
|
||||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||||
# org.gradle.parallel=true
|
# org.gradle.parallel=true
|
||||||
|
|
||||||
|
systemProp.http.proxyHost=proxy1-3.biotronik.int
|
||||||
|
systemProp.http.proxyPort=9090
|
||||||
|
systemProp.http.proxyUser=Sebastian%20Seedorf
|
||||||
|
systemProp.http.proxyPassword=1111ApoTheke
|
||||||
|
systemProp.https.proxyHost=proxy1-3.biotronik.int
|
||||||
|
systemProp.https.proxyPort=9090
|
||||||
|
systemProp.https.proxyUser=Sebastian%20Seedorf
|
||||||
|
systemProp.https.proxyPassword=1111ApoTheke
|
||||||
Reference in New Issue
Block a user