node.js - 从 Firebase Cloud Functions 访问 Auth
问题描述
我无法从 Firebase Cloud Functions 环境访问用户信息。
我正在尝试做的事情。
const admin = require('firebase-admin')
admin.initializeApp()
exports.test = functions.https.onRequest(() => {
admin.auth().getUser('<user_id>').then(user => {
return console.log(user)
}).catch(e => {
console.error(e)
})
})
现在,当我运行该test
函数时,出现以下错误。
{ code: 'auth/insufficient-permission',
message: 'Credential implementation provided to initializeApp() via the "credential" property has insufficient permission to access the requested resource. See https://firebase.google.com/docs/admin/setup for details on how to authenticate this SDK with appropriate permissions.' },
codePrefix: 'auth' }
现在,我的问题是,是否可以admin.auth().getUser
从云功能环境中使用。
解决方案
您需要将凭证文件传递给 admin sdk 初始化函数。认证相关任务需要在云功能中进行此配置。
转到 Firebase控制台 -> 设置 -> 项目设置 -> 服务帐户 -> 生成新的私钥。
下载文件并包含在您的代码中。
PS:确保此文件不以任何形式向公众共享(将其添加到 git ignore),因为拥有此文件可以完全访问您的 firebase 项目。
推荐阅读
- sas - 如何在 sas 中创建一个表来查看列变量相对于另一个的计数?
- python - 在 DRF 上 POST 没有正文
- angular - 角垫滑动切换中的多个标签
- c - Valgrind 在函数中使用 strncpy 时报告无效的读取大小为 1
- python - PyPi 包应用程序运行而不是使用 runserver 命令克隆的 repo
- d3.js - fork D3 v5 Zoomable Sunburst 坏了
- c++ - 具有 C++ 17 的 gcc 9.3 上的结构成员的特征运行时对齐断言
- javascript - 如何在 Angular 8 应用程序中使用香草 JS 签名板?
- javascript - Javascript将多个html表导出到一个excel文件
- javascript - 了解 webNavigation.onHistoryStateUpdated() 行为