简体   繁体   English

谷歌云/firebase 存储错误:没有 `client_email` 无法签署数据。 ...名称:'SigningError'

[英]Google cloud/firebase storage Error: Cannot sign data without `client_email`. ... name: 'SigningError'

Im trying to get a signedurl from a file in firebase/gc storage.我试图从 firebase/gc 存储中的文件中获取 signedurl。 All other solutions that i could find was to create a service account, download the service key, and use it in my app, but ive done that, and im still getting the error.我能找到的所有其他解决方案是创建服务帐户、下载服务密钥并在我的应用程序中使用它,但我已经这样做了,但我仍然收到错误。 Ive followed this advice also and added relevant roles to my service account SigningError with Firebase getSignedUrl() .我也遵循了这个建议,并使用 Firebase getSignedUrl() 向我的服务帐户 SigningError添加了相关角色。

The client_email property is in the service key that im using. client_email 属性在我使用的服务密钥中。

Pretty new to service accounts and gc so i may be missing something simple.服务帐户和 gc 很新,所以我可能会遗漏一些简单的东西。

I am able to list the buckets, and all other requests to cloud firestore are working.我能够列出存储桶,并且对云 Firestore 的所有其他请求都在工作。 Its just the signedurl for specific files is proving very difficult to retrieve.它只是特定文件的 signedurl 证明很难检索。

Been driving me a bit loopy so any help would be great.一直让我有点发疯,所以任何帮助都会很棒。

Heres my code.这是我的代码。

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const { ApolloServer, gql } = require('apollo-server-express');
const { Storage } = require('@google-cloud/storage');

const serviceAccount = require('./emom-84ee4-firebase-adminsdk-2309z-aab93226ec.json');
const keyfileName = require('./emom-84ee4-ac9e94667d5e.json');

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://emom-84ee4.firebaseio.com"
});

const storage = new Storage({
    projectId: 'emom-84ee4',
    keyFileName: keyfileName,
    // TRIED THIS ALSO => keyFileName: serviceAccount
});

const typeDefs = gql`
    type DownloadURL {
        url: String
    }

    type Comment {
        artist: String,
        comment: String,
        userId: String,
        replies: [Comment]
    }

    type Track {
        album: String,
        artist: String,
        artistId: String,
        description: String,
        genre: String,
        id: ID,
        title: String,
        duration: Int,
        comments: [Comment]
    }
    type User {
        artist: String,
        artistImageUrl: String,
        artistName: String,
        bio: String,
        location: String,
        userId: String,
        website: String
    }
    type Query {
        tracks: [Track]
        users: [User]
        downloadUrl: DownloadURL
    }
`

const resolvers = {
    Query: {
        async tracks() {
            const tracks = await admin
            .firestore()
            .collection('tracks')
            .get();
        return tracks.docs.map(track => track.data());
    },
    async users() {
        const users = await admin
            .firestore()
            .collection('users')
            .get();
            return users.docs.map(user => user.data());
    },
    // ISSUE HAPPENING HERE
    async downloadUrl() {
        try {
            const signedUrl = await storage
                .bucket('emom-84ee4.appspot.com')
                .file('tracks/ds5MaDn5ewxxvV0CK9GG.mp3')
                .getSignedUrl({ action: 'read', expires: '10-25-2022' });
            const url = signedUrl;
            console.log(url)
            return url;
        } catch (error) {
            console.error(error);
        }
    }
    }
}

const app = express();
const server = new ApolloServer({ typeDefs, resolvers });

server.applyMiddleware({ app, path: '/', cors: true });

exports.graph = functions.https.onRequest(app);

I was getting "Cannot sign data without client_email " error when running firebase emulators:start .运行firebase emulators:start时出现“无法在没有client_email的情况下签署数据”错误。

I fixed it by setting up a service account and downloading the service account.json credentials file as service_account.json , then running GOOGLE_APPLICATION_CREDENTIALS="service_account.json" firebase emulators:start我通过设置服务帐户并将服务帐户.json 凭据文件下载service_account.json来修复它,然后运行GOOGLE_APPLICATION_CREDENTIALS="service_account.json" firebase emulators:start

You will need to add your service account key when you initialize your app.初始化应用程序时,您需要添加服务帐户密钥。

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

var creds = require("[path to your serviceAccountKey.json]");

admin.initializeApp({
  credential: admin.credential.cert(creds),
});

If you don't have a service account, you can read how to get it here如果您没有服务帐户,可以在此处阅读如何获取它

or use https://console.firebase.google.com/project/**YOUR_PROJECT**/settings/serviceaccounts/adminsdk或使用https://console.firebase.google.com/project/**YOUR_PROJECT**/settings/serviceaccounts/adminsdk

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使在服务帐户密钥中提供,也无法在没有“client_email”的情况下签署数据 - Cannot sign data without `client_email` even when provided in service account key 无需下载即可访问 Google Cloud Storage 中的数据 - Accessing data in Google Cloud Storage without downloading it 谷歌云存储:删除存储桶后无法重用存储桶名称 - Google cloud storage: Cannot reuse bucket name after deleting bucket Firebase 使用email登录后google登录报错:密码无效或用户没有密码 - Firebase Sign-in with email after google sign-in has error : The password is invalid or the user does not have a password 获取客户端 URL 到 Firebase 符合存储规则的云存储 - Getting a client URL to Firebase Cloud Storage that comply with storage rules Firebase Auth - 没有来自谷歌登录提供商的电子邮件 - Firebase Auth - no email from google sign in provider Google Cloud Storage:下载具有不同名称的文件 - Google Cloud Storage: download a file with a different name google colab 与 google 云存储数据出口 - google colab with google cloud storage data egress 谷歌云存储节点客户端 ResumableUploadError - Google Cloud Storage node client ResumableUploadError Flutter 谷歌登录 - Email 数据返回 null - Flutter Google Sign In - Email data returns null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM