【问题标题】:Could not parse auth token (Firebase)无法解析身份验证令牌 (Firebase)
【发布时间】:2021-10-17 05:10:30
【问题描述】:

我正在尝试使用此规则将数据保存在我的 firebase 实时数据库中:

{
  "rules": {
    "users": {
      "$uid": {
        // Allow only authenticated content owners access to their data
        ".read": "auth != null && auth.uid == $uid",
        ".write": "auth != null && auth.uid == $uid",
      },
    },
  },
}

我需要创建一个子用户并将其命名为该用户的 uid。所以,我这样做了:

user=auth.sign_in_with_email_and_password('email', 'password')
database.child('users').child(user['localId']).set("nahid",user['localId'])

但是当我运行它时,我得到了这个错误:

requests.exceptions.HTTPError: [Errno 401 Client Error: Unauthorized for url: https://khelobd-6f730-default-rtdb.firebaseio.com/users/7Km7srPfqqccZwa0On5i2QaJDUi2.json?auth=7Km7srPfqqccZwa0On5i2QaJDUi2] {
  "error" : "Could not parse auth token."
}

我该如何解决这个问题?

【问题讨论】:

    标签: python-3.x firebase firebase-realtime-database pyrebase


    【解决方案1】:

    ?auth= 参数似乎不是用户的 Firebase ID 令牌,而是 UID 本身。尝试将set() 中的user['localId'] 更改为user['idToken']

    user=auth.sign_in_with_email_and_password('email', 'password')
    database.child('users').child(user['localId']).set("nahid",user['idToken'])
    #                                                                  ^^^
    

    【讨论】:

    • 谢谢!有效。你刚刚救了我!!!
    猜你喜欢
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-16
    相关资源
    最近更新 更多