【发布时间】:2017-04-10 03:56:36
【问题描述】:
用于服务器的 Swift + Vapor 框架 + Xcode 8.1
我正在尝试读取向我的数据库发出 HTTP 请求的 Firebase 实时数据库,但我的权限被拒绝。
这些是步骤:
1. 使用从“console.developers.google.com”下载的密钥创建 JWT 签名
2. 向 OAuth2 服务器发送 POST 请求并获取访问令牌
3. 使用从 OAuth2 服务器接收到的访问令牌向 firebase 数据库发送 GET 请求。
我得到“权限被拒绝”,HTTP/1.1 403 Forbidden
// the header of the JSON Web Token (first part of the JWT)
let headerJWT = ["alg":"RS256","typ":"JWT"]
// the claim set of the JSON Web Token
let jwtClaimSet =
["iss":"firebase-adminsdk-kxx5h@fir-30c9e.iam.gserviceaccount.com",
"scope":"https://www.googleapis.com/auth/firebase.database", //is this the correct API to access firebase database?
"aud":"https://www.googleapis.com/oauth2/v4/token",
"exp": expDate,
"iat": iatDate]
drop.get("access") { request in
var accesstoken = "ya29.ElqhA-....XXXX"
let responseFirebase = try drop.client.get("https://fir- 30c9e.firebaseio.com/data/Users.json",
headers: ["Authorization":"Bearer \(accesstoken)"],
query: [:])
print("FirebaseResponse_is \(responseFirebase)")
return "success"
}
【问题讨论】:
-
@frank van puffelen 您能否就我为什么无法访问我的 Firebase 数据库发表您的看法?
标签: firebase firebase-realtime-database service-accounts vapor