Firebase REST API 使用电话号码进行身份验证 [英] Firebase REST API Authenticate With Phone Number

查看:28
本文介绍了Firebase REST API 使用电话号码进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PAW 来尝试测试使用 Firebase 部署的不同云功能.该应用程序使用电话身份验证,但目前几乎没有关于如何通过 REST API 完成电话号码身份验证的文档.

我已根据

  1. (但这是可选的)使会话信息成为正文响应动态值

  1. 创建您的验证电话号码请求

  1. (同样,可选)使 idToken 也是一个正文响应动态值

  1. 在您对 Firebase 执行的任何其他后续请求中使用 idToken 动态值

将变量添加为正文响应动态值的最佳部分是您可以将它们链接起来并按顺序调用它们:

I am using PAW to try and test different cloud functions deployed with Firebase. The app uses phone authentication, however currently there is little to no documentation on how to accomplish phone number authentication via REST API.

I have whitelisted a phone number for testing as per instructions here.

It appears that what I need to do is call on the verifyPhoneNumber method, which I have pieced together that the REST API endpoint I need is in the format:

https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPhoneNumber?key={WEB_API_KEY}

Now where I get stuck is in trying to pass the data that is expected. It looks like this endpoint expects a phoneNumber and an applicationVerifier object. I've pieced this together from the corresponding documentation here.

I try to make a request that looks like:

POST /identitytoolkit/v3/relyingparty/verifyPhoneNumber?key={WEB_API_KEY}
Content-Type: application/json; charset=utf-8
Host: www.googleapis.com
Connection: close
User-Agent: Paw/3.1.7 (Macintosh; OS X/10.13.6) GCDHTTPRequest
Content-Length: 73

{"phoneNumber":"+18035551111","applicationVerifier":{"type":"recaptcha"}}

The response I receive is:

HTTP/1.1 400 Bad Request
Vary: X-Origin
Vary: Referer
Content-Type: application/json; charset=UTF-8
Date: Thu, 13 Sep 2018 16:35:33 GMT
Server: ESF
Cache-Control: private
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Alt-Svc: quic=":443"; ma=2592000; v="44,43,39,35"
Accept-Ranges: none
Vary: Origin,Accept-Encoding
Connection: close

{
  "error": {
    "code": 400,
    "message": "MISSING_SESSION_INFO",
    "errors": [
      {
        "message": "MISSING_SESSION_INFO",
        "domain": "global",
        "reason": "invalid"
      }
    ]
  }
}

I'm not sure what I'm doing wrong at this point as I'm running out of documentation and sort of just blindly guessing parameters now. How can I authenticate via white-listed phone number via REST API for testing?

解决方案

  1. Create you verification code request (the key is an environment variable)

  1. (but this is optional) make the session info a Body Response Dynamic Value

  1. Create your verify phone number request

  1. (again, optional) make the idToken also a Body Response Dynamic Value

  1. Use the idToken dynamic value in any other subsequent requests you perform to Firebase

The best part about adding the variables as Body Response Dynamic Values is you can chain them and call them in a sequence:

这篇关于Firebase REST API 使用电话号码进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