Firebase-tools: firebase login: Token Fetch Error

Created on 3 Oct 2017  ·  45Comments  ·  Source: firebase/firebase-tools

Hi,

I'm having some trouble to login.

Version info

3.13.0

Steps to reproduce

$ firebase login --no-localhost --debug

Expected behavior

A sucessful login

Actual behavior

$ firebase login --no-localhost --debug
[2017-10-03T18:14:05.541Z] ----------------------------------------------------------------------
[2017-10-03T18:14:05.546Z] Command:       /usr/local/bin/node /usr/local/bin/firebase login --no-localhost --debug
[2017-10-03T18:14:05.546Z] CLI Version:   3.13.0
[2017-10-03T18:14:05.546Z] Platform:      linux
[2017-10-03T18:14:05.546Z] Node Version:  v8.6.0
[2017-10-03T18:14:05.547Z] Time:          Tue Oct 03 2017 15:14:05 GMT-0300 (BRT)
[2017-10-03T18:14:05.547Z] ----------------------------------------------------------------------

? Allow Firebase to collect anonymous CLI usage and error reporting information? No

Visit this URL on any device to log in:
https://accounts.google.com/o/oauth2/auth?client_id=563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com&scope=email%20openid%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloudplatformprojects.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Ffirebase%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&response_type=code&state=866083077&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob

? Paste authorization code here: 4/9FxonAqbx4paDM4BWzPaSLFuLbAUaTB8bS65YK5R_vc
[2017-10-03T18:14:20.567Z] >>> HTTP REQUEST POST https://accounts.google.com/o/oauth2/token { code: '4/9FxonAqbx4paDM4BWzPaSLFuLbAUaTB8bS65YK5R_vc',
  client_id: '563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com',
  client_secret: 'j9iVZfS8kkCEFUPaAeJV0sAi',
  redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
  grant_type: 'authorization_code' } 
 Tue Oct 03 2017 15:14:20 GMT-0300 (BRT)
[2017-10-03T18:14:20.582Z] Token Fetch Error: Error
    at FirebaseError (/usr/local/lib/node_modules/firebase-tools/lib/error.js:11:17)
    at Request._callback (/usr/local/lib/node_modules/firebase-tools/lib/api.js:32:23)
    at self.callback (/usr/local/lib/node_modules/firebase-tools/node_modules/request/request.js:186:22)
    at emitOne (events.js:115:13)
    at Request.emit (events.js:210:7)
    at Request.onRequestError (/usr/local/lib/node_modules/firebase-tools/node_modules/request/request.js:878:8)
    at emitOne (events.js:115:13)
    at ClientRequest.emit (events.js:210:7)
    at ClientRequest.onError (/usr/local/lib/node_modules/firebase-tools/node_modules/tunnel-agent/index.js:179:21)
    at Object.onceWrapper (events.js:316:30)

Error: Authentication Error: Your credentials are no longer valid. Please run firebase login --reauth

For CI servers and headless environments, generate a new token with firebase login:ci

Someone knows what's going on?

Most helpful comment

I had the same issue and occasionally this helped me:
set "NODE_TLS_REJECT_UNAUTHORIZED=0"
and then re-run firebase login

All 45 comments

Hi, I have the same problem

I am facing the same problem but with 'Firebase login' command!
Please suggest a resolution to this?

I'm experiencing exact same problem. I've been trying out different combinations of firebase login and firebase login:ci with --reauth, --no-localhost, and --debug to no avail. Also, it hasn't made a difference doing an explicit firebase logut. Further, I've been using three different browsers i.e. Firefox, Chrome, and Safari for doing the authorization to see if that might make a difference. It hasn't.

Judging from the kind of "Token Fetch Error" @thiagobonfante and I'm getting the API request to the OAuth API fails leading to a rejected promise at: https://github.com/firebase/firebase-tools/blob/b247ab9ca9e669d833ff830465c280e304d8b068/lib/auth.js#L83

Note, how a response, however faulty, from the OAuth API would result in an error message with both a status code and a response body: https://github.com/firebase/firebase-tools/blob/b247ab9ca9e669d833ff830465c280e304d8b068/lib/auth.js#L75

