Using Postman to Fetch a Firebase Token

Alex Wasik
Nov 11, 2020

--

You can get a token from firebase and have Postman use it for all your requests.

Postman logo

For Firebase Authentication users, it is very common to need to use Postman for querying your API endpoints while also needing a Bearer Token from Firebase Auth to connect. Postman makes fetching a token and automatically setting it in all of your API requests easy.

In Postman, create a POST request with the following URL https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key={FIREBASE_API_KEY}.

In the Body, pass the following:

{
"email": "<email>",
"password": "<password>",
"returnSecureToken": true
}

The email will be a user in your firebase authentication list along with the password associated with that user.

The Content Type is application/json and will be automatically set in Postman. The response you will get back will be a JSON object and idToken is the token you need for your API requests as the Bearer Token.

To create an automated setting of this token, you can add the following code in the Tests tab of your auth request:

Tests Tab in Postman
Postman Tests Tab
var jsonData = JSON.parse(responseBody);
pm.globals.set("id_token", jsonData.idToken);

For your Postman requests, on another tab, set the Bearer Token in Authorization to {{id_token}}

Authorization Tab

The token will be automatically set in your requests.

Note: Firebase Tokens are only valid for 1 hour. When your token expires, send another POST request to the above URL to refresh.

--

--

Alex Wasik
Alex Wasik

Written by Alex Wasik

FullStack dev who mostly enjoys all things JS. If I can do it, so can you!

Responses (1)