HTTP Error: 401 while setting up firebase cloud functions for android project
Asked Answered
P

5

204

I`m trying to set up firebase functions, but I get an error after running firebase init.

Error: 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.

enter image description here

Philae answered 19/10, 2018 at 11:29 Comment(0)
P
586

I solved the problem! you need to logout firebase logout then log-in firebase login again or just refresh the token with firebase login --reauth

it seems that the expiry time of Firebase auth token is limited to max 1Hr

Philae answered 19/10, 2018 at 11:35 Comment(3)
Glad to help :)Philae
Note: To log out, use firebase logout, then log back in with firebase loginAldora
I did firebase login several times... it said I was already logged in, but it was all a "lie." Disappointed users have to logout & back in or request the reauth explicitly. Why can't they just fail the current login behavior and auto-reauth if nec.? It requires extra work and is a poorer UX.Kaylakayle
W
43

Use firebase login --reauth, that happened to me because an old FIREBASE_TOKEN was present while trying to exec firebase init

Wherefrom answered 4/6, 2019 at 17:51 Comment(0)
J
20

First, manually delete FIREBASE_TOKEN from the Environment Variables on your Windows system, only THEN run firebase login --reauth.

Note: I tried to re-authenticate without deleting the Firebase token first, but it didn't work.

Juncaceous answered 3/1, 2022 at 23:55 Comment(5)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewAxseed
I'd have rather commented @pixshatterer's post, but didn't have sufficient points. However, the focus of my answer is on the removal/deletion of the Firebase token, which was not clearly specified by other answers. Moreover, the accepted answer didn't work in my case. It looks like there is a variety of use cases, for which a different solution is required. Maybe we need a summing-up answer.Juncaceous
@Juncaceous How can I delete the FIREBASE_TOKEN? none of the solutions here work for me, but I can not find the environment variable that you mention.Constitutive
Hey @Gerros, you need to look into your Environment Variables on your Windows system and look for that key. Not sure what OS version you are on, but if you google it you'll easily find a way to access your Env Vars.Juncaceous
@Juncaceous thx, I looked it up already but can not find it. I have Win10 and there is no env var FIREBASE_TOKENConstitutive
H
0

Had the same issue but with firebase hosting. For some reason only using sudo firebase I managed to make it work

Haws answered 7/12, 2021 at 13:46 Comment(0)
C
0

In my case, just doing 'firebase login --reauth' didn't work. When I did 'firebase login', it showed that I was logged in but with some deprecation warning: screenshot of my terminal

Turned out the node.js version was the problem. I updated it by following this answer (upgrade node js to the latest version on mac), launched a new terminal, and firebase command worked without 401 error.

Cymar answered 16/3 at 3:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.