To follow up, in trying to reinstall the NPM package for Firebase Tools to see if that might make a difference NPM failed in a way that smelled like a DNS issue. I restarted the computer (macOS 10.12.6 Sierra) and then both the NPM install and the reauth of Firebase Tools went through.

As such I can't tell with certainty that the two issues were related. However, a reboot of your computer might just be a thing to try if you're experiencing this issue.

@tblomseth in my case I've already tried all you said. The error was thrown by line 83.

If this is still an issue, please re-open.

I am getting the same issue. I tried the same thing yesterday it was working perfectly fine. but now i am getting an authorization error. I have also attached the snapshot.

image

Same issue here.... any solutions?

Same issue :(

same issue

same issue

Did running firebase login --reauth like the error message suggested work?

same issue

no @laurenzlong, even this didn't work

I had the same issue and occasionally this helped me:
set "NODE_TLS_REJECT_UNAUTHORIZED=0"
and then re-run firebase login

@MrSuhov Thank you, it realy works!

@MrSuhov thanks, works for me too!!

same issue

same issue - I've tried all of the above, and I'm not using a proxy, which also seems to be a cause.

Version info

4.0.1

Platform Information

Windows

Steps to reproduce

$ firebase login --no-localhost --debug

Expected behavior

A sucessful login

Actual behavior

PS C:_angular\flow-v6.2.4> firebase login --no-localhost --debug
[2018-08-01T16:31:54.980Z] ----------------------------------------------------------------------
[2018-08-01T16:31:54.996Z] Command: C:\Program Files\nodejs\node.exe C:\Users\patrick\AppData\Roamingnpm\node_modules\firebase-tools\binfirebase login --no-localhost --debug
[2018-08-01T16:31:54.996Z] CLI Version: 4.0.1
[2018-08-01T16:31:54.997Z] Platform: win32
[2018-08-01T16:31:54.997Z] Node Version: v9.10.1
[2018-08-01T16:31:54.998Z] Time: Wed Aug 01 2018 18:31:54 GMT+0200 (Romance (zomertijd))
[2018-08-01T16:31:54.998Z] ----------------------------------------------------------------------

? Allow Firebase to collect anonymous CLI usage and error reporting information? No

Visit this URL on any device to log in:
https://accounts.google.com/o/oauth2/auth?client_id=563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com&scope=email%20openid%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloudplatformprojects.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Ffirebase%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&response_type=code&state=781119839&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob

? Paste authorization code here: 4/AAAcSvs3St9DxIT5uTp-uj0Eln5YzWpq_zz7IPv0EUxV00lY_n9kSvA
[2018-08-01T16:32:11.524Z] >>> HTTP REQUEST POST https://accounts.google.com/o/oauth2/token
{ code: '4/AAAcSvs3St9DxIT5uTp-uj0Eln5YzWpq_zz7IPv0EUxV00lY_n9kSvA',
client_id: '563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com',
client_secret: 'j9iVZfS8kkCEFUPaAeJV0sAi',
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
grant_type: 'authorization_code' }
Wed Aug 01 2018 18:32:11 GMT+0200 (Romance (zomertijd))
[2018-08-01T16:32:11.626Z] Token Fetch Error: Error
at new FirebaseError (C:\Users\patrick\AppData\Roamingnpm\node_modules\firebase-tools\liberror.js:11:16)
at Request._callback (C:\Users\patrick\AppData\Roamingnpm\node_modules\firebase-tools\lib\api.js:35:11)
at self.callback (C:\Users\patrick\AppData\Roamingnpm\node_modules\firebase-tools\node_modules\request\request.js:185:22)
at Request.emit (events.js:180:13)
at Request.emit (domain.js:421:20)
at Request.onRequestError (C:\Users\patrick\AppData\Roamingnpm\node_modules\firebase-tools\node_modules\request\request.js:877:8)
at ClientRequest.emit (events.js:180:13)
at ClientRequest.emit (domain.js:421:20)
at TLSSocket.socketErrorListener (_http_client.js:395:9)
at TLSSocket.emit (events.js:180:13)

Error: Authentication Error: Your credentials are no longer valid. Please run firebase login --reauth

For CI servers and headless environments, generate a new token with firebase login:ci

Additional remarks

I have tried the following workarounds based on this issue:

  1. npm uninstall -g firebase-tools
  2. Restarting the computer
  3. npm install -g firebase-tools
  4. firebase login => successful login!
  5. firebase list => Error: Authentication Error: Your credentials are no longer valid. Please run firebase login --reauth
  6. firebase login => Already logged in as **@gmail.com
  7. firebase logout => ! Invalid refresh token, did not need to deauthorize

    • Logged out from @gmail.com

  8. firebase loginfirebase login --no-localhost --debug => same as above

Can someone help?
I need to deploy a new version of my application asap.
Thanks.

I was running into this exact same issue. I restarted my machine--restarting Docker was probably enough, but hey!--and ran docker system prune.

Once Docker was completely fresh, I ran my build again and it worked just fine.

I also added set "NODE_TLS_REJECT_UNAUTHORIZED=0" to my build script... so that could have helped too?

If you're in China, set a proxy like shadowsocks in your console.
~/.zshrc

function proxy() {
    export http_proxy="http://192.168.1.100:1087"
    export https_proxy="http://192.168.1.100:1087"
    export all_proxy="http://192.168.1.100:1087"
}

function unproxy() {
    unset http_proxy https_proxy all_proxy
}

I also facing same issue. here is my logs..

localhost:functions gradler$ firebase login --no-localhost --debug
[2019-03-18T07:46:03.766Z] ----------------------------------------------------------------------
[2019-03-18T07:46:03.769Z] Command: /usr/local/bin/node /usr/local/bin/firebase login --no-localhost --debug
[2019-03-18T07:46:03.770Z] CLI Version: 6.5.0
[2019-03-18T07:46:03.770Z] Platform: darwin
[2019-03-18T07:46:03.770Z] Node Version: v11.2.0
[2019-03-18T07:46:03.770Z] Time: Mon Mar 18 2019 16:46:03 GMT+0900 (Korean Standard Time)
[2019-03-18T07:46:03.770Z] ----------------------------------------------------------------------

? Allow Firebase to collect anonymous CLI usage and error reporting information? Yes

Visit this URL on any device to log in:
https://accounts.google.com/o/oauth2/auth?client_id=563584335869-fgrhgmd47bqnekij5i8b5pr03xxxxxxx.apps.googleusercontent.com&scope=email%20openid%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloudplatformprojects.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Ffirebase%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&response_type=code&state=111287150&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob

? Paste authorization code here: 4/EAHhdfZTTEq50Xbdh6Cv4no5ZjeO-xxxx
[2019-03-18T07:46:17.983Z] >>> HTTP REQUEST POST https://accounts.google.com/o/oauth2/token
code=4/EAHhdfZTTEq50Xbdh6Cv4no5ZjeO-xxxx, client_id=563584335869-fgrhgmd47bqnekij5xxxxxxxx.apps.googleusercontent.com, client_secret=j9iVZfS8kkCEFUPxxxx, redirect_uri=urn:ietf:wg:oauth:2.0:oob, grant_type=authorization_code
[2019-03-18T07:46:18.022Z] Token Fetch Error: Error
at new FirebaseError (/usr/local/lib/node_modules/firebase-tools/lib/error.js:9:18)
at Request._callback (/usr/local/lib/node_modules/firebase-tools/lib/api.js:30:31)
at self.callback (/usr/local/lib/node_modules/firebase-tools/node_modules/request/request.js:185:22)
at Request.emit (events.js:182:13)
at Request.EventEmitter.emit (domain.js:441:20)
at Request.onRequestError (/usr/local/lib/node_modules/firebase-tools/node_modules/request/request.js:881:8)
at ClientRequest.emit (events.js:182:13)
at ClientRequest.EventEmitter.emit (domain.js:441:20)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:182:13)

