标签: firebase-admin

firebase admin SDK创建用户并发送验证邮件

在使用firebase admin SDK创建用户后,如何发送验证电子邮件?我想要结合起来createUser function,sendEmailVerification function 有人可以指出一个暗示或答案吗?谢谢

更新:

用户创建由已在应用程序中登录的管理员用户完成,因此管理员用户只是在仪表板上创建用户.这与注册方法完全不同.

更新2:

我试图按照bojeil的回答,我仍然坚持用户使用自定义令牌登录的步骤.它与我当前的管理员用户会话发生冲突,管理员用户被踢出,而新用户已登录,即使我退出新用户,管理员用户仍然不在,需要登录才能重新登录该应用程序.

获取自定义令牌后,这是我在应用程序中的代码:

$http.post('/.custom-token', {uid: $scope.data.data.uid})
        .then(function (response) {
            console.log("custom token here:", response.data.token);
            firebase.auth().signInWithCustomToken(response.data.token)
                .then(function (firebaseUser) {
                    firebaseUser.sendEmailVerification();
                    firebase.auth().signOut().then(function() {
                        // Sign-out successful.
                        console.log("signed out success");
                    }, function(error) {
                        // An error happened.
                    });
                })

                .catch(function(error) {
                    // Handle Errors here.
                    var errorCode = error.code;
                    var errorMessage = error.message;
                    // ...
                });

        });
Run Code Online (Sandbox Code Playgroud)

所以,我获得令牌,登录新用户,发送电子邮件验证链接,然后注销新用户.但我正在执行此操作的管理员用户也会退出.我在这里想念的是什么?

angularjs firebase firebase-authentication firebase-admin

9
推荐指数
2
解决办法
4726
查看次数

Firestore 查询 endBefore 和 endAt 未按预期工作

我使用的是 Node 10、firebase 8.0、firebase-admin 9.3.0。我已经包含了我的测试代码和客户端 js 版本的副本。

数据

Document ID | name | is_visible
----------- | ---- | ----------
     1      |   a  | true
     2      |   b  | true
     3      |   c  | true
     4      |   d  | true
     5      |   e  | true
     6      |   f  | true
     7      |   g  | true
     8      |   h  | true
     9      |   i  | true
Run Code Online (Sandbox Code Playgroud)

代码

var admin = require("firebase-admin");

const firebaseConfig = {xxx}

admin.initializeApp({
    credential: admin.credential.cert(firebaseConfig)
  });

const getDocs = …
Run Code Online (Sandbox Code Playgroud)

node.js firebase-admin google-cloud-firestore

9
推荐指数
1
解决办法
3460
查看次数

Docker 在 AWS Beanstalk 上为 Python 应用程序构建超时

我有一个在 AWS Beanstalk 上运行的 Python2/Django 应用程序。我使用 Dockerfile 进行部署。一切都工作正常,直到我将firebase-admin==3.2.1依赖项添加到我的requirements.txt. 发生的情况是 Docker 映像构建时间比平时更长,并且 Beanstalk 构建过程开始失败。经过更多分析,我注意到子依赖项需要很长时间才能安装grpcio==1.31.0。Firebase lib 使用它与 Google API 进行通信。

我尝试将命令超时设置增加到 20 分钟或更长,但没有任何改变。EB部署过程消耗了整个时间间隔并最终失败。我尝试进入 EC2 实例本身以查找任何可以调整的有用内容,但一无所获。

eb-engine.log我相信这是解释错误部分的示例。

  Stored in directory: /root/.cache/pip/wheels/6f/8e/a7/c5ce8f1742b7d2b9e07cd1064cf201293d157c3c4e1021a74a
  Running setup.py bdist_wheel for psutil: started
  Running setup.py bdist_wheel for psutil: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/39/a0/f5/c4fa280463e29aea07797acb5312358fefb067c1f4f98e11b1
  Running setup.py bdist_wheel for Pyphen: started
  Running setup.py bdist_wheel for Pyphen: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/78/e3/76/42853bf2f7573a72fb5fe377a8406c979a5479ad6930506cde
  Running setup.py bdist_wheel for cairocffi: …
