简体   繁体   English

403 调用者没有 Firebase 管理 API addFirebase 的权限

[英]403 The caller does not have permission for Firebase Management API addFirebase

I want to add Firebase project through Firebase Management Api.我想通过 Firebase Management Api 添加 Firebase 项目。 So for that.所以为此。 I made project on Google Cloud Platform console.我在谷歌云平台控制台上做了项目。 And created service account with permission as a owner.并以所有者身份创建了服务帐户。

I tried to read and create project throw google api explorer for addFirebase and it works.我尝试阅读并创建项目 throw google api explorer for addFirebase并且它有效。 But when i try to do the same through my code it read availableProject successfully and give output as但是当我尝试通过我的代码做同样的事情时,它成功读取了availableProject并将输出作为

{ "projectInfo": [ { "project": "projects/firebase-api-238012", "displayName": "Firebase-Api" } ] } { "projectInfo": [ { "project": "projects/firebase-api-238012", "displayName": "Firebase-Api" } ] }

but when i try to add project it give me this error但是当我尝试添加项目时它给了我这个错误

{ "error": { "code": 403, "message": "The caller does not have permission", "status": "PERMISSION_DENIED" } } { "error": { "code": 403, "message": "调用者没有权限", "status": "PERMISSION_DENIED" } }

I don't know why its is not creating project.我不知道为什么它没有创建项目。 What other permission it needs.它需要什么其他许可。 And why it allowed to me read available projects first.以及为什么它允许我先阅读可用的项目。

here is how i am trying to add my project.这是我尝试添加项目的方式。

jwt.js jwt.js

const { google } = require('googleapis');
var serviceAccountJwt = require('./Firebase-Api-b0e41b85ad44.json');

exports.connect = async () => {
return new Promise((resolve, reject) => {

    // scope is based on what is needed in our api
    const scope = ['https://www.googleapis.com/auth/firebase', 'https://www.googleapis.com/auth/cloud-platform'];

    // create our client with the service account JWT
    const { client_email, private_key } = serviceAccountJwt;
    const client = new google.auth.JWT(client_email, null, private_key, scope, null);

    // perform authorization and resolve with the client

    return client.authorize((err) => {
        if (err) { reject(err) }
        else {
            resolve(client)
        };
    });
});

} }

index.js file index.js 文件

const { google } = require('googleapis');
const request = require('request');
const { connect } = require('./jwt');
const availableProjects = 'https://firebase.googleapis.com/v1beta1/availableProjects';


async function getAccessToken() {
let client = await connect();
let accessToken = await client.getAccessToken();
let res = await getProjects(accessToken.token)
}

getAccessToken().catch(err => {
console.log(JSON.stringify(err))
})

const bodys = {
"timeZone": "America/Los_Angeles",
"locationId": "asia-south1",
"regionCode": "US"
}

async function getProjects(accesstoken) {

let options = {
url: availableProjects,
headers: {
  'Authorization': 'Bearer ' + accesstoken,
  'Accept': 'application/json',
  'Content-Type': 'application/json'
}
}

return request(options, async function (err, res) {
if (err) {
  console.error(err + " error");
 } else {
  //here it gives successful output
  console.log("response")
  console.log(res.body);
  let bodyJson = JSON.parse(res.body);
  let projectName = bodyJson.projectInfo[0].project;
  console.log(projectName)
  await addProject(accesstoken, projectName)
  return res.body;
 }
 });
 }

async function addProject(accesstoken, projecctID) {

 fbUrl = getAddFBUrl(projecctID);
 let options = {
 url: fbUrl,
  headers: {
  'Authorization': 'Bearer ' + accesstoken,
  'Accept': 'application/json',
  'Content-Type': 'application/json'
  },
  body:JSON.stringify(bodys)
 }

return request.post(options, function (err, res) {
 if (err) {
  console.error(err + " error");
 } else {
//here in response out put as permission denied 403
  console.log("response")
  console.log(res.body);
  console.log(JSON.stringify(res));
  return res.body;
 }

 });
}


function getAddFBUrl(projectId) {
return 'https://firebase.googleapis.com/v1beta1/' + projectId + 
':addFirebase';
}

i found one similar question to this.我发现了一个与此类似的问题。 But it didn't helped me to resolve my issue which is here但这并没有帮助我解决这里的问题

AskFirebase问Firebase

From the Firebase REST reference: Method: projects.addFirebase来自 Firebase REST 参考:方法:projects.addFirebase