Error: Authentication Error: Your credentials are no longer valid. Please run firebase login --reauth

For CI servers and headless environments, generate a new token with firebase login:ci

A way to solve it is to just do:

firebase logout which will log you out and log in again with firebase login

@tennessine 嘿,老哥,这个是在哪个文件设置的?在linux服务器上的吗?

Getting the same issue Token Fetch Error: Error; does someone has some tips on how to solve it?

I was able to solve the issue on my side; this was in fact linked to that problem: https://github.com/firebase/firebase-admin-node/issues/115

Fixed it adding ugly code process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; in api.js before the request call

Thank you @tennessine. Your way works for me.
Hi @cnscorpions, I am using:

Win10
Cmder(bash) # then we can use commands of Linux on windows
Shadowsocks-windows

find the user_profile.sh file in the path where you extracted your cmder, it may be likeC:\Users\Cmder\config
then add below functions (Thank you @tennessine again)

function pxyo() {
    export http_proxy="http://127.0.0.1:1080"
    export https_proxy="http://127.0.0.1:1080"
    export all_proxy="http://127.0.0.1:1080"
        echo 'proxy-on'
}

function pxyf() {
    unset http_proxy https_proxy all_proxy
        echo 'proxy-off'
}

NOTE:
I use port 1080(default local port), so I set like above
And 127.0.0.1 for shadowsocks