Run Code Online (Sandbox Code Playgroud)

python-2.7 docker amazon-elastic-beanstalk dockerfile firebase-admin

9
推荐指数
0
解决办法
1114
查看次数

Firebase管理员NoClassDefFoundError:FirebaseOptions $ Builder

我正在使用这个:

FileInputStream serviceAccount;
    try {
        serviceAccount = new FileInputStream("firebase_key.json");
    } catch (FileNotFoundException e) {
        System.out.println(e.getMessage());
        return;
    }
    System.out.println("Reached here!");

    FirebaseOptions options = new FirebaseOptions.Builder()
            .setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
            .setDatabaseUrl("https://*.firebaseio.com/")
            .build();

    FirebaseApp.initializeApp(options);
Run Code Online (Sandbox Code Playgroud)

但是,应用程序崩溃了 java.lang.NoClassDefFoundError for FirebaseOptions$Builder

我的build.gradle:

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile 'com.google.firebase:firebase-admin:4.1.1'
}
Run Code Online (Sandbox Code Playgroud)

我正在使用IntelliJ.

logcat的:

    Exception in thread "main" java.lang.NoClassDefFoundError: com/google/firebase/FirebaseOptions$Builder
10:57:43 AM web.1 |     at com.x.*.TokenGenerator.main(TokenGenerator.java:26)
10:57:43 AM web.1 |  Caused by: java.lang.ClassNotFoundException: com.google.firebase.FirebaseOptions$Builder
10:57:43 AM web.1 |     at java.net.URLClassLoader.findClass(Unknown Source)
10:57:43 AM web.1 | …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-authentication firebase-admin

8
推荐指数
1
解决办法
819
查看次数

使用node.js admin sdk创建令牌时,Firebase REST验证

我知道这个问题在这里被问了很多,但我似乎无法找到可以解决我问题的确切答案.

我希望通过添加access_token参数来使用REST调用访问Firebase.

使用Node.js Admin SDK创建access_token,使用以下代码:

var admin = require("firebase-admin");

var serviceAccount = require("./pk.json");

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://XXX.firebaseio.com"
});

var uid = "1234";


admin.auth().createCustomToken(uid)
  .then(function(customToken) {
    // Send token back to client
    console.log("Token: "+customToken);
  })
  .catch(function(error) {
    console.log("Error creating custom token:", error);
  });
Run Code Online (Sandbox Code Playgroud)

问题是,如果我从Node.js创建令牌并将其用于我的REST调用,则会Unauthorized request出现错误.

我已经读过一些问题,人们在发布令牌时添加了范围参数,但是没有找到使用Node.js Admin SDK的方法.

谷歌的文档并没有详细解释这个问题.知道我可能尝试解决这个问题吗?

oauth node.js firebase firebase-authentication firebase-admin

8
推荐指数
1
解决办法
4704
查看次数

角度通用| firebase-admin | 代码:'app/invalid-credential'|套接字挂断

import * as admin from 'firebase-admin';
var serviceAccount = require('./keys/keyfile.json');
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://test.firebaseio.com"
});

var registrationToken = "--some-key--";

var payload = {
  notification: {
    title: "$GOOG up 1.43% on the day",
    body: "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day."
  },
  data: {
    stock: "GOOG",
    open: "829.62",
    close: "635.67"
  }
};


