2016-11-25 42 views
10

服务器+的Xcode 8.1无法通过禁止

我想读火力地堡实时数据库的HTTP请求到我的DB斯威夫特+蒸汽框架HTTP/REST错误403访问火力数据库,但我得到许可被拒绝。

这些步骤如下:
1.创建智威汤逊与“console.developers.google.com”
2.发送POST请求到OAuth2服务器并获得访问令牌
3.发送下载的密钥签名使用从OAuth2服务器接收的访问令牌向Firebase数据库发出GET请求。

我收到拒绝 “权限”,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":"[email protected]", 
"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" 
} 

​​ FireBase Database Rulles

+0

@frank面包车puffelen能否请你摆脱你的意见,为什么我不能进入我火力地堡数据库? – bibscy

回答

3

scope关键是缺少值https://www.googleapis.com/auth/userinfo.email

let jwtClaimSet = 
    ["iss":"[email protected]", 
"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] 

我找到了答案browsing google groups here

+0

它的工作,谢谢 –

0
headers: ["Authorization":"Authorization: Bearer \(accesstoken)"], 

应该

headers: ["Authorization":"Bearer \(accesstoken)"], 
+0

我仍然收到错误:Permission Denied – bibscy

+0

你可以尝试解开accesstoken? 'header:[“Authorization”:“Bearer \(accesstoken!)”],也打印出你的标题并发布它看起来像 –

+0

我不能强制展开'accesstoken',因为它不是可选的。 FirebaseResponse_is响应 ' - HTTP/1。1个403禁止 - 接头: \t连接:保持活跃 \t缓存控制:无缓存 \t服务器:nginx \t日期:星期五,2016年11月25日17时55分零零秒GMT \t内容类型:应用程序/ JSON; charset = utf-8 \t内容长度:37 \t Strict-Transport-Security:max-age = 31556926; includeSubDomains;预加载 \t访问控制允许来源:* - 正文: \t { “错误”:“权限被拒绝”。 }' – bibscy

4

TLDR;尝试将auth=<TOKEN>置于查询字符串中,而不是使用授权标头。


Firebase文档不清楚这是如何工作的。根据文件,有三种方法应该工作。

  1. 在查询字符串auth=<TOKEN>link
  2. 在查询字符串( link)在请求头
  3. Authorization: Bearer <TOKEN>link

我不相信所有的三种方法实际上做

  • access_token=<TOKEN>然而,工作。我在我的应用程序中使用了方法1,所以我知道这是可以肯定的。

  • +0

    如果我做了'headers:[:],query:[“auth”:“ya29.E ... XXXX”])'我得到了400个错误的请求。如果我做'header:[:],query:[“access_token”:“ya29.ElqiA”])'我得到403 Forbidden。如果我做'header:[“Authorization”:“Bearer \(accesstoken)”],query:[:])',我得到403 Forbidden – bibscy

    +0

    我也试过'curl https://fir-30c9e.firebaseio.com/ data/Users.json?access_token = ya29.ElqiAz4TSV-FXkKpXOE636vk__pWx8y5pqZ5QYW .....等等,我得到“错误”:“权限被拒绝”。 – bibscy

    +0

    我不确定。如果卷曲甚至不起作用,也许您的令牌无效?如果您正在使用硬编码的accesstoken,它可能已过期。 – nloewen