首页 > 解决方案 > Chrome 扩展中的 Firebase 电话号码身份验证

问题描述

可能吗?我在https://firebase.google.com/docs/auth/web/phone-auth上读了一点,但它一直提到OAuth redirect domains,不确定 chrome 扩展域是否对此有效?

标签: firebasegoogle-chrome-extensionoauthoauth-2.0firebase-authentication

解决方案


它们不适用于 chrome 扩展程序,但您可以在网页中呈现 reCAPTCHA 验证程序,获取验证 ID 和代码并将其传递给您的 chrome 扩展程序postMessage,然后使用以下方式通过您的 chrome 扩展程序登录:

// You get verificationId from reCAPTCHA rendered on web page.
// You ask the user to provide the 6 digit code.
var cred = firebase.auth.PhoneAuthProvider.credential(verificationId, code);
firebase.auth().signInWithCredential(cred)
  .then(function(result) {
    // User signed in.
  })
  .catch(function(error) {
    // Error occurred.
  });

推荐阅读