function panelMessage(){
admin.messaging().sendToDevice(registrationToken, payload)
  .then(function(response) {
    // See the MessagingDevicesResponse reference documentation for
    // the contents of response.
    console.log("Successfully sent message:", response); …
Run Code Online (Sandbox Code Playgroud)

node.js angular-universal firebase-admin angular

8
推荐指数
1
解决办法
296
查看次数

从使用 firebase-admin 上传的文件中获取公共 URL

我使用 firebase-admin 和 firebase-functions 在 Firebase 存储中上传文件。

我在存储中有这个规则:

service firebase.storage {
  match /b/{bucket}/o {
    match /images {
      allow read;
      allow write: if false;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我想使用以下代码获取公共 URL:

const config = functions.config().firebase;
const firebase = admin.initializeApp(config);
const bucketRef = firebase.storage();

server.post('/upload', async (req, res) => {

  // UPLOAD FILE

  await stream.on('finish', async () => {
        const fileUrl = bucketRef
          .child(`images/${fileName}`)
          .getDownloadUrl()
          .getResult();
        return res.status(200).send(fileUrl);
      });
});
Run Code Online (Sandbox Code Playgroud)

但我有这个错误.child is not a function。如何使用 firebase-admin 获取文件的公共 url?

google-cloud-storage firebase firebase-storage firebase-admin

8
推荐指数
2
解决办法
2万
查看次数

Firebase Cloud功能:无法从文件读取凭据

由于新的Firebase Cloud Functions(版本> 1.0)。我只需要打电话

admin.initializeApp();
Run Code Online (Sandbox Code Playgroud)

没有任何参数。

但是,当我这样做时,然后运行firebase deploy --only函数,就会发生此错误:

无法从文件G:\ projects \ ANOTHER_PROJECT \ ANOTHER_PROJECT.json中读取凭据:错误:ENOENT:没有此类文件或目录,请打开“ G:\ projects \ ANOTHER_PROJECT \ ANOTHER_PROJECT.json”

firebase google-cloud-functions firebase-admin

8
推荐指数
2
解决办法
828
查看次数

如何为上传到 firebase 存储的文件生成访问令牌?

我可以使用 firebase-admin 通过 nodejs 将文件上传到我的 firebase 存储桶,但是当我转到 firebase UI 时,我无法打开该文件。我注意到通过 firebase UI 上传的文件会自动生成一个访问令牌,但没有通过 nodejs 上传的文件。

我已经尝试了几种方法,例如使用下载令牌设置元数据并在上传文件后公开文件。没有一个奏效。

如何通过 API 调用生成访问令牌,而不必为每个上传的文件点击生成令牌?

node.js firebase firebase-storage firebase-admin

8
推荐指数
3
解决办法
6148
查看次数

Firebase admin SDK FCM 错误 需要主题、令牌或条件之一

我正在修复发生的错误消息,但它以前也可以使用。我正在发送带有多个令牌的 FCM 通知并收到以下错误

0|api      | 2020-2-11 13:26:26   [ExceptionsHandler] Exactly one of topic, token or condition is required
0|api      |  +542752ms
0|api      | Error: Exactly one of topic, token or condition is required
0|api      |     at FirebaseMessagingError.FirebaseError [as constructor] (/var/www/tokee-api-new/node_modules/firebase-admin/lib/utils/error.js:42:28)
0|api      |     at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/var/www/tokee-api-new/node_modules/firebase-admin/lib/utils/error.js:88:28)
0|api      |     at new FirebaseMessagingError (/var/www/tokee-api-new/node_modules/firebase-admin/lib/utils/error.js:254:16)        0|api      |     at Object.validateMessage (/var/www/tokee-api-new/node_modules/firebase-admin/lib/messaging/messaging-types.js:46:15)
0|api      |     at /var/www/tokee-api-new/node_modules/firebase-admin/lib/messaging/messaging.js:265:31
0|api      |     at Array.map (<anonymous>)
0|api      |     at Messaging.sendAll (/var/www/tokee-api-new/node_modules/firebase-admin/lib/messaging/messaging.js:264:29)
0|api      |     at Messaging.sendMulticast (/var/www/tokee-api-new/node_modules/firebase-admin/lib/messaging/messaging.js:313:21)   0|api      |     at userChunks.forEach.userChunk …
Run Code Online (Sandbox Code Playgroud)

javascript node.js firebase firebase-cloud-messaging firebase-admin

8
推荐指数
2
解决办法
7645
查看次数