Swift + Vapor 服务器框架 + Xcode 8.1
我正在尝试读取 Firebase 实时数据库,向我的数据库发出 HTTP 请求,但权限被拒绝。
这些是步骤:
1. 创建 JWT,使用从“console.developers.google.com”下载的密钥对其进行签名
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":"[email protected] /cdn-cgi/l/email-protection",
"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"
}
TLDR;尝试放置auth=<TOKEN>
在您的查询字符串中而不是使用授权标头。
Firebase 文档并不清楚它是如何工作的。根据文档,三种方法应该有效。
-
auth=<TOKEN>
在查询字符串中(link https://firebase.google.com/docs/reference/rest/database/#section-param-auth)
-
access_token=<TOKEN>
在查询字符串中(link https://firebase.google.com/docs/reference/rest/database/user-auth#section-using-the-access-token)
-
Authorization: Bearer <TOKEN>
在请求标头中(link https://firebase.google.com/docs/reference/rest/database/user-auth#section-using-the-access-token)
然而,我不相信这三种方法都确实有效。我在我的应用程序中使用方法 1,所以我知道其中一种方法肯定有效。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)