问题
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
回答1:
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
}
来源:https://stackoverflow.com/questions/58475228/how-to-sign-in-with-email-and-password-using-firebase-admin-sdk-in-android