Using Postman to Fetch a Firebase Token
You can get a token from firebase and have Postman use it for all your requests.
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:
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}}
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.