Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to retrieve Firebase ID Token from the CLI?

I have a Firebase function that is triggered onRequest(), using the firebase-admin SDK and using Express as middleware. This function is not expected to be tied to a Firebase client/frontend (meaning, it is expected that this function can be called via curl -X POST ... etc.).

I want to secure this function such that only users with access to the Firebase project can make requests. I've found Firebase ID Tokens, and see how to create them on the client side.

My issue is that I don't have a client to create them from.

Is there a way to create an ID Token for an authorized user using the CLI, or another similar method?

E.g., something like

firebase login
firebase use <project-id>
firebase generate-id-token // would return an ID token with standard expiration rules.
like image 301
Sean McClure Avatar asked Jan 23 '26 04:01

Sean McClure


1 Answers

There isn't a command in Firebase CLI to login as a user and print ID token. You can call Firebase Auth REST API using cURL and get the token.

curl --request POST \
  --url 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=[FIREBASE_API_KEY]' \
  --header 'Content-Type: application/json' \
  --data '{
  "email": "[email protected]",
  "password": "12345678",
  "returnSecureToken": true
}'

I want to secure this function such that only users with access to the Firebase project can make requests.

Anyone can use the REST API but they must know the account's password to login.

like image 195
Dharmaraj Avatar answered Jan 26 '26 20:01

Dharmaraj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!