Error: Failed to get Firebase project project-name. Please make sure the project exists and your account has permission to access it - firebase

I tried running firebase deploy like I have always done but came across this Error:
Error: Failed to get Firebase project project-name. Please make sure the project exists and your account has permission to access it.
I have run firebase login and I get 'Already logged in as email#example.com'
The firebase-debug.log file shows a few 401 http responses and some of them have the following text:
'Request had invalid authentication credentials' and also 'invalid token'
How can this be solved?

For me this worked,
firebase logout
firebase login

This worked for me:
Run
firebase use --add
And re-select the project

Simply
use firebase login --reauth

For me, I was setting up a new machine with an existing firebase project. This is what I did:
First successfully login to firebase from your command console
firebase login
Get a list of your projects
firebase projects:list
Tell firebase which project you are using
firebase use <Project ID>
Then, I was able to deploy and use other commands for this project. Hope this helps someone.

sometimes there is a token error you can check debug.log
Error Message in debug.log : [debug] [2020-10-13T23:01:28.050Z] <<< HTTP RESPONSE BODY {"error":{"code":401,"message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED"}}
Solution of error use
firebase login --reauth
and again firebase init for reinitializing the project
select project and
firebase deploy

Run
firebase use --add
And re-select the project
This works 100%

Try logging out of firebase CLI and then log back in with the account that has the project that you are trying to run.
This was the case with me. I was logged in to another firebase account.
Steps:
`firebase logout`
`firebase login`

Any typo inside the .firebaserc would show this error. For me I had an extra comma, removing it solved the error.

Disconnecting the company's VPN and trying it again worked for me.

If none of the other answers worked for you, I had the same problem and received this solution from Firebase Support. (ty Sergei)
My system will occasionally create and Environment Variable named FIREBASE_TOKEN. The token will expire, but the variable does not. Restarts and logout/login cycles did nothing. Deleting the variable works every time though.
Remove-Item Env:\FIREBASE_TOKEN

It's really awesome and confusing------>
just did these command ->
> firebase logout
>
> firebase login

if you use Mac or Linux, you can write this command export http_proxy=http://127.0.0.1:1087 to make sure your terminal uses the proxy, which is useful for me.

None of the above solutions worked for me but removing/editing the stored value of the default project in $HOME/.config/configstore/firebase-tools.json did work.

If you have this issue in a CI pipeline, you can regenerate a token on your local machine with
firebase login:ci
Put the generated token as an environment variable, e.g. FIREBASE_TOKEN and run like this:
firebase deploy --token "$FIREBASE_TOKEN"

