简体   繁体   English

是否可以在Firebase中使用电子邮件和电话号码进行身份验证?

[英]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.

相关问题 Firebase电话号码身份验证错误 - Firebase Phone number authentication Error Firebase 认证:Swift 中的电话号码认证 - Firebase Authentication : Phone number authentication in Swift Firebase 更新电子邮件和电话号码。 “此操作很敏感,需要最近的身份验证。” updateEmail ios swift 上的错误 - Firebase Update Email and Phone number. “this operation is sensitive and requires recent authentication.” Error on updateEmail ios swift 在 Firebase 身份验证中更新电话号码 - Swift - Update Phone Number in Firebase Authentication - Swift 离子电容 Firebase 电话号码认证问题 - Ionic Capacitor Firebase Phone Number Authentication Problems 电话号码身份验证不适用于 IOS 设备 [Firebase] - Authentication of phone number is not working on IOS Devices [Firebase] 设备无法使用Firebase身份验证电话号码 - Device not working with Firebase Authentication Phone Number Firebase验证电话号码,然后使用Swift使用电子邮件/密码对用户进行身份验证 - Firebase verify phone number then authenticate user with email/password with Swift Firebase 电话身份验证失败 - Firebase phone Authentication failes Firebase - 是否可以阻止电话号码注册 - Firebase -is it possible to block a phone number from signing up
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM