我使用 Lambda 到 Firebase 消息。我参考这个。但 lambda 函数仍然超时,因为它无法连接到谷歌服务器。
处理程序.js
/ [START imports]
const firebase = require('firebase-admin');
const serviceAccount = require("../serviceAccount.json");
module.exports.message = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
const registrationToken = "xxxxxxx";
const payload = {
data: {
score: "850",
time: "2:45"
}
};
// [START initialize]
if(firebase.apps.length == 0) { // <---Important!!! In lambda, it will cause double initialization.
firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount),
databaseURL: 'https://messaging-xxxxx.firebaseio.com'
});
}
// Send a message to the device corresponding to the …Run Code Online (Sandbox Code Playgroud) amazon-web-services firebase aws-lambda firebase-cloud-messaging firebase-admin
我正在尝试使用 python 的 firebase admin sdk 来制作自定义令牌并在测试我的应用程序时验证这些令牌。问题是,当我尝试验证令牌时,我总是收到这样的错误:
ValueError: Firebase ID token has incorrect "aud" (audience) claim. Expected "my_project_id" but got "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit". Make sure the ID token comes from the same Firebase project as the service account used to authenticate this SDK. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.
Run Code Online (Sandbox Code Playgroud)
我按照指南创建应用程序并制作令牌:
import firebase_admin
from firebase_admin import auth, credentials
cred = credentials.Certificate('/path/to/file.json')
app = firebase_admin.initialize(cred)
custom_token = auth.create_custom_token('some-uid', app=app)
auth.verify_id_token(custom_token, app=app)
Run Code Online (Sandbox Code Playgroud)
在这里我得到了错误。_TokenGenarator 似乎是使用从错误中返回的默认值进行初始化的。我认为在传递应用程序时它应该自动更改这些内容,但它没有发生。我错过了什么吗?
我正在尝试在 Raspberry pi 上运行 python3 中的 firebase admin SDK,但它不起作用。
我运行(在控制台中)
sudo pip install firebase-admin
Run Code Online (Sandbox Code Playgroud)
安装然后尝试使用(在IDSL中)
import firebase_admin
Run Code Online (Sandbox Code Playgroud)
在 Python 3 中,但我收到“找不到模块”错误。我可能会缺少什么?这是在旧 Pi 上全新安装 Raspbian 时的情况。
有一种方法可以在firebase-admin python sdk中添加服务器时间戳吗?我尝试:
firestore.SERVER_TIMESTAMP
firestore.constants.SERVER_TIMESTAMP
Run Code Online (Sandbox Code Playgroud)
但是,我得到这个例外:
TypeError: ('Cannot convert to a Firestore Value', <object object at 0x10380fc20>, 'Invalid type', <class 'object'>)
Run Code Online (Sandbox Code Playgroud) 我想知道如何在 Node.js SDK Firebase 中获取访问令牌和 id 令牌。当我在signUpWithEmailAndPassword之后打印用户对象时,我看到accessToken是那里的属性之一,但是当我在用户对象上使用名为getIdToken的方法时,我得到了与在用户对象中看到的相同的令牌。那为什么不叫 getAccessToken 呢???我想要的是返回包含访问、id、刷新令牌和过期时间的客户端对象。PS 我不能只说 user.stsTokenManager.accessToken 因为它告诉我还没有这样的属性。
node.js oauth-2.0 firebase firebase-authentication firebase-admin
我正在尝试在 pom.xml 中添加 firebase-admin 依赖项:
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.6.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用“干净安装”命令构建我的项目时,出现以下错误:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Communication Manager 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Downloading: http://192.168.1.4:8081/artifactory/libs-release/com/google/firebase/firebase-admin/6.6.0/firebase-admin-6.6.0.pom
[INFO] Downloaded: http://192.168.1.4:8081/artifactory/libs-release/com/google/firebase/firebase-admin/6.6.0/firebase-admin-6.6.0.pom (21 KB at 44.6 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.498 s
[INFO] Finished at: 2019-01-02T11:43:59+05:30
[INFO] Final Memory: 14M/308M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project communicationmgr: Could not resolve dependencies for project com.example.server:communicationmgr:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.google.firebase:firebase-admin:jar:6.6.0 -> …Run Code Online (Sandbox Code Playgroud) 我需要在我的 AWS Lambda 项目中使用 Firebase Admin Java,但是SocketTimeoutException当Firebase Auth Admin尝试在 Google 的服务器中获取公钥时会抛出一个。我知道 Firebase Admin 配置正确,因为我可以在 Tomcat 实例中本地运行它而无需担心。
然后我尝试向像 一样的测试 API 发出 HTTPS 请求https://postman-echo.com/get?foo1=bar1&foo2=bar2,并且它具有相同的行为,我也收到超时,这让我认为这是 Lambda 调用 HTTPS 请求的问题。
现在我所知道的:
为了完整起见,我将把SocketTimeoutException我从 Firebase Admin Java 中获得的内容留在这里,尽管我不确定这是 Firebase Admin 库中的问题还是 AWS Lambda + HTTPS 的问题,或者两者兼而有之:
[main] ERROR com.example.project.filters.FirebaseAuthenticationFilter - 解析或验证令牌 com.google.firebase.auth.FirebaseAuthException 时出错:验证签名时出错。在 com.google.firebase.auth.FirebaseTokenVerifierImpl.checkSignature(FirebaseTokenVerifierImpl.java:160) …
java aws-lambda firebase-authentication aws-api-gateway firebase-admin
使用 Firebase Storage 存储图像时,图像的 URL 如下所示: https ]?alt=media&token=[令牌]
我想得到这个网址。
根据this、this、this和this,我需要使用该.getDownloadURL()方法,该方法位于“存储引用”..但可用对象的文档与实际对象不符。
当我尝试访问.getDownloadURL()下面代码中文档建议的对象上的方法时,我收到了各种未找到属性的错误。
const admin = require('firebase-admin');
admin.initializeApp();
admin
.storage()
.bucket()
.upload(imageToBeUploaded.filepath, {
destination: storageFolder,
resumable: false,
metadata: {
metadata: {
contentType: imageToBeUploaded.mimetype
}
}
})
.then((taskSnapshot) => {
// HOW DO I GET THE DOWNLOADABLE URL
})
Run Code Online (Sandbox Code Playgroud)
我试过以下:
taskSnapshot[1].getDownloadURL(),
admin.storage().ref(storageFolder+'/'+imageFileName).getDownloadURL(),
admin.storageRef(storageFolder+'/'+imageFileName).getDownloadURL(),
admin.storage().ref().child(storageFolder+'/'+imageFileName).getDownloadURL(),
.. 和一堆其他人。
反复试验没有找到具有该方法的“storageRef”,
firebase google-cloud-functions firebase-storage firebase-admin
我正在尝试在托管中安装我的 node.js 服务器。在 Windows 上运行但在托管中无法运行的服务器。
运行 NPM 安装错误
An error occured during installation of modules. The operation was performed, but check availability of application has failed. Web application responds, but its return code "500 Internal Server Error" or content type before operation "text/html; charset=UTF-8" doesn't equal to contet type after operation "text/html; charset=UTF-8".
Run Code Online (Sandbox Code Playgroud)
启动服务器错误
Error: error:02016002:system library:stat:No such file or directory
at Sign.sign (internal/crypto/sig.js:86:29)
at Object.sign (/home/maksoboi/nodevenv/score/12/lib/node_modules/jsonwebtoken/node_modules/jwa/index.js:152:45)
at Object.jwsSign [as sign] (/home/maksoboi/nodevenv/score/12/lib/node_modules/jsonwebtoken/node_modules/jws/lib/sign-stream.js:32:24)
at Object.module.exports [as sign] (/home/maksoboi/nodevenv/score/12/lib/node_modules/jsonwebtoken/sign.js:186:16)
at ServiceAccountCredential.createAuthJwt_ (/home/maksoboi/nodevenv/score/12/lib/node_modules/firebase-admin/lib/auth/credential.js:101:20) …Run Code Online (Sandbox Code Playgroud) 由于 Deno 几天前刚刚发布了稳定版本,有没有可能的方法在 Deno 中使用 firebase-admin?
firebase-admin ×10
firebase ×8
aws-lambda ×2
node.js ×2
deno ×1
hosting ×1
java ×1
javascript ×1
linux ×1
oauth-2.0 ×1
python ×1
python-3.x ×1
raspbian ×1