1.run this
firebase logout
firebase login
2.if u can not login successfully , like this ?
[https://i.stack.imgur.com/4MJM5.png][1]
run this , export http_proxy=http://localhost:your proxy port
4.successfully!!!
[https://i.stack.imgur.com/sRcvG.png][1]

It is possible you are trying to deploy without internet connection. The first thing to look for is if your internet is okay.

Make sure that you don't have this file .firebaserc already existing in your project directory if you already do!
Delete it and try firebase init in console again.

I got this error in Linux when I was out of disk space, freeing some space resolved it.

Related

vs code asking for authorization code in changing Firebase account during installation

? Which Firebase account would you like to use?
> [Login in with another account]
> ********* (other Firebase account logged in)
? Which Firebase account would you like to use? [Login in with another account]
? Enter authorization code:
Where do I get the authorization code?
I figured it out! you should first run
firebase login
then
firebase init
before running
ng add #angular/fire
It is a step-by-step process.

Unable to deploy a firebase cloud function due to permission error

I was trying to deploy my first firebase cloud function using firebase cli but I encountered an error instead :
C:\Users\Anurag Tripathi\Desktop\firebasecloudfunction> firebase deploy --only functions
Error: Missing permissions required for functions deploy. You must have permission iam.serviceAccounts.ActAs on service account project_number#appspot.gserviceaccount.com.
To address this error, ask a project Owner to assign your account the "Service Account User" role from this URL:
https://console.cloud.google.com/iam-admin/iam?project=project_number
I tried to solve the problem by following the instruction but didn't get any success . Please help.
Edit : I have abandoned the project :( , so I really can't test the answers. Thanks all for the answers and comments. I will accept the most upvoted answer.
This is what worked for me. First run firebase login:list to find out if the account logged into firebase cli is the same account authorized in your Google Cloud Console. If not, run firebase logout <email> then firebase login, then deploy again.
As specified in the docs, apart from the Service Account User role, you should assign the Cloud Functions Admin role to the Service Account that you are using to deploy the functions
It turned out I had the wrong project name in the .firebaserc file. After changing the name to the correct google cloud project name it worked.
firebase projects:list
If the current Firebase account doesn't have your project, you have to logout first.
firebase logout
firebase login
firebase projects:list
firebase use <project ID>
So for example,
firebase use stripesample1
firebase projects:list
firebase deploy --only functions
I was having same issue, I just did firebase logout and firebase login and issue resolved
I had this issue with a co-worker who inherited the Firebase Admin role from the Organization the project belongs to.
I confirmed he had inherited the role but not all the same permissions as when you assign the role manually from Firebase Console -> Users and Permissions.
So, I could have followed the instructions in the link shown in the error log. But I thought it was safer to just re-assign the Firebase Admin role from firebase console. That solved the issue.

Missing necessary permission resourcemanager.projects.getIamPolicy

The deployment of your Cloud Function failed:
Missing necessary permission resourcemanager.projects.getIamPolicy for service-1044193269753#gcf-admin-robot.iam.gserviceaccount.com on resource projects/ourcafe-mucqxq. Please grant service-1044193269753#gcf-admin-robot.iam.gserviceaccount.com the Cloud Functions Service Agent role. You can do that by running 'gcloud iam service-accounts add-iam-policy-binding projects/ourcafe-mucqxq --member=service-1044193269753#gcf-admin-robot.iam.gserviceaccount.com --role=Cloud Functions Service Agent'
I bumped into this problem in Dialogflow Fulfillment. However, I didn't know how to figure it out, did someone know how to do that?
This picture is IAM
This picture is Service Account
I stumbled over the same message. It appears there's a typo in the gcloud command they give you: the role argument is missing the "roles/" prefix. This version worked for me:
gcloud projects add-iam-policy-binding ourcafe-mucqxq \
--member=serviceAccount:service-1044193269753#gcf-admin-robot.iam.gserviceaccount.com \
--role=roles/cloudfunctions.serviceAgent
Maybe you need to log out and back in.
Check all the small boxes in the login interface.
I feel like the answer is given to you. But I'm not sure. Have you tried running the command provided from the google cloud shell.
From your images the service account that is actually mentioned (service-1044193269753)does not have the role needed.
Read more on the Cloud functions service account here

Firebase tools login from command line

I'm using Codeship to deploy a firebase app.
In order to do so, I first need to login using the firebase login command. Problem is, I need to login in the browser and then return to the command line and perform the deployment.
Is there an automated way to supply credentials to Firebase?
Cheers
firebase login --no-localhost is what worked for me. You get the Authorisation code from browser which you need to paste into your terminal window.
The accepted answer is correct for the old version of firebase-tools, however this has been deprecated as of version 3. The new command to get the token is:
firebase login:ci
You should save this in some kind of environment variable, ideally, FIREBASE_TOKEN.
Then, with any command you intend to run via ci (i.e. deploy), you can run:
firebase [command] --token [FIREBASE_TOKEN]
See wvm2008's answer for a more up to date version
One option would be to mint a token for the build server and pass it into the CLI with:
firebase --token <token>
You can also get a token from a system where you interactively logged in with:
firebase login:ci
See this page for more options.
Answer: Environmental Variables.
Specifically, using a machine with a browser and firebase tools installed, run firebase login:ci --no-localhost and paste the resulting key from the firebase CLI tool into an Environmental Variable and name it FIREBASE_TOKEN (not $FIREBASE_TOKEN).
In your deployment, say
npm install -g firebase-tools
firebase deploy
Done. If you care about Why? Read on.
The firebase/firebase-tools repo README indicates the following regarding Usage with CI Systems.
The Firebase CLI requires a browser to complete authentication, but is
fully compatible with CI and other headless environments.
On a machine with a browser, install the Firebase CLI. Run firebase
login:ci to log in and print out a new access token (the current CLI
session will not be affected).
NOTE: You actually want to type firebase login:ci --no-localhost
Store the output token in a secure but accessible way in your CI
system. There are two ways to use this token when running Firebase
commands:
Store the token as the environment variable FIREBASE_TOKEN and it will
automatically be utilized. Run all commands with the --token <token>
flag in your CI system.
πŸ‘‰ NOTE: You MUST put your token in quotes IIF using the --token flag
πŸ”₯ πŸ‘‰BIGGER NOTE Do NOT prefix your environment variable with $ or you will get a nonsensical error message below!!!
Your CLI authentication needs to be updated to take advantage of new features.
Please run firebase login --reauth
Error: Command requires authentication, please run firebase login
The order of precedence for token loading is flag, environment
variable, active project.
πŸ‘Œ Recommendation is to use Environmental Variable so the secret token is not stored/visible in the logs.

Firebase CLI Authentication through token

I followed the steps described in the official GitHub tutorial for use the Firebase CLI (Command Line) with a CI system (simple OS without browser integrate). I use my PC to login in firebase and get the token (from the browser procedure). I copied the token on the other system and I passed the token in all command but it does not work. I get the message that I need to be authenticate for doing these operations:
firebase login
firebase prefs:token
copy and use the token in other system
firebase list --token sdfgfdsg......
What's the problem?
Using a machine with a browser and firebase tools installed, run firebase login:ci --no-localhost and paste the resulting key from the firebase CLI tool into an Environmental Variable and name it FIREBASE_TOKEN (not $FIREBASE_TOKEN).
In your deployment, say
npm install -g firebase-tools
firebase deploy
Make sure not to run firebase logout on your PC, as doing so will invalidate the token (we're working on making this clearer now, actually).
If not, make sure that you're quoting the token:
firebase list --token '-K.....|.....'
The characters included in the auth token may cause shell errors that prevent the command from completing properly if it's not quoted.
I was facing the same problem with Travis, and the problem was the encryption of the token used by travis, you have to ensure you have correctly escaped the pipe symbol inside the token.
in my case something like
travis encrypt 'FIREBASE_TOKEN=-jksdjksjksdj\|ksdkjsjk'
Hope this helps, because I can ensure you that if you do:
firebase deploy --token '-jksdjksjksdj|ksdkjsjk'
in Travis it just works.
firebase is not recognizing the token in your case for some reason, you need to find that reason
Check this out:
http://docs.travis-ci.com/user/encryption-keys/

Resources