【发布时间】:2018-11-03 05:44:59
【问题描述】:
我目前正在使用 Firebase Functions v1.0.3 和 Firebase Admin v5.12.1。 express NodeJS 库似乎运行良好。
问题
但是,当我尝试通过发送授权标头来保护请求时:
Authorization: Bearer <token>
它没有显示我的令牌的任何日志。当我在 Firebase Functions index.js 文件中使用 console.log(request) 来获取 token 时,我看不到任何与 Bearer 或 Authorization Bearer 匹配的单词。
当我使用console.log 时,我从req.headers 得到以下信息:
{ 'content-length': '0',
'accept-language': 'en-US,en;q=0.9',
'accept-encoding': 'gzip, deflate, br',
referer: 'http://localhost:5000/admin/',
accept: '*/*',
'access-control-request-headers': 'authorization,content-type',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36',
origin: 'http://localhost:5000',
'access-control-request-method': 'GET',
connection: 'close',
host: 'localhost:5001'
}
文档来源
我已阅读有关 Firebase Functions Samples: Authorized HTTPS Endpoint 示例代码的文档,其中一些似乎已过时。
firebase.auth().currentUser.getToken()
例如现在是:
firebase.auth().currentUser.getIdToken()
其他库
我尝试安装了express-authorization-bearer 和express-bearer-token 等库,但仍然无法捕获idToken。
我想知道这是 NodeJS 问题还是 Firebase Functions 问题。我目前正在使用 NodeJS v6.11.4
问题
如何使用 Express 或任何使用 NodeJS 的方法在 Firebase Functions 中捕获令牌?
【问题讨论】:
标签: node.js firebase http-headers firebase-authentication google-cloud-functions