简体   繁体   English

Electron js,Angular 5中的Firebase电话号码身份验证

[英]Firebase phone number authentication in Electron js, Angular 5

I am trying to implement Firebase Phone Number Authentication but there is a problem with environment such as I am using electron js. 我正在尝试实施Firebase电话号码身份验证,但是环境存在问题,例如我正在使用电子js。

Here is my code 这是我的代码

import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase';

constructor(public afAuth: AngularFireAuth) {}

sendPhoneNumber() {

const phoneNumber = '+' + this.phoneNumber;
const appVerifier = new firebase.auth.RecaptchaVerifier('LoginPage-signInButton', {
    'size': 'invisible',
    'callback': (response) => {
      console.log('response', response)
    },
    'error-callback': (error) => {
      console.log('error', error);
    }
  });
  this.afAuth.auth.signInWithPhoneNumber(phoneNumber, appVerifier)
    .then(confirmationResult => {
      console.log(confirmationResult);
    }) 
}

And I am getting this error 我收到这个错误

code: "auth/operation-not-supported-in-this-environment"
message: "RecaptchaVerifier is only supported in a browser HTTP/HTTPS environment."

are there any solutions for this problem or workaround? 有针对此问题或解决方法的任何解决方案吗?

Based on your question, you seem to be trying to handle Phone authentication in your Electron Application. 根据您的问题,您似乎正在尝试在电子应用程序中处理电话身份验证。 Phone authentication using Firebase JS library might not work based on how you are handling it in your Electron environment since the reCAPTCHA will be unable to verify the origin of your application. 基于FireCAP JS库的电话身份验证可能无法根据您在Electron环境中的处理方式进行工作,因为reCAPTCHA将无法验证应用程序的来源。 This is due to the fact that the origin will look like file://assets/index.html. 这是由于原点看起来像file://assets/index.html。

Firebase's phone authentication service for web depends on an app verifier interface: https://firebase.google.com/docs/reference/js/firebase.auth.RecaptchaVerifier which RecaptchaVerifier implements. Firebase的网络电话身份验证服务取决于应用验证程序界面:RecaptchaVerifier实现的https://firebase.google.com/docs/reference/js/firebase.auth.RecaptchaVerifier

Do this: 做这个:

Open on browser, render the reCAPTCHA, get the reCAPTCHA token, close the browser and then pass it back to your the Electron app then implement your own firebase.auth.ApplicationVerifier. 在浏览器上打开,呈现reCAPTCHA,获取reCAPTCHA令牌,关闭浏览器,然后将其传递回Electron应用程序,然后实现自己的firebase.auth.ApplicationVerifier。

Open a browser custom tab and redirect to your own and white-list in the Firebase Console where firebase.auth.RecaptchaVerifier will be rendered. 打开浏览器“自定义”标签,然后在Firebase控制台中重定向到您自己的白名单,将在其中显示firebase.auth.RecaptchaVerifier。 You then pass the reCAPTCHA response token back to your app. 然后,您将reCAPTCHA响应令牌传递回您的应用程序。 This guarantees that only your app can open it. 这样可以保证只有您的应用可以打开它。

You need to listen to incoming links in your app and parse the reCAPTCHA token. 您需要监听应用程序中的传入链接并解析reCAPTCHA令牌。 Repackage it in a firebase.auth.ApplicationVerifier implementation. 将其重新打包在firebase.auth.ApplicationVerifier实现中。 You can now pass it to signInWithPhoneNumber to complete sign-in. 现在,您可以将其传递给signInWithPhoneNumber以完成登录。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM