Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Firebase Auth Provider for Loged in User

How can i check that my user Loged in to my app Using which Auth Provider ? I wanted to detect that did my user loged in to my app using Facebook auth provider or using Email Provider or by using Google auth provider . I have searched this in Firebase Docs but i couldnt find any proper answer ,

like image 462
Muhammad Usman Avatar asked Sep 16 '17 11:09

Muhammad Usman


3 Answers

FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if (firebaseUser.getProviderData().size() > 0) {
            //Prints Out google.com for Google Sign In, prints facebook.com for Facebook
            e("TOM", "Provider: " + firebaseUser.getProviderData().get(firebaseUser.getProviderData().size() - 1).getProviderId());

        }
like image 143
Dr Adams Avatar answered Nov 15 '22 14:11

Dr Adams


You can always check the list of providers as Malik pointed out. However, as you can have multiple providers linked to the same user, to get the sign in method of the current User with multiple providers, you have to check the ID token. You need to check firebase.sign_in_provider claim in the token. That will give you the sign in method used to get the ID token. To get it on the client, you need to getIdToken and then parse the returned JWT with some JWT parser.

like image 35
bojeil Avatar answered Nov 15 '22 13:11

bojeil


You can use method getIdTokenResult() of your user object (firebase.User) to get IdTokenResult object, whose signInProvider property you can use to detect signin method of your logged in user.

like image 1
Anand Shankar Avatar answered Nov 15 '22 13:11

Anand Shankar