android - 使用手机号码和密码登录 Firebase(无 OTP)
问题描述
我正在尝试制作一个 android 应用程序,使用手机号码和密码进行身份验证(是的,不是 OTP !!!)。我已经阅读了自定义令牌的文章,但没有理解。(这是文档的链接) 有人可以帮助实现这个吗?(请使用自定义令牌显示它的实现)提前谢谢您!!;)
解决方案
自定义身份验证是一个完全自定义的解决方案,需要您自己设置额外的 OAuth 提供程序,而您很可能对此不感兴趣。
相反,您可以通过使用密码 Auth 来实现此目的,只需将项目名称作为 domain 附加到末尾即可125132346@myproject-0.com
。这确实意味着它与电话验证和您可能认为理想的 OTP 没有直接关联。很酷的是,如果您将来还需要链接您的手机验证,Firebase 支持 Auth 链接。
密码:https ://firebase.google.com/docs/auth/web/password-auth
链接身份验证:https ://firebase.google.com/docs/auth/web/account-linking
更新
要实现自定义令牌,您必须在云服务(例如 Firebase 云功能)上安装 admin-sdk。然后,您必须将用户重定向到该函数或使用用户凭据调用它以生成令牌,通常这是通过另一个 OAuth 提供程序完成的,以防止欺骗。
最小设置如下: Cloud Function with onRequest
exports.phoneAuth = functions.https.onRequest((request, response) => {
const uid = request.body.number; // users phone number from the request
return admin
.auth()
.createCustomToken(uid)
.then((customToken) => {
response.status(200).send(customToken);
})
.catch((error) => {
console.error('Error creating custom token:', error);
});
});
推荐阅读
- coq - Coq - 你如何应用匹配子句的暗示?
- python - 减少使用 if's / elif
- mongodb - 跨文档数组元素的MongoDB唯一索引(不跨嵌套文档)
- c++ - 复制构造函数是否有助于 C++ 中的 memcpy?
- javascript - 如何用点击计数值替换图像而不是添加带有点击计数值的图像?(删除图像+添加新图像)
- arrays - 用 1 和 0 填充矩阵以使其满足给定的行和列总和的程序
- python - 使用抓取的数据创建数据框
- opencv - USB 网络摄像头和可用格式
- python - 如何使用python从语料库中删除单个字符(字母)
- r - 使用字符串向量在数据框中查找字符串