[英]Is it possible to use email and phone number to authentication in Firebase?
I am looking for a way in swift to make user sign up with his/her phone number then add his/her email and password. 我正在寻找一种迅速使用户注册他/她的电话号码,然后添加他/她的电子邮件和密码的方法。
But when user logs in , he/she logs in only with email and password. 但是,当用户登录时,他/她仅使用电子邮件和密码登录。
The phone number is only for security reasons. 该电话号码仅出于安全原因。
You can link an email and password to a user account that is created via phone authentication but Firebase Auth does not enforce 2 factor authentication the next time the user signs in. The user is able to log in with either (email/password or phone) without requiring both. 您可以将电子邮件和密码链接到通过电话身份验证创建的用户帐户,但是Firebase Auth在用户下次登录时不会强制执行2因子身份验证。用户可以使用(电子邮件/密码或电话)登录不需要两者。 You will need to implement your own custom solution for this.
您将需要为此实现自己的自定义解决方案。 Please file a request via Firebase support or the official Firebase Google Group for 2 factor auth.
请通过Firebase支持或官方的Firebase Google网上论坛提出请求,以进行2因子验证。
If you wish to just verify the phone number and link it to the account but not require it next sign-in, you can after you create user with email and password, ask the user for the phone number, call: 如果您只想验证电话号码并将其链接到帐户,但又不需要下次登录,则可以在用电子邮件和密码创建用户后,向用户询问电话号码,然后致电:
[[FIRPhoneAuthProvider provider] verifyPhoneNumber:phoneNumber ...]
which resolves with a verificationID. 它用一个VerificationID解析。 You then initialize a phone auth credential after getting the SMS code:
然后,您在获取SMS代码后初始化电话身份验证凭据:
FIRPhoneAuthCredential *credential = [[FIRPhoneAuthProvider provider] credentialWithVerificationID:verificationID verificationCode:verificationCode];
Finally you call: [[[FIRAuth auth] currentUser] linkWithCredential:credential]
最后,您调用:
[[[FIRAuth auth] currentUser] linkWithCredential:credential]
on the currentUser using the phone credential. 使用电话凭证在currentUser上。 This will add that phone number to the email/password user.
这会将电话号码添加到电子邮件/密码用户。 You can consider it verified.
您可以认为它已通过验证。 The next time they sign in with email/password you can access that via user.phoneNumber.
下次他们使用电子邮件/密码登录时,您可以通过user.phoneNumber进行访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.