Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to login to `firebase-tools` on headless remote server?

I am attempting to use firebase-tools on a remote Linux server via Putty. There is no desktop running on this server.

When I run firebase login, I'm presented with a long url that I need to copy/paste into any other device's browser:

https://accounts.google.com/o/oauth2/auth?client_id=xxxxxxxxxxxx.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=3kkd93kl&redirect_uri=http%3A%2F%2Flocalhost%3A9005

I copy/paste this into the browser on my local machine, then I authenticate with my Google account, then it attempts to redirect me to

http://localhost:9005/?state=25744816&code=4/mz.....

which is not an actual server running on my machine and is defintely not the address to the remote machine, which doesn't even have port 9005 active.

So the result is that the terminal is still sitting at "Waiting for authentication..."

I see a command called login:ci which says its for non-interactive environments, but it appears to do the same thing as the login command.

How do I get around this issue?

like image 251
Jake Wilson Avatar asked May 07 '17 05:05

Jake Wilson


People also ask

How do I access firebase terminal?

Windows. Download the standalone binary for the CLI. Then, you can access the executable to open a shell where you can run the firebase command. Use npm (the Node Package Manager) to install the CLI and enable the globally available firebase command.

How do I know if I have firebase command line?

Run firebase tools --version to check version. And as per the prompt, run npm install -g firebase-tools to update. You're right.

What does firebase Login do?

You can use Firebase Authentication to allow users to sign in to your app using one or more sign-in methods, including email address and password sign-in, and federated identity providers such as Google Sign-in and Facebook Login.


2 Answers

You can use firebase login --no-localhost

It will then prompt a url you can visit from any browser (no matter the machine), like your host.

Log in url prompt response

Log in with your Google account as usual and accept the permission request.

Finally, copy the provided authorization code

The authorization code of the url you visited

And paste it back in your remote machine's terminal. You should get a success message.

like image 200
UnJavaScripter Avatar answered Oct 30 '22 13:10

UnJavaScripter


Procedure on how to setup Firebase for CI and headless servers is described here: https://github.com/firebase/firebase-tools#using-with-ci-systems

The Firebase CLI requires a browser to complete authentication, but is fully compatible with CI and other headless environments.

  1. On a machine with a browser, install the Firebase CLI.
  2. Run firebase login:ci to log in and print out a new refresh token (the current CLI session will not be affected).
  3. 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:

  1. Store the token as the environment variable FIREBASE_TOKEN and it will be automatically used.
  2. Run all commands with --token <token> flag in your CI system.
like image 24
Yassine ElBadaoui Avatar answered Oct 30 '22 12:10

Yassine ElBadaoui