Cly*_*row 5 kotlin firebase firebase-realtime-database
我想使用 Rest API 获取/设置实时数据库规则,但是没有教程适合我。我尝试这样做:
https://my-project-database.europe-west1.firebasedatabase.app/ 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)
Run Code Online (Sandbox Code Playgroud)
然而,令牌看起来很奇怪,末尾有一长串点(它与:为什么我从 Google OAuth 得到带有一堆句点/点的 JWT?)
ya29.c.Kp8BCgi0lxWtUt-_[普通 JWT 内容,出于安全原因进行了编辑]yVvGk................................. ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ......................................
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