简体   繁体   中英

How to sign in with email and password using firebase admin sdk in Android

I'd like to create an Android application based on firebase. I'd like my application to autheticate users and check what their role is; so I used the method signInWithEmailAndPassword coming from the object FirebaseAuth.getInstance() to log. Then I thought to save for each user a claim so I could keep track of their roles and to do this I use the Firebase admin SDK; problem is I no longer have the method signInWithEmailAndPassword on the class FirebaseAuth so I can't log my users. What can I do to use both methods/fonctionnalities in the same project? Thank you

Carlo

You can't use the Admin SDK in an Android app. It can only be used in back-end, server-side applications. You can implement a back-end service to set the custom claims as follows:

// Assuming the idToken is the authenticated user's ID token
// sent by the Android client:
FirebaseAuth auth = FirebaseAuth.getInstance();
try {
  FirebaseToken token = auth.verifyIdToken(idToken);
  FirebaseAuth.getInstance().setCustomUserClaims(token.getUid(), myClaims);
} catch (FirebaseAuthException ex) {
  // Handle error
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM