use of com.google.firebase.auth.UserInfo 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.firebase.auth.UserInfo in project mxisd by kamax-io.
the class GoogleFirebaseAuthenticator method authenticate.
@Override
public BackendAuthResult authenticate(_MatrixID mxid, String password) {
if (!isEnabled()) {
throw new IllegalStateException();
}
log.info("Trying to authenticate {}", mxid);
final BackendAuthResult result = BackendAuthResult.failure();
String localpart = mxid.getLocalPart();
CountDownLatch l = new CountDownLatch(1);
getFirebase().verifyIdToken(password).addOnSuccessListener(token -> {
try {
if (!StringUtils.equals(localpart, token.getUid())) {
log.info("Failure to authenticate {}: Matrix ID localpart '{}' does not match Firebase UID '{}'", mxid, localpart, token.getUid());
result.fail();
return;
}
result.succeed(mxid.getId(), UserIdType.MatrixID.getId(), token.getName());
log.info("{} was successfully authenticated", mxid);
log.info("Fetching profile for {}", mxid);
CountDownLatch userRecordLatch = new CountDownLatch(1);
getFirebase().getUser(token.getUid()).addOnSuccessListener(user -> {
try {
toEmail(result, user.getEmail());
toMsisdn(result, user.getPhoneNumber());
for (UserInfo info : user.getProviderData()) {
toEmail(result, info.getEmail());
toMsisdn(result, info.getPhoneNumber());
}
log.info("Got {} 3PIDs in profile", result.getProfile().getThreePids().size());
} finally {
userRecordLatch.countDown();
}
}).addOnFailureListener(e -> {
try {
log.warn("Unable to fetch Firebase user profile for {}", mxid);
result.fail();
} finally {
userRecordLatch.countDown();
}
});
waitOnLatch(result, userRecordLatch, "Firebase user profile");
} finally {
l.countDown();
}
}).addOnFailureListener(e -> {
try {
if (e instanceof IllegalArgumentException) {
log.info("Failure to authenticate {}: invalid firebase token", mxid);
} else {
log.info("Failure to authenticate {}: {}", mxid, e.getMessage(), e);
log.info("Exception", e);
}
result.fail();
} finally {
l.countDown();
}
});
waitOnLatch(result, l, "Firebase auth check");
return result;
}
use of com.google.firebase.auth.UserInfo in project FirebaseAuth-Android by jirawatee.
the class ManageUserActivity method updateUI.
private void updateUI(FirebaseUser user) {
if (user != null) {
// User's profile
mTextViewProfile.setText("Firebase ID: " + user.getUid());
mTextViewProfile.append("\n");
mTextViewProfile.append("DisplayName: " + user.getDisplayName());
mTextViewProfile.append("\n");
mTextViewProfile.append("Email: " + user.getEmail());
mTextViewProfile.append("\n");
mTextViewProfile.append("Photo URL: " + user.getPhotoUrl());
// User's provider
mTextViewProvider.setText(null);
for (UserInfo profile : user.getProviderData()) {
// Id of the provider (ex: google.com)
mTextViewProvider.append("providerId: " + profile.getProviderId());
mTextViewProvider.append("\n");
// UID specific to the provider
mTextViewProvider.append("UID: " + profile.getUid());
mTextViewProvider.append("\n");
mTextViewProvider.append("name: " + profile.getDisplayName());
mTextViewProvider.append("\n");
mTextViewProvider.append("email: " + profile.getEmail());
mTextViewProvider.append("\n");
mTextViewProvider.append("photoUrl: " + profile.getPhotoUrl());
if (!"password".equals(profile.getProviderId())) {
mTextViewProvider.append("\n\n");
}
}
findViewById(R.id.provider_fields).setVisibility(View.VISIBLE);
findViewById(R.id.update_profile_fields).setVisibility(View.VISIBLE);
findViewById(R.id.update_email_fields).setVisibility(View.VISIBLE);
findViewById(R.id.update_password_fields).setVisibility(View.VISIBLE);
findViewById(R.id.send_password_reset_fields).setVisibility(View.VISIBLE);
findViewById(R.id.delete_fields).setVisibility(View.VISIBLE);
} else {
mTextViewProfile.setText(R.string.signed_out);
mTextViewProvider.setText(null);
findViewById(R.id.provider_fields).setVisibility(View.GONE);
findViewById(R.id.update_profile_fields).setVisibility(View.GONE);
findViewById(R.id.update_email_fields).setVisibility(View.GONE);
findViewById(R.id.update_password_fields).setVisibility(View.GONE);
findViewById(R.id.send_password_reset_fields).setVisibility(View.GONE);
findViewById(R.id.delete_fields).setVisibility(View.GONE);
}
hideProgressDialog();
}
use of com.google.firebase.auth.UserInfo in project FirebaseUI-Android by firebase.
the class SignedInActivity method populateProfile.
private void populateProfile(@Nullable IdpResponse response) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user.getPhotoUrl() != null) {
GlideApp.with(this).load(user.getPhotoUrl()).fitCenter().into(mBinding.userProfilePicture);
}
mBinding.userEmail.setText(TextUtils.isEmpty(user.getEmail()) ? "No email" : user.getEmail());
mBinding.userPhoneNumber.setText(TextUtils.isEmpty(user.getPhoneNumber()) ? "No phone number" : user.getPhoneNumber());
mBinding.userDisplayName.setText(TextUtils.isEmpty(user.getDisplayName()) ? "No display name" : user.getDisplayName());
if (response == null) {
mBinding.userIsNew.setVisibility(View.GONE);
} else {
mBinding.userIsNew.setVisibility(View.VISIBLE);
mBinding.userIsNew.setText(response.isNewUser() ? "New user" : "Existing user");
}
List<String> providers = new ArrayList<>();
if (user.getProviderData().isEmpty()) {
providers.add(getString(R.string.providers_anonymous));
} else {
for (UserInfo info : user.getProviderData()) {
switch(info.getProviderId()) {
case GoogleAuthProvider.PROVIDER_ID:
providers.add(getString(R.string.providers_google));
break;
case FacebookAuthProvider.PROVIDER_ID:
providers.add(getString(R.string.providers_facebook));
break;
case TwitterAuthProvider.PROVIDER_ID:
providers.add(getString(R.string.providers_twitter));
break;
case EmailAuthProvider.PROVIDER_ID:
providers.add(getString(R.string.providers_email));
break;
case PhoneAuthProvider.PROVIDER_ID:
providers.add(getString(R.string.providers_phone));
break;
case EMAIL_LINK_PROVIDER:
providers.add(getString(R.string.providers_email_link));
break;
case FirebaseAuthProvider.PROVIDER_ID:
// Ignore this provider, it's not very meaningful
break;
default:
providers.add(info.getProviderId());
}
}
}
mBinding.userEnabledProviders.setText(getString(R.string.used_providers, providers));
}
Aggregations