3

Problem:

I am facing an issue. I am using Firebase Auth UI in my android app. I have requested for email in GoogleSignInOptions.

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.web_client_id))
            .requestEmail()
            .build();

Passing this GoogleSignInOptions in login builder

            new AuthUI.IdpConfig.GoogleBuilder()
                    .setSignInOptions(gso)
                    .build(),

Now when I do login by google in app, onActivityResult() is called then I am unable to get Email by FirebaseUser.getEmail(). While IdpResponse contains email.

IdpResponse response = IdpResponse.fromResultIntent(data); // response.getEmail() returns email

Above IdpResponse contains email.

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); // user.getEmail() is null

Above FirebaseUser object does not contain email.

Purpose

I want have email in FirebaseUser object. Because there are other signIn providers too. Like facebook, email/pass, twitter. so I am searching for a unique solution.

Khemraj Sharma
  • 46,529
  • 18
  • 168
  • 182
  • Okay, recheck the following steps: 1. Did you add your app's SHA1 certificate fingerprint in the Firebase project on Firebase console? 2. After adding the SHA certificate fingerprint did you download a fresh copy of google-services.json and add that to your project root folder when building the apk? These are steps you need to follow before beginning to use Google Sign-In. More about Google Sign-In- https://firebase.google.com/docs/auth/android/google-signin To test your setup try using the GoogleSigninActivity from https://github.com/firebase/quickstart-android/tree/master/auth in your app – MD Naseem Ashraf Mar 17 '19 at 08:32
  • @MDNaseemAshraf I am working on a live app, and changed login methods with firebase auth UI. then it occured. However verified it too. – Khemraj Sharma Mar 17 '19 at 08:56
  • If you're using a live app (an app already on play store) then you'd also need to add your production SHA1 fingerprints to Firebase project, the SHA1 you get from your Play Console ( https://stackoverflow.com/a/55080245/2119723 ). That means there should be at least two SHA1 fingerprints in your Firebase console for that project. Then rebuild the project with a fresh copy of google-services.json after adding the production keys to firebase project and try your app. – MD Naseem Ashraf Mar 17 '19 at 09:04
  • @MDNaseemAshraf Bro, I mean both debug and release versions are working, just email has issue. If SHA1 keys are not configured then you will not be authenticated by firebase. But issue is that if I use Firebase Auth UI then FirebaseUser object does not contain email. – Khemraj Sharma Mar 17 '19 at 09:58
  • @Khemraj did you solve your problem? – Pradeep Sep 12 '19 at 11:58
  • @Pradeep its been months, I don't remind what exactly I did to resolve this. You can check if there is some error in response by `IdpResponse.getError()`. – Khemraj Sharma Sep 12 '19 at 12:27
  • Yeah I solved that the issue is allowing multiple accounts per email cause the getEmail to be null. Now ihave resolved that. – Pradeep Sep 13 '19 at 08:05
  • @Khemraj BUt I have another serious issue. I need a big help on that. do you have time to clear my issue? please. TActually that is regarding OTP verification. The otp is sending to other numbers but not to the phone where the app is insatlled. Sometimes Not sending at all. But the logcat shows no error and onverficationcompleted is called. – Pradeep Sep 13 '19 at 08:09
  • @Khemraj https://stackoverflow.com/questions/57919903/otp-is-working-but-sometimes-not-working-at-all-in-the-firebase-authentication – Pradeep Sep 13 '19 at 08:26
  • @Pradeep I did not use phone provider ever. Sorry I don't have idea about this issue. But you can directly ask help from firebase on link. https://firebase.google.com/support/troubleshooter/report/bugs/ – Khemraj Sharma Sep 14 '19 at 08:23

1 Answers1

0

check document here Document link

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

if (user != null) {
    for (UserInfo profile : user.getProviderData()) {
        // Id of the provider (ex: google.com)
        String providerId = profile.getProviderId();

        // UID specific to the provider
        String uid = profile.getUid();

        // Name, email address, and profile photo Url
        String name = profile.getDisplayName();
        String email = profile.getEmail();
        Uri photoUrl = profile.getPhotoUrl();
Toast.makeText(Activity.this, email, Toast.LENGTH_SHORT).show();
    }
}