Then use pxyo to open the set, and you can login firebase now.
If you login failed again, please check your connect use curl www.google.com.
It works for me.

I ran firebase login --debug and output showed me:

[2019-08-27T22:59:17.587Z] ----------------------------------------------------------------------
[2019-08-27T22:59:17.590Z] Command:       /usr/local/bin/node 
[2019-08-27T22:59:17.590Z] CLI Version:   7.2.2
[2019-08-27T22:59:17.590Z] Platform:      darwin
[2019-08-27T22:59:17.590Z] Node Version:  v10.15.3
[2019-08-27T22:59:17.591Z] Time:          Tue Aug 27 2019 15:59:17 GMT-0700 (Pacific Daylight Time)
**[2019-08-27T22:59:17.591Z] Env Overrides: FIREBASE_CLIENT_SECRET**
[2019-08-27T22:59:17.591Z] ----------------------------------------------------------------------

I use the variable FIREBASE_CLIENT_SECRET without knowing firebase relies on that as well. Wasted hours on this... Check the debug to see maybe you are overwriting an env variable unknowingly. After unsetting the variable, I was able to login immediately.

Just ran into this - as seen above it looks like it's failing on the POST request, takes long to come back with:

[2019-09-03T04:50:55.231Z] Token Fetch Error: Error
at new FirebaseError (/usr/local/lib/node_modules/firebase-tools/lib/error.js:9:18)
at Request._callback (/usr/local/lib/node_modules/firebase-tools/lib/api.js:30:31)
at self.callback (/usr/local/lib/node_modules/firebase-tools/node_modules/request/request.js:185:22)
at Request.emit (events.js:182:13)
at Request.EventEmitter.emit (domain.js:441:20)
at Request.onRequestError (/usr/local/lib/node_modules/firebase-tools/node_modules/request/request.js:881:8)
at ClientRequest.emit (events.js:182:13)
at ClientRequest.EventEmitter.emit (domain.js:441:20)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:182:13)

EDIT: none of the above suggestions worked (including setting NODE_TLS_REJECT_UNAUTHORIZED) haven't tried the proxy thing though.

EDIT 2: for me it seemed to be some network error, I tried the same thing again 30 minutes later and it worked.

Running 7.3.0 and reverting to 7.1.1

