2016-11-25 44 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