标签: firebase-admin

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 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 admin sdk列出所有用户

有没有办法列出使用firebase admin sdk的所有用户?文档仅显示通过uid或电子邮件获取一个用户.

firebase firebase-authentication firebase-admin

7
推荐指数
3
解决办法
7458
查看次数

Firebase Admin Nodejs找不到模块service_account.json

我用"node firebasedb.js"启动我的节点.我的firebasedb.js包含以下代码:

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

var serviceAccount = require("service_account.json");

// Initialize Firebase
var config = {
    credential: admin.credential.cert(serviceAccount),
    apiKey: "<api key>",
    authDomain: "<auth domain>",
    databaseURL: "<database url>",
    storageBucket: "<storage bucket>",
};

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

当我运行节点时,我在.json文件所在的目录中.但它说

Error: Cannot find module 'service_account.json'
Run Code Online (Sandbox Code Playgroud)

service node.js firebase firebase-admin

7
推荐指数
1
解决办法
5405
查看次数

有没有办法从客户端应用程序中调用Firebase服务器"功能",比如使用Angular 2?

因此,Firebase提供了一种称为"功能"的功能,它本质上是一个nodejs服务器,它具有预先配置的所有Firebase内容,并自动处理所有缩放.我想知道,有没有办法从角度2应用程序调用"函数"index.js文件中的函数?

我需要利用firebase-admin npm模块检查用户的电子邮件是否存在,然后获取该用户的uid(如果有).

根据此链接,我可以设置我的index.js文件,例如:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

// I'm actually not sure if this is how you do this part:
exports.getUserByEmail = (email) => {
  return admin.auth().getUserByEmail(email);
}
Run Code Online (Sandbox Code Playgroud)

有没有办法getUserByEmail()在Angular 2应用程序中调用组件内部?

提前致谢!

firebase google-cloud-functions firebase-admin angular

7
推荐指数
1
解决办法
6880
查看次数

如何使用firestore admin nodejs sdk设置服务器时间戳?

const firebase = require('@firebase/app').default;
require('@firebase/firestore')

const admin = require('firebase-admin')
const functions = require('firebase-functions')

// initialize the admin SDK...    

exports.setUpdatedDate = functions.firestore.document('/foos/{fooId}/bars/{barId}')
    .onCreate(event => {
      admin.firestore().collection('foos').doc( event.params.fooId )
            .set({
                updatedDate: firebase.firestore.FieldValue.serverTimestamp()
            }, {merge:true})
    })
Run Code Online (Sandbox Code Playgroud)

运行上面的函数shell,我得到:

Cannot encode type ([object Object]) to a Firestore Value
at Function.encodeValue (...\functions\node_modules\@google-cloud\firestore\src\document.js:772:11
Run Code Online (Sandbox Code Playgroud)

那么如何使用firestore admin nodejs sdk设置服务器时间戳?

node.js firebase google-cloud-functions firebase-admin google-cloud-firestore

7
推荐指数
1
解决办法
3095
查看次数

Firestore向数组字段添加值

我试图使用Firebase云功能将聊天室的ID添加到数组字段中的用户文档.我似乎无法弄清楚写入数组字段类型的方法.这是我的云功能

  exports.updateMessages = functions.firestore.document('messages/{messageId}/conversation/{msgkey}').onCreate( (event) => {
    console.log('function started');
    const messagePayload = event.data.data();
    const userA = messagePayload.userA;
    const userB = messagePayload.userB;   

        return admin.firestore().doc(`users/${userA}/chats`).add({ event.params.messageId }).then( () => {

        });

  });
Run Code Online (Sandbox Code Playgroud)

这是我的数据库看起来的方式

在此输入图像描述

任何提示非常感谢,我是firestore的新手.

node.js firebase google-cloud-functions firebase-admin google-cloud-firestore

7
推荐指数
3
解决办法
1万
查看次数

限制对admin-sdk的firestore访问

我正在设计一个基于VueJs(用于UI)+ NodeJs(用于后端,将在Google Cloud Platform中运行)+ Firestore(用于auth +数据库)的应用程序(我们称之为TodoList应用程序).

我已经浏览了Google的大量文档(有时是多余的!)来实现应该有用的东西,但我不确定它是否符合生产要求.

情况:

  • 由于基于密码的Firebase身份验证(以及用户的凭据,包括他的accessToken,存储在我的Vuex商店中),用户已在我的VueJs应用程序上登录.
  • Firebase Admin SDK正在我的后端运行.
  • 我的VueJs应用程序正在请求我的后端.
  • 后端验证客户端请求中发送的accessToken
  • 由于Admin SDK,我的后端请求我的Firestore数据库

我在Firestore数据库上设置了一些安全规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId}/{document=**} {
      allow read, write: if request.auth.uid == userId;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这样我就不希望任何记录的用户访问其他用户的数据.

题:

由于Firebase Admin SDK对我的Firestore数据库具有完全权限,因此如何确保不会出现任何安全问题.现在,我只是验证请求中发送的accessToken到我的后端,但......有些东西让我觉得这个错了!

码:

在客户端:

auth.onAuthStateChanged((user) => {
  if (user) {
    // Save the user credentials
  }
}
Run Code Online (Sandbox Code Playgroud)

在服务器端:

// idToken comes from the client app (shown above)
// …
Run Code Online (Sandbox Code Playgroud)

authentication node.js firebase firebase-admin google-cloud-firestore

7
推荐指数
2
解决办法
1381
查看次数