[英]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.