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

跟風遠走 提交于 2020-03-05 05:54:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!