To call projects.addFirebase, a member must be an Editor or Owner for the existing GCP Project.要调用 projects.addFirebase,成员必须是现有 GCP 项目的编辑者或所有者。 Service accounts cannot call projects.addFirebase.服务帐号无法调用 projects.addFirebase。

Update:更新:

To call projects.addFirebase, a project member or service account must have the following permissions (the IAM roles of Editor and Owner contain these permissions): firebase.projects.update, resourcemanager.projects.get, serviceusage.services.enable, and serviceusage.services.get.要调用 projects.addFirebase,项目成员或服务帐户必须具有以下权限(Editor 和 Owner 的 IAM 角色包含这些权限):firebase.projects.update、resourcemanager.projects.get、serviceusage.services.enable 和 serviceusage .services.get。

https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects/addFirebase https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects/addFirebase

I'm not sure if my answer will be helpful for author of this question, but this if first two things all should check when facing 403 Error with Google Cloud APIs我不确定我的回答是否对这个问题的作者有帮助,但是如果前两件事都应该在面对 Google Cloud API 的 403 错误时检查

0) Check configuration with gcloud 0) 使用 gcloud 检查配置

1) As mentioned before the first thing is to check the role of service account. 1) 如前所述,首先要检查服务帐户的角色。 You need Editor/Owner usually.您通常需要编辑/所有者。

https://cloud.google.com/iam/docs/understanding-roles https://cloud.google.com/iam/docs/understanding-roles

https://console.cloud.google.com/iam-admin https://console.cloud.google.com/iam-admin

在此处输入图像描述

在此处输入图像描述

2) The second one is to check if API enabled for project at all. 2) 第二个是检查是否为项目启用了 API。

在此处输入图像描述 在此处输入图像描述

Also when creating a key check it for correct service account.此外,在创建密钥时,请检查它是否有正确的服务帐户。

For someone who's just get started like me, this thing maybe helpful.对于像我这样刚入门的人来说,这件事可能会有所帮助。 When I seted up database, I choose Start in locked mode instead of Start in test mode .当我设置数据库时,我选择Start in locked mode而不是Start in test mode Therefore, I can't read or write:((. For beginner, just set everything in test mode. Hope it helpful.因此,我不会读或写:((。对于初学者,只需将所有内容设置为测试模式即可。希望对您有所帮助。

https://i.stack.imgur.com/nVxjk.png https://i.stack.imgur.com/nVxjk.png

Your problem means that your project is not linked with your firebase account which means you have to login with your firebase account.您的问题意味着您的项目未与您的 firebase 帐户关联,这意味着您必须使用您的 firebase 帐户登录。 Than you will have the permission比你将获得许可

  1. type cd functions in your firebase project directory在你的 firebase 项目目录中键入cd functions
  2. type firebase login输入firebase login
  3. login with the Gmail which is connected with your firebase account使用与您的 firebase 帐户关联的 Gmail 登录

It'll work它会起作用

暂无
暂无

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

相关问题 Firebase 初始化函数返回 403 调用者没有权限 - Firebase init functions returns 403 caller does not have permission GCP 403 调用方没有 create_transfer_config 的权限 - GCP 403 The caller does not have permission for create_transfer_config cURL 到 GoogleCloud Vision API:调用者没有使用项目 foo 所需的权限 - cURL to GoogleCloud Vision API: Caller does not have required permission to use project foo cloud_firestore/permission-denied 调用者无权执行指定操作 - cloud_firestore/permission-denied The caller does not have permission to execute the specified operation firestore 备份 function 错误,“PERMISSION_DENIED:调用者没有权限” - firestore backup function errors with "PERMISSION_DENIED: The caller does not have permission" 获取错误:Firestore:调用者没有执行指定操作的权限。 但是我已经登录了 - Get Error : Firestore: The caller does not have permission to execute the specified operation. But I have already signed in Firebase 存储:用户无权访问 - Firebase Storage: User does not have permission to access 错误 403:您的客户端没有在 python google 云模块中获取 URL 的权限 - error 403: Your client does not have permission to get URL in python google cloud module Firebase function 尝试写入 firebase 存储“Firebase 存储:用户无权访问”时出错 - Firebase function getting error when trying to write to firebase storage "Firebase Storage: User does not have permission to access" 由于调用者没有权限,从 S3 到 GCS 的 Google StorageTransfer 作业失败 - Google StorageTransfer job from S3 to GCS failed due to The caller does not have permission
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM