【发布时间】:2021-09-06 22:54:34
【问题描述】:
我想使用 Rest API 获取/设置实时数据库规则,但是没有教程适合我。我尝试这样做:
- 我将 url 复制到我在欧洲的实时数据库
https://my-project-database.europe-west1.firebasedatabase.app/ - 我从本教程中复制了 java 代码:https://firebase.google.com/docs/database/rest/auth,它应该给我访问令牌
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