繁体   English   中英

有什么方法可以使用“auth REST API”从我的 firebase auth 用户那里获得“emailVerified”?

[英]Is there any way to get the "emailVerified" from my firebase auth user using ''auth REST API''?

I'm currently using firebase as my backend webserver, and I used the auth REST API to authenticate users in my app (login using email and password ). My question is I want to know if there is an http request that I can a response by it that includes if the email that logged in is verified or not, I have tried mixing the rest API with the firebase-Auth package but it didn'不工作。

我刚刚找到了“setAccountInfo”端点,但要让它工作,我需要发送给用户的确认 email 中的“oobCode”,我猜我无法自动获得它。 谁可以帮我这个事?

我认为您可以使用getAccountInfo端点来做到这一点,该端点返回包含有emailVerified属性的以下有效负载(来自文档的示例):

{
  "users": [
    {
      "localId": "ZY1rJK0...",
      "email": "user@example.com",
      "emailVerified": false,
      "displayName": "John Doe",
      "providerUserInfo": [
        {
          "providerId": "password",
          "displayName": "John Doe",
          "photoUrl": "http://localhost:8080/img1234567890/photo.png",
          "federatedId": "user@example.com",
          "email": "user@example.com",
          "rawId": "user@example.com",
          "screenName": "user@example.com"
        }
      ],
      "photoUrl": "https://lh5.googleusercontent.com/.../photo.jpg",
      "passwordHash": "...",
      "passwordUpdatedAt": 1.484124177E12,
      "validSince": "1484124177",
      "disabled": false,
      "lastLoginAt": "1484628946000",
      "createdAt": "1484124142000",
      "customAuth": false
    }
  ]
}

样品请求(来自文档,已粘贴以供参考):

 curl 'https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=[API_KEY]' \\ -H 'Content-Type: application/json' --data-binary '{"idToken":"[FIREBASE_ID_TOKEN]"}' 

在上面的示例中,您将[API_KEY]替换为Firebase项目的Web API密钥,并将[FIREBASE_ID_TOKEN]替换为用户的Firebase ID令牌。


PS:我没有尝试过在问题末尾提到的setAccountInfo端点,但是我认为它用于发送(POST)通过电子邮件收到的验证码(来自doc :->“ oobCode:发送的操作码到用户的电子邮件以进行电子邮件验证。”)

import pyrebase
firebaseConfig = {
  "apiKey": "",
  "authDomain": "",
  "projectId": "",
  "storageBucket": "",
  "messagingSenderId": "",
  "appId": "",
  "measurementId": "",
  "databaseURL": ""
}
firebase = pyrebase.initialize_app(firebaseConfig)
auth = firebase.auth()
email= "your Email"
password = "your Password"
login = auth.sign_in_with_email_and_password(email, password)
acc_info=auth.get_account_info(login['idToken'])
if "users" in acc_info:
    if acc_info["users"]:
        for val in acc_info['users']:
            if "emailVerified" in val:
                print(val["emailVerified"])

暂无
暂无

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

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