无法通过HTTP / REST错误403禁止访问FireBase数据库 [英] Can't access FireBase Database via HTTP/REST error 403 Forbidden

查看:402
本文介绍了无法通过HTTP / REST错误403禁止访问FireBase数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

服务器+ Xcode 8.1的Swift + Vapor框架

我正在尝试读取Firebase实时数据库向我的数据库发出HTTP请求,但是我拒绝了权限。

这些步骤是:

1.创建JWT使用从console.developers.google.com下载的密钥对其进行签名


2.将POST请求发送到OAuth2服务器并获取访问令牌

3.将GET请求发送到使用从OAuth2服务器接收的访问令牌的firebase数据库。



我得到Permission denied,HTTP / 1.1 403 Forbidden

  // JSON Web Token的头(JWT的第一部分)
let headerJWT = [alg:RS256,typ:JWT]

/ / JSON Web令牌的声明集
让jwtClaimSet =
[iss:firebase-adminsdk-kxx5h@fir-30c9e.iam.gserviceaccount.com,
scope :https://www.googleapis.com/auth/firebase.database,//这是访问Firebase数据库的正确API吗?
aud:https://www.googleapis.com/oauth2/v4/token,
exp:expDate,
iat:iatDate]


drop.get(access){request
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))
returnsuccess
}



<解决方案范围键缺少值 https://www.googleapis.com /auth/userinfo.email

 让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]

我找到了答案在这里浏览谷歌组织


Swift + Vapor framework for server + Xcode 8.1

I am trying to read Firebase Realtime Database making HTTP requests to my DB, but I get permission denied.

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.

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"
}

解决方案

The scope key was missing value 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]

I found the answer browsing google groups here

这篇关于无法通过HTTP / REST错误403禁止访问FireBase数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