用于服务器+ Xcode 8.1的Swift + Vapor框架
我正在尝试阅读Firebase实时数据库向我的数据库发出HTTP请求,但我得到了许可被拒绝.
以下是这些步骤:
1.使用从"console.developers.google.com"下载的密钥创建JWT签名
2.将POST请求发送到OAuth2服务器并获取访问令牌
3.将GET请求发送到firebase数据库,并从中接收访问令牌OAuth2服务器.
我得到"权限被拒绝",HTTP/1.1 403禁止
// 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" …Run Code Online (Sandbox Code Playgroud)