2
按照google docs中關於在GAE中使用Firebase進行身份驗證的指示,我正在從Android向我的後端python服務器發送授權令牌。驗證Firebase身份驗證令牌權限被拒絕
import google.auth.transport.requests
import google.oauth2.id_token
HTTP_REQUEST = google.auth.transport.requests.Request()
id_token = headers['authorization'].split(' ').pop()
user_info = google.oauth2.id_token.verify_firebase_token(
id_token, HTTP_REQUEST)
導致以下堆棧跟蹤:
File "/Users/alex/projects/don/don_server/mobile/main.py", line 61, in get_video
user_id = get_user_id(self.request_state.headers)
File "/Users/alex/projects/don/don_server/mobile/main.py", line 37, in get_user_id
id_token, HTTP_REQUEST)
File "/Users/alex/projects/don/don_server/mobile/lib/google/oauth2/id_token.py", line 115, in verify_firebase_token
id_token, request, audience=audience, certs_url=_GOOGLE_APIS_CERTS_URL)
File "/Users/alex/projects/don/don_server/mobile/lib/google/oauth2/id_token.py", line 76, in verify_token
certs = _fetch_certs(request, certs_url)
File "/Users/alex/projects/don/don_server/mobile/lib/google/oauth2/id_token.py", line 50, in _fetch_certs
response = request(certs_url, method='GET')
File "/Users/alex/projects/don/don_server/mobile/lib/google/auth/transport/requests.py", line 111, in __call__
raise exceptions.TransportError(exc)
TransportError: ('Connection aborted.', error(13, 'Permission denied'))
我仔細檢查過我的火力點項目設置和localhost
被列爲認證標誌授權域使用下面的代碼讀取令牌(我正在GAE本地開發服務器上運行此操作)。
至於我記得這是工作幾個星期前。有任何想法嗎?
UPDATE:
我實現了使用服務帳戶相同的身份驗證作爲firebase docs建議,但我得到同樣的錯誤信息:
from firebase_admin import auth, credentials
import firebase_admin
fpath = os.path.join(os.path.dirname(__file__), 'shared', 'firebase-admin-private-key.json')
cred = credentials.Certificate(fpath)
firebase_admin.initialize_app(cred)
然後處理傳入的令牌
id_token = headers['authorization'].split(' ').pop()
user_info = auth.verify_id_token(id_token)