问题
I am developing Android app using Firebase. Because of that, I want to use Firebase Auth. I have following requirements:
- Register/Log in using Facebook
- Register/Log in using Email/Password
- Register/Log in using Phone Number/Password
The first two are OK, I followed basic tutorials. However, Phone Number / Password is the problem here. Firebase supports only Phone Number/SMS Token for this (its called Phone Auth), but there is no mention about my case. I do not want to hack Firebase and use its realtime database instead of Auth 'database'. Is there any better way to achieve this?
Thank you.
回答1:
Firebase phone authentication is using OTP(one time password). This way there is no hassle for the user to remember the password. Once authenticated, you will be registered. The sms code acts as a password. But that is for one time. Usually , users prefer such behaviour in which you dont have to remember the passwords. If you are still looking for the way you want, see this link and create a custom authentication method. https://firebase.google.com/docs/auth/android/custom-auth
回答2:
I had a similar problem - I combined firebase auth(email + password) with (phone+otp) to get phone+password auth -
https://medium.com/@shivampesitbng/firebase-phone-password-auth-in-vue-b94f15b8fb3d
回答3:
If you have both email and phone of your user and you can use Admin SDK, then perhaps you could exchange users phone number to his email and login with email and password in the background.
Something like this (node.js)
admin.auth().getUserByPhoneNumber(phoneNumber)
.then(user => {
firebase.auth().signInWithEmailAndPassword(user.email, password);
});
来源:https://stackoverflow.com/questions/46351512/firebase-auth-using-phone-number-and-password