Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Firebase Token for Backend Testing

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?

like image 711
Joel Holmes Avatar asked Oct 26 '18 12:10

Joel Holmes


People also ask

How do I get the Firebase refresh token?

You can refresh a Firebase ID token by issuing an HTTP POST request to the securetoken.googleapis.com endpoint. The refresh token's grant type, always "refresh_token". A Firebase Auth refresh token. The number of seconds in which the ID token expires.

How do I get the JWT token from Firebase authentication?

To achieve this, you must create a server endpoint that accepts sign-in credentials—such as a username and password—and, if the credentials are valid, returns a custom JWT. The custom JWT returned from your server can then be used by a client device to authenticate with Firebase (iOS+, Android, web).

How do I get OAuth 2.0 access token for Firebase?

Once you have a service account key file, you can use one of the Google API client libraries to generate a Google OAuth2 access token with the following required scopes: https://www.googleapis.com/auth/userinfo.email. https://www.googleapis.com/auth/firebase.database. Using the Google API Client Library for Node.


2 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":"[[email protected]]","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.

like image 158
Cheche Avatar answered Oct 24 '22 09:10

Cheche


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

like image 33
Aditya Joardar Avatar answered Oct 24 '22 09:10

Aditya Joardar