如何在后端使用 firebase 云函数通过直接函数调用应用身份验证中间件
how to apply authentication middleware with direct function calling using firebase cloud function on backend
我正在使用带有 firebase 云函数的直接函数调用,并希望使用后端服务器的令牌对每个函数进行身份验证
- 不使用像 firebase 这样的 HTTP 端点提供示例函数here
- 像下面这样调用所有函数
`
const functions = require('firebase-functions');
const admin = require('firebase-admin');
exports = module.exports = functions.https.onRequest((req, res) => {
if (req.method !== 'GET') {
return res.status(401).json({
message: 'Method not allowed'
})
}
var db = admin.firestore();
return db.doc('channels/' + req.query.id).get()
.then(snapshot => {
return res.send(snapshot.data())
})
.catch(reason => {
return res.send(reason)
})
});
请告诉我如何使用具有这些类型功能的 auth 中间件,如果方向错误请纠正我
提前致谢
在没有得到回应后,我决定使用 HTTP 请求进行函数调用,因为身份验证非常先进,但仍然热烈欢迎对我的问题提出好的解决方案。
我正在使用带有 firebase 云函数的直接函数调用,并希望使用后端服务器的令牌对每个函数进行身份验证
- 不使用像 firebase 这样的 HTTP 端点提供示例函数here
- 像下面这样调用所有函数
`
const functions = require('firebase-functions');
const admin = require('firebase-admin');
exports = module.exports = functions.https.onRequest((req, res) => {
if (req.method !== 'GET') {
return res.status(401).json({
message: 'Method not allowed'
})
}
var db = admin.firestore();
return db.doc('channels/' + req.query.id).get()
.then(snapshot => {
return res.send(snapshot.data())
})
.catch(reason => {
return res.send(reason)
})
});
请告诉我如何使用具有这些类型功能的 auth 中间件,如果方向错误请纠正我
提前致谢
在没有得到回应后,我决定使用 HTTP 请求进行函数调用,因为身份验证非常先进,但仍然热烈欢迎对我的问题提出好的解决方案。