Firebase functions:log - HTTP Error: 401, Request had invalid authentication credentials - firebase

I issued the command "firebase functions:log" from the command line and received the error:
Error: Failed to list log entries HTTP Error: 401, Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.
I am logged in to firebase, since the command "firebase login" responds with:
Already logged in as [my email address]
Any assistance is appreciated.
Thanks

I logged out of firebase on the command line via "firebase logout", then logged backed in via "firebase login" to resolve the issue

Related

FCM Push - Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential

I am trying to send fcm message to specific topic by using cURL command but it says error like
{
"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"
}
}
I used server key from firebase console
I followed this FCM Documentation
How to resolve this 401 error.
Actually I think why, this is because you need a Service account that will handle it for you.
So follow the steps here and this will make you generate a new key pair. With this key, you can get the access token from a code (see in python below but the documentation has support for NodeJS / Java) :
def _get_access_token():
"""Retrieve a valid access token that can be used to authorize requests.
:return: Access token.
"""
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'service-account.json', SCOPES)
access_token_info = credentials.get_access_token()
return access_token_info.access_tokenmessaging.py
And you just have to print this value, copy-paste it and use it as the Bearer OAuth 2 access token.

Request had invalid authentication credentials, what to do? R Studio

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. [authError]
<error/bigrquery_authError>
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. [authError]
Backtrace:
1. bigrquery::bq_table_download(...)
5. bigrquery:::bq_check_response(...)
6. bigrquery:::signal_reason(json$error$errors[[1L]]$reason, json$error$message)
Run `rlang::last_trace()` to see the full context.
Can someone please help, how to fix this? I'm downloading a huge table with millions of lines, it stuck in 12% and returns this error.

I can't deploy Firebase functions because I don't have "Service Account User" Role

I'm trying to deploy Firebase Functions like so:
firebase deploy --only functions
However, I'm getting the following error:
Error: Missing permissions required for functions deploy. You must have permission iam.serviceAccounts.ActAs on service account xyz#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?xyz
I've already given myself Service Account User permission by going to
Identity -> Service Accounts -> xyz#appspot.gserviceaccount.com -> Permissions -> + Grant Access
I've added my email and service account linked in GOOGLE_APPLICATION_CREDENTIALS. I'm still getting the same error.
Any ideas?
Can you verify that you are logged with the correct account and that you are linked to the project?
You can double check by creating a new project and then in cli
$ firebase logout
$ firebase login
$ firebase init

How do I solve: Error: Failed to list Firebase projects. See firebase-debug.log for more info

So I'm minding my own business trying to initializing a Firebase project in my Angular app when all of the sudden I'm hit with this error:
Error: Failed to list Firebase projects. See firebase-debug.log for more info.
To get to that point, I followed the instructions in the documentation here which are basically run:
$ npm install -g firebase-tools
$ firebase login // Turns out I was already logged in
$ firebase projects:list // Make sure you can access your account.
Anyway, back to the error. "Ok," I think. "I'll just check out the log it's pointing me to." I open the log and see:
HTTP Error: 401, 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.`
`FirebaseError: HTTP Error: 401, 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.`
The part about "invalid authentication credentials" makes me think it has something to do with me not being logged into firebase but firebase login shows I am logged in.
The URL in the log just takes me to the docs for using firebase auth in my app. Well, I would love to. But first I need this command to work, Firebase.
Has anyone run into this/have a solution for it?
Update
The fix is:
$ firebase login --reauth
Thanks to #kynan in the comments for simplifying the original two-liner down to this one-liner.
If that doesn't work, you can also try logging out and logging back in like the original answer.
Original Answer
The fix is:
$ firebase logout
$ firebase login
It looks like when you upgrade firebase-tools, that may invalidate your auth token. You just have to log out and log back in.
Here's the message when you log out:
$ firebase logout
! Invalid refresh token, did not need to deauthorize
+ Logged out from <email>
For people who don't want to logout, the below command will also work.
firebase login --reauth
use firebase logout to log out
then use firebase login to log back in to firebase in the CLI
Do this after updating the firebase tools using npm install -g firebase-tools
After succesfull login, use firebase use --add to list all the projects you have
for Who don't want to logout, the below command also work
firebase login --reauth
First go to command prompt and run below code then execute above code.
In Command Prompt:
Run : powershell Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
In my case that it couldn't list my firebase projects, I try to access firebase by vpn that I was installed on my system (not my browser), and it worked. Then I could initial firebase in my project as hosting and deploy it.
Okay so for me it was the problem of the wifi I was using. Apparently the wifi had been denied access to firebase so I used vpn and it worked like charm. You can try using a vpn to see if it would come
I encountered Exact same error but for a different reason. I was configuring Flutter app for Both iOS and Android. My bundleId contained a _ in it. so when I tried
flutterfire configure
Then my android app would configure just fine but iOS would not. and give this error. So if the above solution isn't working for you like me please check your bundleId or package Name. it can be the culprit.

How do I get "firebase login" to work from Google Cloud Shell

I logged into Google Cloud Shell and found that that the Firebase CLI is already installed.
I then tried to run "firebase list" to see that it was working and was prompted to login.
"Visit this URL on any device to log in:"
<very long URL>
I copy/pasted the URL into a browser and got the standard "Firebase CLI would like to:" prompt from Google but when I approved it by clicking the "Allow" button, it failed.
This is the error page that showed.
This site can’t be reached
localhost refused to connect.
Search Google for localhost 9005
ERR_CONNECTION_REFUSED
Run the following command in your terminal:
firebase login --no-localhost
This will return a url that you can copy in the browser. After completing the steps, you'll receive back a code which you paste in the terminal.
run same command if logging in from within docker
In cloudshell when following the above link, it gives: Authorization Error
Error 400: invalid_request
Required parameter is missing: response_type
But it does work from chromebook linux!

Resources