【问题标题】:Firebase Authentication for Realm Cloud using JWT and a Google Cloud Function使用 JWT 和 Google Cloud 函数对 Realm Cloud 进行 Firebase 身份验证
【发布时间】:2019-08-04 21:39:45
【问题描述】:

我正在尝试使用 JWT 对 Realm Cloud 进行身份验证。我使用 Firebase 作为身份验证服务,并尝试创建一个 Google Cloud Function 来生成 JWT。我使用终端命令“ssh-keygen”生成了私钥和公钥。 Realm 的 JWT 教程建议使用以下代码行来读取密钥文件:

const key = fs.readFileSync('./functions/id_rsa', 'utf8'); 

我将私钥复制到项目中,将上面的代码指向文件,但是当我部署 Google Cloud Function 时,收到以下错误消息:

⚠ 函数[myAuthFunction(us-central1)]:部署错误。功能 加载用户代码失败。错误消息:文件 index.js 中的代码 无法加载。您的代码中是否存在语法错误?详细堆栈 跟踪:错误:ENOENT:没有这样的文件或目录,打开 './functions/id_rsa'

我的项目结构如下: Picture

我曾尝试在 Realm 的论坛上提问,但没有得到太多帮助。他们建议的整个云功能是:

const functions = require("firebase-functions");
const jwt = require('jsonwebtoken');
const fs = require('fs');
const key = fs.readFileSync(’pathToMyPrivateKeyFile');
exports.myAuthFunction = functions.https.onCall((data, context) => {    
    const uid = context.auth.uid 
    const payload = { userId: uid }    
    const token = jwt.sign(payload, { key: key, passphrase: "your-passphrase" }, { algorithm: 'RS256'}),    
    return { token:token }
});

综上,谷歌云功能如何读取我项目中的私钥文件?公钥存储在我的 Realm Cloud 仪表板中,用于特定实例。

来源: Realm Cloud JWT Firebase tutorial

【问题讨论】:

    标签: firebase firebase-authentication realm google-cloud-functions realm-cloud


    【解决方案1】:

    尝试只传递./id_rsaid_rsa。我相信路径根目录是 index.js 文件所在的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-30
      • 2021-04-10
      • 2018-07-23
      • 1970-01-01
      • 2018-12-29
      • 2020-01-24
      • 2020-07-22
      • 2020-01-16
      相关资源
      最近更新 更多