use of com.google.android.gms.auth.api.credentials.Credential in project FirebaseUI-Android by firebase.
the class SignInDelegate method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case RC_CREDENTIALS_READ:
if (resultCode == ResultCodes.OK) {
// credential selected from SmartLock, log in with that credential
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
handleCredential(credential);
} else {
// Smart lock selector cancelled, go to the AuthMethodPicker screen
startAuthMethodChoice();
}
break;
case RC_IDP_SIGNIN:
case RC_AUTH_METHOD_PICKER:
case RC_EMAIL_FLOW:
finish(resultCode, data);
break;
default:
IdpSignInContainer signInContainer = IdpSignInContainer.getInstance(getActivity());
if (signInContainer != null) {
signInContainer.onActivityResult(requestCode, resultCode, data);
}
}
}
use of com.google.android.gms.auth.api.credentials.Credential in project FirebaseUI-Android by firebase.
the class SmartLockBase method credentialsFromFirebaseUser.
/**
* Make a list of {@link Credential} from a FirebaseUser. Useful for deleting Credentials,
* not for saving since we don't have access to the password.
*/
public static List<Credential> credentialsFromFirebaseUser(@NonNull FirebaseUser user) {
if (TextUtils.isEmpty(user.getEmail())) {
Log.w(TAG, "Can't get credentials from user with no email: " + user);
return Collections.emptyList();
}
List<Credential> credentials = new ArrayList<>();
for (UserInfo userInfo : user.getProviderData()) {
// Get provider ID from Firebase Auth
String providerId = userInfo.getProviderId();
// Convert to Credentials API account type
String accountType = providerIdToAccountType(providerId);
// Build and add credential
Credential.Builder builder = new Credential.Builder(user.getEmail()).setAccountType(accountType);
// to make deletion succeed.
if (accountType == null) {
builder.setPassword("some_password");
}
credentials.add(builder.build());
}
return credentials;
}
use of com.google.android.gms.auth.api.credentials.Credential in project WordPress-Android by wordpress-mobile.
the class SmartLockHelper method saveCredentialsInSmartLock.
public void saveCredentialsInSmartLock(@NonNull final String username, @NonNull final String password, @NonNull final String displayName, @NonNull final Uri profilePicture) {
Activity activity = getActivityAndCheckAvailability();
if (activity == null || mCredentialsClient == null || !mCredentialsClient.isConnected()) {
return;
}
Credential credential = new Credential.Builder(username).setPassword(password).setName(displayName).setProfilePictureUri(profilePicture).build();
Auth.CredentialsApi.save(mCredentialsClient, credential).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (!status.isSuccess() && status.hasResolution()) {
try {
Activity activity = getActivityAndCheckAvailability();
if (activity == null) {
return;
}
// This prompt the user to resolve the save request
status.startResolutionForResult(activity, SignInActivity.SMART_LOCK_SAVE);
} catch (IntentSender.SendIntentException e) {
// Could not resolve the request
}
}
}
});
}
use of com.google.android.gms.auth.api.credentials.Credential in project WordPress-Android by wordpress-mobile.
the class SmartLockHelper method deleteCredentialsInSmartLock.
public void deleteCredentialsInSmartLock(@NonNull final String username, @NonNull final String password) {
Activity activity = getActivityAndCheckAvailability();
if (activity == null || mCredentialsClient == null || !mCredentialsClient.isConnected()) {
return;
}
Credential credential = new Credential.Builder(username).setPassword(password).build();
Auth.CredentialsApi.delete(mCredentialsClient, credential).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
AppLog.i(T.NUX, status.isSuccess() ? "SmartLock: credentials deleted for username: " + username : "SmartLock: Credentials not deleted for username: " + username);
}
});
}
use of com.google.android.gms.auth.api.credentials.Credential in project WordPress-Android by wordpress-mobile.
the class SmartLockHelper method smartLockAutoFill.
public void smartLockAutoFill(@NonNull final Callback callback) {
Activity activity = getActivityAndCheckAvailability();
if (activity == null || mCredentialsClient == null || !mCredentialsClient.isConnected()) {
return;
}
CredentialRequest credentialRequest = new CredentialRequest.Builder().setPasswordLoginSupported(true).build();
Auth.CredentialsApi.request(mCredentialsClient, credentialRequest).setResultCallback(new ResultCallback<CredentialRequestResult>() {
@Override
public void onResult(@NonNull CredentialRequestResult result) {
Status status = result.getStatus();
if (status.isSuccess()) {
Credential credential = result.getCredential();
callback.onCredentialRetrieved(credential);
} else {
if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
try {
Activity activity = getActivityAndCheckAvailability();
if (activity == null) {
return;
}
// Prompt the user to choose a saved credential
status.startResolutionForResult(activity, SignInActivity.SMART_LOCK_READ);
} catch (IntentSender.SendIntentException e) {
AppLog.d(T.NUX, "SmartLock: Failed to send resolution for credential request");
}
} else {
// The user must create an account or log in manually.
AppLog.d(T.NUX, "SmartLock: Unsuccessful credential request.");
}
}
}
});
}
Aggregations