Firebase Auth REST API

Firebase Auth REST API

You can query the Firebase Auth backend through a REST API. This can be used for various operations such as creating new users, signing in existing ones, and editing or deleting these users.

Throughout this document, API_KEY refers to the Web API Key, which can be obtained on the project settings page in your admin console.

API Usage

Method: POST
Content-Type: application/json
Endpoint

https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=[API_KEY]

Request Body Payload

Property Name Type Description
token string A Firebase Auth custom token from which to create an ID and refresh token pair.
returnSecureToken boolean Whether or not to return an ID and refresh token. Should always be true.

Response Payload

Property Name Type Description
idToken string A Firebase Auth ID token generated from the provided custom token.
refreshToken string A Firebase Auth refresh token generated from the provided custom token.
expiresIn string The number of seconds in which the ID token expires.

Sample request

curl 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=[API_KEY]' \
-H 'Content-Type: application/json' \
--data-binary '{"token":"[CUSTOM_TOKEN]","returnSecureToken":true}'

A successful request is indicated by a 200 OK HTTP status code. The response contains the Firebase ID token and refresh token associated with the custom token.

Sample response

{
  "idToken": "[ID_TOKEN]",
  "refreshToken": "[REFRESH_TOKEN]",
  "expiresIn": "3600"
}

Common error codes

Exchange a refresh token for an ID token

You can refresh a Firebase ID token by issuing an HTTP POST request to the securetoken.googleapis.com endpoint.

Method: POST
Content-Type: application/x-www-form-urlencoded
Endpoint

https://securetoken.googleapis.com/v1/token?key=[API_KEY]

Request Body Payload

Property Name Type Description
grant_type string The refresh token's grant type, always "refresh_token".
refresh_token string A Firebase Auth refresh token.

Response Payload

Property Name Type Description
expires_in string The number of seconds in which the ID token expires.
token_type string The type of the refresh token, always "Bearer".
refresh_token string The Firebase Auth refresh token provided in the request or a new refresh token.
id_token string A Firebase Auth ID token.
user_id string The uid corresponding to the provided ID token.
project_id string Your Firebase project ID.

Sample request

curl 'https://securetoken.googleapis.com/v1/token?key=[API_KEY]' \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data 'grant_type=refresh_token&refresh_token=[REFRESH_TOKEN]'

A successful request is indicated by a 200 OK HTTP status code. The response contains the new Firebase ID token and refresh token.

Sample response

{
  "expires_in": "3600",
  "token_type": "Bearer",
  "refresh_token": "[REFRESH_TOKEN]",
  "id_token": "[ID_TOKEN]",
  "user_id": "tRcfmLH7o2XrNELi...",
  "project_id": "1234567890"
}

Common error codes