我想使用 Firebase Admin SDK 来验证 JWT 令牌。我使用 undertow.io 作为我的 HTTP 库。Undertow 创建多个线程来处理连接。
我是否需要创建FirebaseApp或FirebaseAuth对象线程区域设置,或者我可以只执行该方法getInstance并让 SDK 处理它吗?
我正在尝试使用 Firebase Cloud Functions 为我的应用程序创建 REST API。我知道如何在 Cloud Functions 中使用 Admin SDK。它确实有API createUser。我的前端应用程序允许用户使用 Google 和 Facebook 登录,但我不知道如何将它们组合在一起。
我的应用程序已成功实施Sign in with Google,Sign in with Facebook但我如何以及将哪些数据传输到 Cloud Functions(或任何 REST API 服务器),以便它可以在 Firebase 中使用适当的提供商创建用户。
更新以获得更多解释
我正在为 iOS 和 Android 创建一个具有某种基于云的后端的应用程序。现在我正在尝试使用 Firebase,但我不打算将我的应用程序与 Firebase 紧密耦合,因此不想将 Firebase-iOS 和 Firebase-Android SDK 拉入我的应用程序代码中。我希望能够自由地将后端切换到 AWS 或 Azure,而无需更改前端代码。
一种(也是唯一的?)方法是创建一个服务器,该服务器将公开 REST API 端点并代表我完成通常 SDK 所做的工作。为了实现这一目标,我使用了 Cloud Functions,但这并不重要,只要我有 API 可以与实际的云进行通信。
在做出解释之后,现在我的问题是如何让我的用户使用 Google 和 Facebook 等外部提供商登录应用程序,并且仍然实现我想要做的事情。当我让用户通过提供商登录时,我没有将他们的密码发送到后端来创建新的电子邮件/密码用户。
firebase firebase-authentication google-cloud-functions firebase-admin
对于大型项目,使用 firebase admin 从云函数中的集合检索数据失败。我用来查询云函数选择的示例代码如下
admin.database().orderByChild('mmyyyy').equalTo(month).once('value');
Run Code Online (Sandbox Code Playgroud)
当我尝试检索 10600 个项目(试图找出原因)时,此调用失败。在谷歌控制台中有这个日志,但没有其他可以指出我正确的方向
textPayload: "Function execution took 18547 ms, finished with status: 'response error'"
Run Code Online (Sandbox Code Playgroud)
经过多次失败的尝试后,我决定尝试使用 firebase sdk 在客户端上执行此调用,如下所示:
result = await firebase.database().ref(`transactions`).orderByChild('mmyyyy').equalTo(month).once('value');
Run Code Online (Sandbox Code Playgroud)
这在客户端上完美运行,没有错误,并返回我的所有项目,其中 17000 个(该 json 的大小为 26MB)。
为什么会这样呢?是否有任何未记录的限制?
注意:我将云功能内存增加到 1GB,超时时间增加到 5 分钟,但没有帮助。
这是完整的示例代码
admin.database().orderByChild('mmyyyy').equalTo(month).once('value');
Run Code Online (Sandbox Code Playgroud)
firebase firebase-realtime-database google-cloud-functions firebase-admin
我正在尝试在我的 TypeScript (Nest.js) 应用程序中导入 Firebase Admin SDK。
let serviceAccount = require("../../creds.json");
console.log(serviceAccount);
const firebase = require("firebase");
firebase.initializeApp(environment.firebase);
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "projectid"
});
Run Code Online (Sandbox Code Playgroud)
但是当我尝试构建应用程序时,出现以下错误。
ERROR in ./node_modules/@google-cloud/firestore/src/v1beta1/firestore_client.js
Module not found: Error: Can't resolve './firestore_client_config' in '/home/jaybell/trellis-server/trellis/node_modules/@google-cloud/firestore/src/v1beta1'
@ ./node_modules/@google-cloud/firestore/src/v1beta1/firestore_client.js 28:17-53
@ ./node_modules/@google-cloud/firestore/src/v1beta1/index.js
@ ./node_modules/@google-cloud/firestore/src/index.js
@ ./src/server/main.server.ts
ERROR in ./node_modules/google-gax/lib/operations_client.js
Module not found: Error: Can't resolve './operations_client_config' in '/home/jaybell/trellis-server/trellis/node_modules/google-gax/lib'
@ ./node_modules/google-gax/lib/operations_client.js 30:17-54
@ ./node_modules/google-gax/index.js
@ ./node_modules/@google-cloud/firestore/src/v1beta1/index.js
@ ./node_modules/@google-cloud/firestore/src/index.js
@ ./src/server/main.server.ts
ERROR in ./node_modules/google-gax/index.js
Module not found: Error: Can't resolve './package' in '/home/jaybell/trellis-server/trellis/node_modules/google-gax' …Run Code Online (Sandbox Code Playgroud) 我正在初始化我的 firebase 函数,如下所示:
admin.initializeApp(functions.config().firebase)
Run Code Online (Sandbox Code Playgroud)
我已经生成了一个服务帐户密钥,我相信我需要出于身份验证目的来执行此操作。
它给了我一个带有各种键/值的 json 表。
说明是将其添加到 admin.initializeApp 中,如下所示:
var serviceAccount = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
});
Run Code Online (Sandbox Code Playgroud)
这与我的做法非常不同。
我什至不确定我是否需要这样做,因为我确实可以使用以前的方法访问 firestore,但是使用有效用户 id 令牌进行身份验证不起作用,在 firebase 中出现以下错误:
错误:错误:解码 Firebase ID 令牌失败。确保您传递了代表 ID 令牌的整个字符串 JWT。有关如何检索 ID 令牌的详细信息,请参阅 https://firebase.google.com/docs/auth/admin/verify-id-tokens 。
通过嗅探,似乎缺少的是 admin sdk 服务帐户。
我有一个 firebase 云函数,它从云 Firestore 获取数据。
const userSnapshot = await admin.firestore().collection('users').doc(user).get()
Run Code Online (Sandbox Code Playgroud)
当使用firebase emulators:start.
我收到以下错误:
The Cloud Firestore emulator is not running so database operations will fail with a 'default credentials' error.
? Google API requested!
- URL: "https://oauth2.googleapis.com/token"
- Be careful, this may be a production service.
> Auth error:Error: invalid_grant
Run Code Online (Sandbox Code Playgroud)
只有在更新 firebase-tools 后才会发生这种情况。以前使用firebase serve --only function --port=9000. 在此工具版本中,我无法通过命令行设置端口。
如何在 Firebase 云功能中使用 Firebase Admin SDK 为 Firestore 文档创建文档推送 ID。
我知道如何使用 AngularFire2 在 Angular 中做到这一点
const bookingId = this.afs.createId();
Run Code Online (Sandbox Code Playgroud)
我需要在我的云功能中做这件事。
node.js firebase google-cloud-functions firebase-admin google-cloud-firestore
该火力点AUTH文档显示,那么您只能火力地堡验证API第二每个项目的要求高达500个请求/秒每个服务帐户和1000个请求/。
例如,如果我使用 Firebase Auth Admin SDK 来调用getUserByEmail或updateUser,这些操作是否计入 API 限制?
如何使用verifyIdTokenAPI验证 id 令牌?如果我的项目通过验证 authIdToken 来验证从客户端传入服务器的所有请求,这是否意味着我的服务器的扩展阈值上限将为每个项目 1000 个请求/秒,因为服务器的下游服务之一 Firebase Auth 最多只能接受1000 个请求/秒来验证身份验证令牌?
Firebase 文档似乎缺少与这些 API 限制相关的详细信息。
我正在尝试为 FCM 实现服务器以向 android/iOS 设备发送通知。
我需要向 android 和 iOS 发送纯数据通知,但 iOS 的后台通知似乎非常不稳定。(即使该应用程序在前台,我也经常根本没有收到消息。)
当我使用带有 FCM 直接通道的传统 FCM REST 服务器进行测试时,它在 iOS 上运行良好,但这对我来说不是一个选项,因为较新的 Admin SDK 不支持直接通道。
是否有任何理由在较新的 Admin SDK 中取消对 FCM 直接渠道的支持?我看到所有 Firebase 文档都推荐使用 Admin SDK,但不知道为什么他们取消了对直接渠道的支持。
push-notification apple-push-notifications firebase-cloud-messaging firebase-admin
我有带有基于服务帐户的访问权限的节点应用程序,所以我使用了firebase-admin. 正如我之前所看到的,firebase-admin大部分是重复的firebase包(除了身份验证部分、签名和其他一些部分),但现在我想调用函数,但找不到firebase.apps[0].functions().httpsCallable('myFunction'). 我研究了 Typescript 类型,他们甚至没有提到函数。
admin.initializeApp({
credential: admin.credential.cert('./service-account-credentials.json'),
databaseURL: process.env.REACT_APP_FIREBASE_DATABASE_URL,
});
const config = {
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
};
const storageBucket = admin.storage().bucket(config.storageBucket);
const firestore = admin.firestore();
// const functions = admin.apps[0].functions(); // not possible
const functions = firebase.apps[0].functions(); // possible, but Firestore.apps not initialized
Run Code Online (Sandbox Code Playgroud)
我有什么选择?
firebase-admin ×10
firebase ×9
node.js ×3
angular ×1
firebase-cli ×1
java ×1
javascript ×1
jwt ×1
typescript ×1