【问题标题】:Firebase Realtime Database - how to manage database rules using REST APIFirebase 实时数据库 - 如何使用 REST API 管理数据库规则
【发布时间】:2021-09-06 22:54:34
【问题描述】:

我想使用 Rest API 获取/设置实时数据库规则,但是没有教程适合我。我尝试这样做:

    val googleCred = GoogleCredential.fromStream(File("/path/to/my/key.json").inputStream())
    val scoped = googleCred.createScoped(
        Arrays.asList( // or use firebase.database.readonly for read-only access
            "https://www.googleapis.com/auth/firebase.database",
            "https://www.googleapis.com/auth/userinfo.email"
        )
    )
    scoped.refreshToken()
    val token = scoped.accessToken
    println(token)

但是这个令牌看起来很奇怪,最后有一长串点,就像(它与:Why am I getting a JWT with a bunch of periods/dots back from Google OAuth?有关)

ya29.c.Kp8BCgi0lxWtUt-_[普通的 JWT 东西,为 安全]yVvGk................................................. ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... .....................

  • 我使用 HTTP GET 来访问https://my-project-database.europe-west1.firebasedatabase.app/.settings/rules.json?access_token=$token 之类的地址,但我得到了 401 UNAUTHORIZED

我认为这是因为我使用了整个这个充满点的奇怪标记作为access_token 变量。所以现在我有问题如何转换它并用作access_token 使其工作

编辑: 我创建了这个要点,虽然它在 python 中它有完全相同的问题。如何使它工作? https://gist.github.com/solveretur/86d53a9c0221f096c38c3ef8f70a8dbd

【问题讨论】:

    标签: firebase kotlin firebase-realtime-database


    【解决方案1】:

    我使用了错误的数据库密钥。

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 2021-01-31
      • 1970-01-01
      • 1970-01-01
      • 2020-03-04
      • 2020-08-08
      相关资源
      最近更新 更多