我正在使用 firebase-functions-test对我的云功能进行单元测试。测试配置为运行离线测试,但在访问测试 firestore 时,我仍然收到身份验证错误:无法解析刷新 token 文件:错误:刷新 token 必须包含“client_secret”属性。
。什么会导致这种情况?
最佳答案
深入挖掘firebase-functions-test
和firebase-admin
的代码后,在为离线模式初始化firebase-functions-test
时, 它仍然使用 gcloud application default credentials .如果您曾经安装和使用过 gcloud,它位于 ~/.config/gcloud/application_default_credentials.json
中。
我在 GCP 上的一个旧项目中有一个设置,该项目是作为服务帐户而不是经过身份验证的用户登录的,因此我有默认的凭据设置,但它不包含所需的 client_secret
通过 firebase-admin
。我只是使用 gcloud auth application-default login
登录应用程序默认值。这解决了问题。
仍然对离线 模式需要身份验证这一事实感到困惑。我没有使用无效但格式正确的应用程序默认凭据进行测试。
关于firebase - 使用 firebase-functions-test 运行离线测试时缺少 `client_secret`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53181510/