`` firebase login --reauth --no-localhost```

I get token, paste it, and after a long time, I get

Error: Authentication Error: Your credentials are no longer valid. Please run firebase login --reauth

with --debug

[2019-09-05T00:20:59.959Z] >>> HTTP REQUEST POST https://accounts.google.com/o/oauth2/token  
 code=4/qgGpDeAVtNXUoSZ5CYXn5APgtFKgI4wyc0Mtqbnb8XSQvuEJs0VvAvc, client_id=563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com, client_secret=j9iVZfS8kkCEFUPaAeJV0sAi, redirect_uri=urn:ietf:wg:oauth:2.0:oob, grant_type=authorization_code

wait a long long time...

[2019-09-05T00:23:10.060Z] Token Fetch Error: Error
    at new FirebaseError (/home/enric/.asdf/installs/nodejs/10.16.0/.npm/lib/node_modules/firebase-tools/lib/error.js:9:18)
    at Request._callback (/home/enric/.asdf/installs/nodejs/10.16.0/.npm/lib/node_modules/firebase-tools/lib/api.js:30:31)
    at self.callback (/home/enric/.asdf/installs/nodejs/10.16.0/.npm/lib/node_modules/firebase-tools/node_modules/request/request.js:185:22)
    at Request.emit (events.js:198:13)
    at Request.EventEmitter.emit (domain.js:448:20)
    at Request.onRequestError (/home/enric/.asdf/installs/nodejs/10.16.0/.npm/lib/node_modules/firebase-tools/node_modules/request/request.js:881:8)
    at ClientRequest.emit (events.js:198:13)
    at ClientRequest.EventEmitter.emit (domain.js:448:20)
    at ClientRequest.onError (/home/enric/.asdf/installs/nodejs/10.16.0/.npm/lib/node_modules/firebase-tools/node_modules/tunnel-agent/index.js:179:21)
    at Object.onceWrapper (events.js:286:20)

Error: Authentication Error: Your credentials are no longer valid. Please run firebase login --reauth

For CI servers and headless environments, generate a new token with firebase login:ci

Very frustrating. Can't make changes to my app. I love Firebase but this kind of stuff makes me question using it in production.

An Answer:
I haven't read the entire change to see if anyone else has suggested it.

Firebase respects your standard GCP Oauth2 token.
Having to go to the browser and get the code doesn't seem very CI or headless.
This is working for us:
export GOOGLE_APPLICATION_CREDENTIALS=key.json # Where key.json is your service account json file
export FIREBASE_TOKEN=$(gcloud auth application-default print-access-token)

In case if someone uses firebase-cli behind corporate proxy with self-signed certificate:

  1. set proxy settings as env variables.
  2. set env variable NODE_EXTRA_CA_CERTS to the path of the self-signed certificate.

In bash:

export NODE_TLS_REJECT_UNAUTHORIZED=0

I had the same issue and occasionally this helped me:
set "NODE_TLS_REJECT_UNAUTHORIZED=0"
and then re-run firebase login

in which file i can set this

I was able to solve the issue on my side; this was in fact linked to that problem: firebase/firebase-admin-node#115

Fixed it adding ugly code process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; in api.js before the request call

can you tell me where i can i find this exactly ?

In bash:

export NODE_TLS_REJECT_UNAUTHORIZED=0

@daryoooooo just do it in bash

Can you explain more because i dont know what. Is bash ?

On Sat, Mar 28, 2020 at 4:42 AM Moa Lai notifications@github.com wrote:

In bash:

export NODE_TLS_REJECT_UNAUTHORIZED=0

@daryoooooo https://github.com/daryoooooo just do it in bash


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-tools/issues/486#issuecomment-605383768,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AM6RWMW6POW2CZLJ76K3P5TRJVPYJANCNFSM4D5SJF7A
.

i had same issue, i disconnected my vpn connection and tried, it worked!!!

please help. no working solutions for me :(

Can't solve for me,Any more solution?

If you're in China, set a proxy like shadowsocks in your console.
~/.zshrc

function proxy() {
  export http_proxy="http://192.168.1.100:1087"
  export https_proxy="http://192.168.1.100:1087"
  export all_proxy="http://192.168.1.100:1087"
}

function unproxy() {
  unset http_proxy https_proxy all_proxy
}

Run following in bash (Windows):

set http_proxy=http://127.0.0.1:<port> & set https_proxy=http://127.0.0.1:<port>

It's working, thanks. I think maybe normally Shadowsocks or Clash is not working for bash.

The solution from @MoaLaiSkirulais works for me....

D:\Aarya's Files\Doctor Management APP\adminlte-v3\WEBSITE FOLDER\medical>firebase login
i Firebase optionally collects CLI usage and error reporting information to help improve our products. Data is collected in accordance with Google's privacy policy (https://policies.google.com/privacy) and is not used to identify you.

? Allow Firebase to collect CLI usage and error reporting information? Yes
i To change your data collection preference at any time, run firebase logout and log in again.

Visit this URL on this device to log in:
https://accounts.google.com/o/oauth2/auth?client_id=563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com&scope=email%20openid%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloudplatformprojects.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Ffirebase%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&response_type=code&state=22105336&redirect_uri=http%3A%2F%2Flocalhost%3A9005

Waiting for authentication...

Error: An unexpected error has occurred.

please help me with this.

Was this page helpful?
0 / 5 - 0 ratings