无法通过 HTTP/REST 错误 403 Forbidden 访问 FireBase 数据库 [英] Can't access FireBase Database via HTTP/REST error 403 Forbidden
问题描述
适用于服务器的 Swift + Vapor 框架 + Xcode 8.1
Swift + Vapor framework for server + Xcode 8.1
我正在尝试读取向我的数据库发出 HTTP 请求的 Firebase 实时数据库,但我的权限被拒绝.
I am trying to read Firebase Realtime Database making HTTP requests to my DB, but I get permission denied.
这些是步骤:
1. 创建 JWT 使用从console.developers.google.com"下载的密钥对其进行签名
2. 向 OAuth2 服务器发送 POST 请求并获取访问令牌
3. 使用从 OAuth2 服务器收到的访问令牌向 firebase 数据库发送 GET 请求.
These are the steps:
1. create JWT sign it with secret key downloaded from "console.developers.google.com"
2. send POST request to OAuth2 server and get access token
3. send GET request to firebase database with access token received from OAuth2 server.
我收到权限被拒绝",HTTP/1.1 403 禁止
I get "Permission denied", 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"
}
推荐答案
scope
键缺少值 https://www.googleapis.com/auth/userinfo.email代码>
let jwtClaimSet =
["iss":"firebase-adminsdk-kxx5h@fir-30c9e.iam.gserviceaccount.com",
"scope": "https://www.googleapis.com/auth/firebase.database
https://www.googleapis.com/auth/userinfo.email",
"aud":"https://www.googleapis.com/oauth2/v4/token",
"exp": expDate,
"iat": iatDate]
我找到了答案在此处浏览 Google 群组
这篇关于无法通过 HTTP/REST 错误 403 Forbidden 访问 FireBase 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!