Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Firebase本地仿真器时,如何对云函数进行身份验证?_Firebase_Firebase Authentication_Google Cloud Functions - Fatal编程技术网

使用Firebase本地仿真器时,如何对云函数进行身份验证?

使用Firebase本地仿真器时,如何对云函数进行身份验证?,firebase,firebase-authentication,google-cloud-functions,Firebase,Firebase Authentication,Google Cloud Functions,我正在尝试设置firebase本地模拟器,以便能够测试云功能。但我要么在主函数外得到“Error:Unauthenticated”响应,要么在主函数内得到auth错误,这取决于我是否尝试使用客户端SDK进行身份验证。云函数如下所示: 导出默认函数.https.onCall(异步(数据,上下文)=>{ console.log(context.auth) //依赖context.auth的自定义函数代码和身份验证检查 } 人们试图这样称呼它: wait firebase.initializeApp

我正在尝试设置firebase本地模拟器,以便能够测试云功能。但我要么在主函数外得到“Error:Unauthenticated”响应,要么在主函数内得到auth错误,这取决于我是否尝试使用客户端SDK进行身份验证。云函数如下所示:

导出默认函数.https.onCall(异步(数据,上下文)=>{
console.log(context.auth)
//依赖context.auth的自定义函数代码和身份验证检查
}
人们试图这样称呼它:

wait firebase.initializeApp({
apiKey:FIREBASE_API_密钥,
authDomain:FIREBASE\u AUTH\u域,
databaseURL:FIREBASE\u数据库\u URL,
projectId:FIREBASE_项目ID,
storageBucket:FIREBASE_STORAGE_BUCKET,
messagingSenderId:FIREBASE\u消息\u发件人\u ID
})
等待firebase.functions().useFunctionsEmulator('http://localhost:5001')
//等待firebase.auth().createUserWithEmailAndPassword(电子邮件,密码)
//let res=wait firebase.auth().使用email和password(电子邮件,密码)登录
const result=await firebase.functions().httpscalable('myFunction')(数据)
如果我这样运行它,我可以看到云函数中的日志显示上下文参数没有auth值。如果我取消对用户登录内容的注释,我会得到一个错误:未经验证的响应,函数本身永远不会运行


是否有一些配置方面的东西我没有?我还没有找到很多关于使用模拟器的文档。

在深入研究实际的SDK之后,我设法找到了它。我使用了一个错误的API密钥,这意味着生成的令牌是错误的。正确的方法是创建用户并以用户身份登录,然后再进行配置调用。

您使用的firebase工具的版本是什么?7.1.0。我也使用节点8和节点10尝试过,没有区别。