Get Firebase Token for Backend Testing

Viewed 2571

I am writing an application in which I would like to use Firebase for the authentication of any sort of back end calls. Is there a way for me to get a token through a CLI or curl for local testing without having to spin up a front end to get the token?

3 Answers

As a resume (to me and maybe others) from @James-Poag answer, use:

curl 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=[API_KEY]' \
-H 'Content-Type: application/json' \
--data-binary '{"email":"[user@example.com]","password":"[PASSWORD]","returnSecureToken":true}'

Where:

  • email (string): The email the user is signing in with.

  • password (string): The password for the account.

  • returnSecureToken (boolean): Whether or not to return an ID and refresh token. Should always be true.

The property idToken from response payload is the parameter you're looking for.

Well i have made a front end one page html to generate dummy firebase ID token for your application, in case anyone needs it

Firebase Token Generator

They changed the link - see REST API.

curl 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=[API_KEY]' \
-H 'Content-Type: application/json' \
--data-binary '{"email":"[user@example.com]","password":"[PASSWORD]","returnSecureToken":true}'

In the example above, you would replace [API_KEY] with the Web API Key of your Firebase project, [user@example.com] with the user's email and [PASSWORD] with the user's password.

Related