Using the REST API

This document shows you how to perform common user operations, such as signing in users and working with tokens, using the Identity Platform REST API.

Before you begin

To use the REST API, you'll need an Identity Platform API key. To obtain a key:

  1. Go to the Identity Providers page in the Google Cloud console.
    Go to the Identity Providers page

  2. Click Application setup details.

  3. Copy the apiKey field.

Note that HTTPS is required for all API calls.

Calling the API

Exchange custom token for an ID and refresh token

You can exchange a custom Auth token for an ID and refresh token by issuing an HTTP POST request to the signInWithCustomToken endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
tokenstringAn Identity Platform custom token from which to create an ID and refresh token pair.
returnSecureTokenbooleanWhether or not to return an ID and refresh token. Should always be true.
tenantIdstringThe tenant ID the user is signing into. Only used in multi-tenancy.
Must match the tenant_id in the token.
Custom Token Claims
PropertyNameDescription
algAlgorithmShould be RS256.
issIssuerYour project's service account email address.
subSubjectYour project's service account email address.
audAudiencehttps://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit
iatIssued-at timeThe current time, in seconds since the UNIX epoch.
expExpiration timeThe time, in seconds since the UNIX epoch, at which the token expires. It can be a maximum of 3600 seconds later than the iat.
Note: this only controls the time when the custom token itself expires. But once you sign a user in using signInWithCustomToken(), they will remain signed in into the device until their session is invalidated or the user signs out.
uidUser IdThe unique identifier of the user, between 1-36 characters long.
tenant_idTenant IdThe identifier of the tenant that the user is signing in to.
claims (optional)Optional custom claims to include in the Security Rules auth or request.auth variables.
Response Payload
Property NameTypeDescription
idTokenstringAn Identity Platform ID token generated from the provided custom token.
refreshTokenstringAn Identity Platform refresh token generated from the provided custom token.
expiresInstringThe 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 Identity Platform ID token and refresh token associated with the custom token.

Sample response

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

Common error codes

  • INVALID_CUSTOM_TOKEN: The custom token format is incorrect or the token is invalid for some reason (e.g. expired, invalid signature etc.)
  • CREDENTIAL_MISMATCH: The custom token corresponds to a different Google Cloud project.

Exchange a refresh token for an ID token

You can refresh an Identity Platform 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 NameTypeDescription
grant_typestringThe refresh token's grant type, always "refresh_token".
refresh_tokenstringAn Identity Platform refresh token.
Response Payload
Property NameTypeDescription
expires_instringThe number of seconds in which the ID token expires.
token_typestringThe type of the refresh token, always "Bearer".
refresh_tokenstringThe Identity Platform refresh token provided in the request or a new refresh token.
id_tokenstringAn Identity Platform ID token.
user_idstringThe uid corresponding to the provided ID token.
project_idstringYour Google Cloud 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 Identity Platform 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

  • TOKEN_EXPIRED: The user's credential is no longer valid. The user must sign in again.
  • USER_DISABLED: The user account has been disabled by an administrator.
  • USER_NOT_FOUND: The user corresponding to the refresh token was not found. It is likely the user was deleted.
  • API key not valid. Please pass a valid API key. (invalid API key provided)
  • INVALID_REFRESH_TOKEN: An invalid refresh token is provided.
  • Invalid JSON payload received. Unknown name \"refresh_tokens\": Cannot bind query parameter. Field 'refresh_tokens' could not be found in request message.
  • INVALID_GRANT_TYPE: The grant type specified is invalid.
  • MISSING_REFRESH_TOKEN: No refresh token provided.
  • PROJECT_NUMBER_MISMATCH: The project number of the refresh token does not match that of the API key provided.

Sign up with email / password

You can create a new email and password user by issuing an HTTP POST request to the Auth signupNewUser endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
emailstringThe email for the user to create.
passwordstringThe password for the user to create.
returnSecureTokenbooleanWhether or not to return an ID and refresh token. Should always be true.
tenantIdstringThe tenant ID of the user to create. Only used in multi-tenancy.
Response Payload
Property NameTypeDescription
idTokenstringAn Identity Platform ID token for the newly created user.
emailstringThe email for the newly created user.
refreshTokenstringAn Identity Platform refresh token for the newly created user.
expiresInstringThe number of seconds in which the ID token expires.
localIdstringThe uid of the newly created user.

Sample request

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

A successful request is indicated by a 200 OK HTTP status code. The response contains the Identity Platform ID token and refresh token associated with the new account.

Sample response

{"idToken":"[ID_TOKEN]","email":"[user@example.com]","refreshToken":"[REFRESH_TOKEN]","expiresIn":"3600","localId":"tRcfmLH7..."}

Common error codes

  • EMAIL_EXISTS: The email address is already in use by another account.
  • OPERATION_NOT_ALLOWED: Password sign-in is disabled for this project.
  • TOO_MANY_ATTEMPTS_TRY_LATER: We have blocked all requests from this device due to unusual activity. Try again later.

Sign in with email / password

You can sign in a user with an email and password by issuing an HTTP POST request to the Auth verifyPassword endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
emailstringThe email the user is signing in with.
passwordstringThe password for the account.
returnSecureTokenbooleanWhether or not to return an ID and refresh token. Should always be true.
tenantIdstringThe tenant ID the user is signing into. Only used in multi-tenancy.
Response Payload
Property NameTypeDescription
idTokenstringAn Identity Platform ID token for the authenticated user.
emailstringThe email for the authenticated user.
refreshTokenstringAn Identity Platform refresh token for the authenticated user.
expiresInstringThe number of seconds in which the ID token expires.
localIdstringThe uid of the authenticated user.
registeredbooleanWhether the email is for an existing account.

Sample request

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}'

A successful request is indicated by a 200 OK HTTP status code. The response contains the Identity Platform ID token and refresh token associated with the existing email/password account.

Sample response

{"localId":"ZY1rJK0eYLg...","email":"[user@example.com]","displayName":"","idToken":"[ID_TOKEN]","registered":true,"refreshToken":"[REFRESH_TOKEN]","expiresIn":"3600"}

Common error codes

  • EMAIL_NOT_FOUND: There is no user record corresponding to this identifier. The user may have been deleted.
  • INVALID_PASSWORD: The password is invalid or the user does not have a password.
  • USER_DISABLED: The user account has been disabled by an administrator.

Sign in anonymously

You can sign in a user anonymously by issuing an HTTP POST request to the Auth signupNewUser endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
returnSecureTokenbooleanWhether or not to return an ID and refresh token. Should always be true.
tenantIdstringThe tenant ID the user is signing into. Only used in multi-tenancy.
Response Payload
Property NameTypeDescription
idTokenstringAn Identity Platform ID token for the newly created user.
emailstringSince the user is anonymous, this should be empty.
refreshTokenstringAn Identity Platform refresh token for the newly created user.
expiresInstringThe number of seconds in which the ID token expires.
localIdstringThe uid of the newly created user.

Sample request

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

A successful request is indicated by a 200 OK HTTP status code. The response contains the Identity Platform ID token and refresh token associated with the anonymous user.

Sample response

{"idToken":"[ID_TOKEN]","email":"","refreshToken":"[REFRESH_TOKEN]","expiresIn":"3600","localId":"Jws4SVjpT..."}

Common error codes

  • OPERATION_NOT_ALLOWED: Anonymous user sign-in is disabled for this project.

Sign in with OAuth credential

You can sign in a user with an OAuth credential by issuing an HTTP POST request to the Auth verifyAssertion endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
requestUristringThe URI to which the IDP redirects the user back.
postBodystringContains the OAuth credential (an ID token or access token) and provider ID which issues the credential.
returnSecureTokenbooleanWhether or not to return an ID and refresh token. Should always be true.
returnIdpCredentialbooleanWhether to force the return of the OAuth credential on the following errors: FEDERATED_USER_ID_ALREADY_LINKED and EMAIL_EXISTS.
tenantIdstringThe tenant ID the user is signing into. Only used in multi-tenancy.
Response Payload
Property NameTypeDescription
federatedIdstringThe unique ID identifies the IdP account.
providerIdstringThe linked provider ID (e.g. "google.com" for the Google provider).
localIdstringThe uid of the authenticated user.
emailVerifiedbooleanWhether the sign-in email is verified.
emailstringThe email of the account.
oauthIdTokenstringThe OIDC id token if available.
oauthAccessTokenstringThe OAuth access token if available.
oauthTokenSecretstringThe OAuth 1.0 token secret if available.
rawUserInfostringThe stringified JSON response containing all the IdP data corresponding to the provided OAuth credential.
firstNamestringThe first name for the account.
lastNamestringThe last name for the account.
fullNamestringThe full name for the account.
displayNamestringThe display name for the account.
photoUrlstringThe photo Url for the account.
idTokenstringAn Identity Platform ID token for the authenticated user.
refreshTokenstringAn Identity Platform refresh token for the authenticated user.
expiresInstringThe number of seconds in which the ID token expires.
needConfirmationbooleanWhether another account with the same credential already exists. The user will need to sign in to the original account and then link the current credential to it.

Sample request with OAuth ID token

curl'https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=[API_KEY]'\ -H'Content-Type: application/json'\ --data-binary'{"postBody":"id_token=[GOOGLE_ID_TOKEN]&providerId=[google.com]","requestUri":"[http://localhost]","returnIdpCredential":true,"returnSecureToken":true}'

A successful request is indicated by a 200 OK HTTP status code. The response contains the Identity Platform ID token and refresh token associated with the authenticated user.

Sample response with OAuth ID token

{"federatedId":"https://accounts.google.com/1234567890","providerId":"google.com","localId":"5xwsPCWYo...","emailVerified":true,"email":"user@example.com","oauthIdToken":"[GOOGLE_ID_TOKEN]","firstName":"John","lastName":"Doe","fullName":"John Doe","displayName":"John Doe","idToken":"[ID_TOKEN]","photoUrl":"https://lh5.googleusercontent.com/.../photo.jpg","refreshToken":"[REFRESH_TOKEN]","expiresIn":"3600","rawUserInfo":"{\"updated_time\":\"2017-02-22T01:10:57+0000\",\"gender\":\"male\", ...}"}

Sample request with OAuth access token

curl'https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=[API_KEY]'\ -H'Content-Type: application/json'\ --data-binary'{"postBody":"access_token=[FACEBOOK_ACCESS_TOKEN]&providerId=[facebook.com]","requestUri":"[http://localhost]","returnIdpCredential":true,"returnSecureToken":true}'

A successful request is indicated by a 200 OK HTTP status code. The response contains the Identity Platform ID token and refresh token associated with the authenticated user.

Sample response with OAuth access token

{"federatedId":"http://facebook.com/1234567890","providerId":"facebook.com","localId":"5xwsPCWYo...","emailVerified":true,"email":"user@example.com","oauthAccessToken":"[FACEBOOK_ACCESS_TOKEN]","firstName":"John","lastName":"Doe","fullName":"John Doe","displayName":"John Doe","idToken":"[ID_TOKEN]","photoUrl":"https://scontent.xx.fbcdn.net/v/...","refreshToken":"[REFRESH_TOKEN]","expiresIn":"3600","rawUserInfo":"{\"updated_time\":\"2017-02-22T01:10:57+0000\",\"gender\":\"male\", ...}"}

Sample request with Twitter OAuth 1.0 credential

curl'https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=[API_KEY]'\ -H'Content-Type: application/json'\ --data-binary'{"postBody":"access_token=[TWITTER_ACCESS_TOKEN]&oauth_token_secret=[TWITTER_TOKEN_SECRET]&providerId=[twitter.com]","requestUri":"[http://localhost]","returnIdpCredential":true,"returnSecureToken":true}'

A successful request is indicated by a 200 OK HTTP status code. The response contains the Identity Platform ID token and refresh token associated with the authenticated user.

Sample response with Twitter OAuth 1.0 credential

{"federatedId":"http://twitter.com/1234567890", "providerId":"twitter.com", "localId":"5xwsPCWYo...", "emailVerified":true, "email":"user@example.com", "oauthAccessToken":"[OAUTH_ACCESS_TOKEN]", "oauthTokenSecret":"[OAUTH_TOKEN_SECRET]", "firstName":"John", "lastName":"Doe", "fullName":"John Doe", "displayName":"John Doe", "idToken":"[ID_TOKEN]", "photoUrl":"http://abs.twimg.com/sticky/...", "refreshToken":"[REFRESH_TOKEN]", "expiresIn":"3600", "rawUserInfo":"{\"updated_time\":\"2017-02-22T01:10:57+0000\",\"gender\":\"male\", ...}"}

Common error codes

  • OPERATION_NOT_ALLOWED: The corresponding provider is disabled for this project.
  • INVALID_IDP_RESPONSE: The supplied auth credential is malformed or has expired.

Fetch providers for email

You can look all providers associated with a specified email by issuing an HTTP POST request to the Auth createAuthUri endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:createAuthUri?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
identifierstringUser's email address
continueUristringThe URI to which the IDP redirects the user back. For this use case, this is just the current URL.
tenantIdstringThe tenant ID the user is signing into. Only used in multi-tenancy.
Response Payload
Property NameTypeDescription
allProvidersList of stringsThe list of providers that the user has previously signed in with.
registeredbooleanWhether the email is for an existing account

Sample request

curl'https://identitytoolkit.googleapis.com/v1/accounts:createAuthUri?key=[API_KEY]'\ -H'Content-Type: application/json'\ --data-binary'{"identifier":"[user@example.com]","continueUri":"[http://localhost:8080/app]"}'

A successful request is indicated by a 200 OK HTTP status code. The response contains the list of providers associated with the email.

Sample response

{"allProviders":["password","google.com"],"registered":true}

Common error codes

  • INVALID_EMAIL: The email address is badly formatted.

Send password reset email

You can send a password reset email by issuing an HTTP POST request to the Auth getOobConfirmationCode endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=[API_KEY]
Optional Headers
Property NameDescription
X-Firebase-Locale The language code corresponding to the user's locale. Passing this will localize the password reset email sent to the user.
Request Body Payload
Property NameTypeDescription
requestTypestringThe kind of OOB code to return. Should be "PASSWORD_RESET" for password reset.
emailstringUser's email address.
tenantIdstringThe tenant ID of the user requesting password reset. Only used in multi-tenancy.
Response Payload
Property NameTypeDescription
emailstringUser's email address.

Sample request

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

A successful request is indicated by a 200 OK HTTP status code.

Sample response

{"email":"[user@example.com]"}

Common error codes

  • EMAIL_NOT_FOUND: There is no user record corresponding to this identifier. The user may have been deleted.

Verify password reset code

You can verify a password reset code by issuing an HTTP POST request to the Auth resetPassword endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:resetPassword?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
oobCodestringThe email action code sent to the user's email for resetting the password.
tenantIdstringThe tenant ID of the user requesting password reset. Only used in multi-tenancy.
Response Payload
Property NameTypeDescription
emailstringUser's email address.
requestTypestringType of the email action code. Should be "PASSWORD_RESET".

Sample request

curl'https://identitytoolkit.googleapis.com/v1/accounts:resetPassword?key=[API_KEY]'\ -H'Content-Type: application/json'--data-binary'{"oobCode":"[PASSWORD_RESET_CODE]"}'

A successful request is indicated by a 200 OK HTTP status code.

Sample response

{"email":"[user@example.com]","requestType":"PASSWORD_RESET"}

Common error codes

  • OPERATION_NOT_ALLOWED: Password sign-in is disabled for this project.
  • EXPIRED_OOB_CODE: The action code has expired.
  • INVALID_OOB_CODE: The action code is invalid. This can happen if the code is malformed, expired, or has already been used.

Confirm password reset

You can apply a password reset change by issuing an HTTP POST request to the Auth resetPassword endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:resetPassword?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
oobCodestringThe email action code sent to the user's email for resetting the password.
newPasswordstringThe user's new password.
tenantIdstringThe tenant ID of the user requesting password reset. Only used in multi-tenancy.
Response Payload
Property NameTypeDescription
emailstringUser's email address.
requestTypestringType of the email action code. Should be "PASSWORD_RESET".

Sample request

curl'https://identitytoolkit.googleapis.com/v1/accounts:resetPassword?key=[API_KEY]'\ -H'Content-Type: application/json'\ --data-binary'{"oobCode":"[PASSWORD_RESET_CODE]","newPassword":"[NEW_PASSWORD]"}'

A successful request is indicated by a 200 OK HTTP status code.

Sample response

{"email":"[user@example.com]","requestType":"PASSWORD_RESET"}

Common error codes

  • OPERATION_NOT_ALLOWED: Password sign-in is disabled for this project.
  • EXPIRED_OOB_CODE: The action code has expired.
  • INVALID_OOB_CODE: The action code is invalid. This can happen if the code is malformed, expired, or has already been used.
  • USER_DISABLED: The user account has been disabled by an administrator.

Change email

You can change a user's email by issuing an HTTP POST request to the Auth setAccountInfo endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:update?key=[API_KEY]
Optional Headers
Property NameDescription
X-Firebase-Locale The language code corresponding to the user's locale. Passing this will localize the email change revocation sent to the user.
Request Body Payload
Property NameTypeDescription
idTokenstringAn Identity Platform ID token for the user.
emailstringThe user's new email.
returnSecureTokenbooleanWhether or not to return an ID and refresh token.
Response Payload
Property NameTypeDescription
localIdstringThe uid of the current user.
emailstringUser's email address.
passwordHashstringHash version of the password.
providerUserInfoList of JSON objectsList of all linked provider objects which contain "providerId" and "federatedId".
idTokenstringNew Identity Platform ID token for user.
refreshTokenstringAn Identity Platform refresh token.
expiresInstringThe number of seconds in which the ID token expires.

Sample request

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

A successful request is indicated by a 200 OK HTTP status code. The response contains the new Identity Platform ID token and refresh token associated with the user.

Sample response

{"localId":"tRcfmLH7o2...","email":"[user@example2.com]","passwordHash":"...","providerUserInfo":[{"providerId":"password","federatedId":"[user@example2.com]"}],"idToken":"[NEW_ID_TOKEN]","refreshToken":"[NEW_REFRESH_TOKEN]","expiresIn":"3600"}

Common error codes

  • EMAIL_EXISTS: The email address is already in use by another account.
  • INVALID_ID_TOKEN:The user's credential is no longer valid. The user must sign in again.

Change password

You can change a user's password by issuing an HTTP POST request to the Auth setAccountInfo endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:update?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
idTokenstringAn Identity Platform ID token for the user.
passwordstringUser's new password.
returnSecureTokenbooleanWhether or not to return an ID and refresh token.
Response Payload
Property NameTypeDescription
localIdstringThe uid of the current user.
emailstringUser's email address.
passwordHashstringHash version of password.
providerUserInfoList of JSON objectsList of all linked provider objects which contain "providerId" and "federatedId".
idTokenstringNew Identity Platform ID token for user.
refreshTokenstringAn Identity Platform refresh token.
expiresInstringThe number of seconds in which the ID token expires.

Sample request

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

A successful request is indicated by a 200 OK HTTP status code. The response contains the new Identity Platform ID token and refresh token associated with the user.

Sample response

{"localId":"tRcfmLH7o2...","email":"[user@example.com]","passwordHash":"...","providerUserInfo":[{"providerId":"password","federatedId":"[user@example.com]"}],"idToken":"[NEW_ID_TOKEN]","refreshToken":"[NEW_REFRESH_TOKEN]","expiresIn":"3600"}

Common error codes

  • INVALID_ID_TOKEN:The user's credential is no longer valid. The user must sign in again.
  • WEAK_PASSWORD: The password must be 6 characters long or more.

Update profile

You can update a user's profile (display name / photo URL) by issuing an HTTP POST request to the Auth setAccountInfo endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:update?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
idTokenstringAn Identity Platform ID token for the user.
displayNamestringUser's new display name.
photoUrlstringUser's new photo url.
deleteAttributeList of stringsList of attributes to delete, "DISPLAY_NAME" or "PHOTO_URL". This will nullify these values.
returnSecureTokenbooleanWhether or not to return an ID and refresh token.
Response Payload
Property NameTypeDescription
localIdstringThe uid of the current user.
emailstringUser's email address.
displayNamestringUser's new display name.
photoUrlstringUser's new photo url.
passwordHashstringHash version of password.
providerUserInfoList of JSON objectsList of all linked provider objects which contain "providerId" and "federatedId".
idTokenstringNew Identity Platform ID token for user.
refreshTokenstringAn Identity Platform refresh token.
expiresInstringThe number of seconds in which the ID token expires.

Sample request

curl'https://identitytoolkit.googleapis.com/v1/accounts:update?key=[API_KEY]'\ -H'Content-Type: application/json'\ --data-binary\'{"idToken":"[ID_TOKEN]","displayName":"[NAME]","photoUrl":"[URL]","returnSecureToken":true}'

A successful request is indicated by a 200 OK HTTP status code.

Sample response

{"localId":"tRcfmLH...","email":"user@example2.com","displayName":"John Doe","photoUrl":"[http://localhost:8080/img1234567890/photo.png]","passwordHash":"...","providerUserInfo":[{"providerId":"password","federatedId":"user@example2.com","displayName":"John Doe","photoUrl":"http://localhost:8080/img1234567890/photo.png"}],"idToken":"[NEW_ID_TOKEN]","refreshToken":"[NEW_REFRESH_TOKEN]","expiresIn":"3600"}

Common error codes

  • INVALID_ID_TOKEN:The user's credential is no longer valid. The user must sign in again.

Get user data

You can get a user's data by issuing an HTTP POST request to the Auth getAccountInfo endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
idTokenstringThe Identity Platform ID token of the account.
Response Payload
Property NameTypeDescription
usersList of JSON objectsThe account associated with the given Identity Platform ID token. Check below for more details.
Response Payload (users array content)
Property NameTypeDescription
localIdstringThe uid of the current user.
emailstringThe email of the account.
emailVerifiedbooleanWhether or not the account's email has been verified.
displayNamestringThe display name for the account.
providerUserInfoList of JSON objectsList of all linked provider objects which contain "providerId" and "federatedId".
photoUrlstringThe photo Url for the account.
passwordHashstringHash version of password.
passwordUpdatedAtdoubleThe timestamp, in milliseconds, that the account password was last changed.
validSincestringThe timestamp, in seconds, which marks a boundary, before which Identity Platform ID tokens are considered revoked.
disabledbooleanWhether the account is disabled or not.
lastLoginAtstringThe timestamp, in milliseconds, that the account last logged in at.
createdAtstringThe timestamp, in milliseconds, that the account was created at.
customAuthbooleanWhether the account is authenticated by the developer.
tenantIdstringThe tenant ID of the user. Only returned in multi-tenancy.

Sample request

curl'https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=[API_KEY]'\ -H'Content-Type: application/json'--data-binary'{"idToken":"[GCIP_ID_TOKEN]"}'

A successful request is indicated by a 200 OK HTTP status code. The response will contain all the user information associated with the account.

Sample response

{"users":[{"localId":"ZY1rJK0...","email":"user@example.com","emailVerified":false,"displayName":"John Doe","providerUserInfo":[{"providerId":"password","displayName":"John Doe","photoUrl":"http://localhost:8080/img1234567890/photo.png","federatedId":"user@example.com","email":"user@example.com","rawId":"user@example.com","screenName":"user@example.com"}],"photoUrl":"https://lh5.googleusercontent.com/.../photo.jpg","passwordHash":"...","passwordUpdatedAt":1.484124177E12,"validSince":"1484124177","disabled":false,"lastLoginAt":"1484628946000","createdAt":"1484124142000","customAuth":false}]}

Common error codes

  • INVALID_ID_TOKEN:The user's credential is no longer valid. The user must sign in again.
  • USER_NOT_FOUND: There is no user record corresponding to this identifier. The user may have been deleted.

You can link an email/password to a current user by issuing an HTTP POST request to the Auth setAccountInfo endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:update?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
idTokenstringThe Identity Platform ID token of the account you are trying to link the credential to.
emailstringThe email to link to the account.
passwordstringThe new password of the account.
returnSecureTokenstringWhether or not to return an ID and refresh token. Should always be true.
Response Payload
Property NameTypeDescription
localIdstringThe uid of the current user.
emailstringThe email of the account.
displayNamestringThe display name for the account.
photoUrlstringThe photo Url for the account.
passwordHashstringHash version of password.
providerUserInfoList of JSON objectsList of all linked provider objects which contain "providerId" and "federatedId".
emailVerifiedbooleanWhether or not the account's email has been verified.
idTokenstringNew Identity Platform ID token for user.
refreshTokenstringAn Identity Platform refresh token.
expiresInstringThe number of seconds in which the ID token expires.

Sample request

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

A successful request is indicated by a 200 OK HTTP status code. The response contains the Identity Platform ID token and refresh token associated with the authenticated user.

Sample response

{"localId":"huDwUz...","email":"user@example.com","displayName":"John Doe","photoUrl":"https://lh5.googleusercontent.com/.../photo.jpg","passwordHash":"...","providerUserInfo":[{"providerId":"password","federatedId":"user@example.com"}],"idToken":"[ID_TOKEN]","refreshToken":"[REFRESH_TOKEN]","expiresIn":"3600","emailVerified":false}

Common error codes

  • CREDENTIAL_TOO_OLD_LOGIN_AGAIN: The user's credential is no longer valid. The user must sign in again.
  • TOKEN_EXPIRED: The user's credential is no longer valid. The user must sign in again.
  • INVALID_ID_TOKEN:The user's credential is no longer valid. The user must sign in again.
  • WEAK_PASSWORD: The password must be 6 characters long or more.

You can link an OAuth credential to a user by issuing an HTTP POST request to the Auth verifyAssertion endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
idTokenstringThe Identity Platform ID token of the account you are trying to link the credential to.
requestUristringThe URI to which the IDP redirects the user back.
postBodystringContains the OAuth credential (an ID token or access token) and provider ID which issues the credential.
returnSecureTokenbooleanWhether or not to return an ID and refresh token. Should always be true.
returnIdpCredentialbooleanWhether to force the return of the OAuth credential on the following errors: FEDERATED_USER_ID_ALREADY_LINKED and EMAIL_EXISTS.
Response Payload
Property NameTypeDescription
federatedIdstringThe unique ID identifies the IdP account.
providerIdstringThe linked provider ID (e.g. "google.com" for the Google provider).
localIdstringThe uid of the authenticated user.
emailVerifiedbooleanWhether the signin email is verified.
emailstringThe email of the account.
oauthIdTokenstringThe OIDC id token if available.
oauthAccessTokenstringThe OAuth access token if available.
oauthTokenSecretstringThe OAuth 1.0 token secret if available.
rawUserInfostringThe stringified JSON response containing all the IdP data corresponding to the provided OAuth credential.
firstNamestringThe first name for the account.
lastNamestringThe last name for the account.
fullNamestringThe full name for the account.
displayNamestringThe display name for the account.
photoUrlstringThe photo Url for the account.
idTokenstringAn Identity Platform ID token for the authenticated user.
refreshTokenstringAn Identity Platform refresh token for the authenticated user.
expiresInstringThe number of seconds in which the ID token expires.

Sample request with OAuth ID token

curl'https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=[API_KEY]'\ -H'Content-Type: application/json'\ --data-binary'{"postBody":"id_token=[GOOGLE_ID_TOKEN]&providerId=[google.com]","requestUri":"[http://localhost]","idToken":"[GCIP_ID_TOKEN]","returnIdpCredential":true,"returnSecureToken":true}'

A successful request is indicated by a 200 OK HTTP status code. The response contains the Identity Platform ID token and refresh token associated with the authenticated user.

Sample response with OAuth ID token

{"federatedId":"https://accounts.google.com/1234567890","providerId":"google.com","localId":"5xwsPCWYo...","emailVerified":true,"email":"user@example.com","oauthIdToken":"[GOOGLE_ID_TOKEN]","firstName":"John","lastName":"Doe","fullName":"John Doe","displayName":"John Doe","idToken":"[ID_TOKEN]","photoUrl":"https://lh5.googleusercontent.com/.../photo.jpg","refreshToken":"[REFRESH_TOKEN]","expiresIn":"3600","rawUserInfo":"{\"updated_time\":\"2017-02-22T01:10:57+0000\",\"gender\":\"male\", ...}"}

Sample request with OAuth access token

curl'https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=[API_KEY]'\ -H'Content-Type: application/json'\ --data-binary'{"postBody":"access_token=[FACEBOOK_ACCESS_TOKEN]&providerId=[facebook.com]","idToken":"[GCIP_ID_TOKEN]","requestUri":"[http://localhost]","returnIdpCredential":true,"returnSecureToken":true}'

A successful request is indicated by a 200 OK HTTP status code. The response contains the Identity Platform ID token and refresh token associated with the authenticated user.

Sample response with OAuth access token

{"federatedId":"http://facebook.com/1234567890","providerId":"facebook.com","localId":"5xwsPCWYo...","emailVerified":true,"email":"user@example.com","oauthAccessToken":"[FACEBOOK_ACCESS_TOKEN]","firstName":"John","lastName":"Doe","fullName":"John Doe","displayName":"John Doe","idToken":"[ID_TOKEN]","photoUrl":"https://scontent.xx.fbcdn.net/v/...","refreshToken":"[REFRESH_TOKEN]","expiresIn":"3600","rawUserInfo":"{\"updated_time\":\"2017-02-22T01:10:57+0000\",\"gender\":\"male\", ...}"}

Sample request with Twitter OAuth 1.0 credential

curl'https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=[API_KEY]'\ -H'Content-Type: application/json'\ --data-binary'{"postBody":"access_token=[TWITTER_ACCESS_TOKEN]&oauth_token_secret=[TWITTER_TOKEN_SECRET]&providerId=[twitter.com]","requestUri":"[http://localhost]","idToken":"[GCIP_ID_TOKEN]","returnIdpCredential":true,"returnSecureToken":true}'

A successful request is indicated by a 200 OK HTTP status code. The response contains the Identity Platform ID token and refresh token associated with the authenticated user.

Sample response with Twitter OAuth 1.0 credential

{"federatedId":"http://twitter.com/1234567890","providerId":"twitter.com","localId":"5xwsPCWYo...","emailVerified":true,"email":"user@example.com","oauthAccessToken":"[OAUTH_ACCESS_TOKEN]","oauthTokenSecret":"[OAUTH_TOKEN_SECRET]","firstName":"John","lastName":"Doe","fullName":"John Doe","displayName":"John Doe","idToken":"[ID_TOKEN]","photoUrl":"http://abs.twimg.com/sticky/...","refreshToken":"[REFRESH_TOKEN]","expiresIn":"3600","rawUserInfo":"{\"updated_time\":\"2017-02-22T01:10:57+0000\",\"gender\":\"male\", ...}"}

Common error codes

  • OPERATION_NOT_ALLOWED: The corresponding provider is disabled for this project.
  • INVALID_IDP_RESPONSE: The supplied auth credential is malformed or has expired.
  • INVALID_ID_TOKEN:The user's credential is no longer valid. The user must sign in again.
  • EMAIL_EXISTS: The email address is already in use by another account.
  • FEDERATED_USER_ID_ALREADY_LINKED: This credential is already associated with a different user account.

You can unlink a provider from a current user by issuing an HTTP POST request to the Auth setAccountInfo endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:update?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
idTokenstringThe Identity Platform ID token of the account.
deleteProviderList of stringsThe list of provider IDs to unlink, eg: 'google.com', 'password', etc.
Response Payload
Property NameTypeDescription
localIdstringThe uid of the current user.
emailstringThe email of the account.
displayNamestringThe display name for the account.
photoUrlstringThe photo Url for the account.
passwordHashstringHash version of the password.
providerUserInfoList of JSON objectsList of all linked provider objects which contain "providerId" and "federatedId".
emailVerifiedbooleanWhether or not the account's email has been verified.

Sample request

curl'https://identitytoolkit.googleapis.com/v1/accounts:update?key=[API_KEY]'\ -H'Content-Type: application/json'\ --data-binary'{"idToken":"[GCIP_ID_TOKEN]","deleteProvider":["[facebook.com]"]}'

A successful request is indicated by a 200 OK HTTP status code.

Sample response

{"localId":"huDwUz...","email":"user@example.com","displayName":"John Doe","photoUrl":"https://lh5.googleusercontent.com/.../photo.jpg","passwordHash":"...","providerUserInfo":[{"providerId":"google.com","federatedId":"1234567890","displayName":"John Doe","photoUrl":"https://lh5.googleusercontent.com/.../photo.jpg"},{"providerId":"password","federatedId":"user@example.com"}],"emailVerified":"true"}

Common error codes

  • INVALID_ID_TOKEN: The user's credential is no longer valid. The user must sign in again.

Send email verification

You can send an email verification for the current user by issuing an HTTP POST request to the Auth getOobConfirmationCode endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=[API_KEY]
Optional Headers
Property NameDescription
X-Firebase-Locale The language code corresponding to the user's locale. Passing this will localize the email verification sent to the user.
Request Body Payload
Property NameTypeDescription
requestTypestringThe type of confirmation code to send. Should always be "VERIFY_EMAIL".
idTokenstringThe Identity Platform ID token of the user to verify.
Response Payload
Property NameTypeDescription
emailstringThe email of the account.

Sample request

curl'https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=[API_KEY]'\ -H'Content-Type: application/json'\ --data-binary'{"requestType":"VERIFY_EMAIL","idToken":"[GCIP_ID_TOKEN]"}'

A successful request is indicated by a 200 OK HTTP status code.

Sample response

{"email":"user@example.com"}

Common error codes

  • INVALID_ID_TOKEN: The user's credential is no longer valid. The user must sign in again.
  • USER_NOT_FOUND: There is no user record corresponding to this identifier. The user may have been deleted.

Confirm email verification

You can confirm an email verification code by issuing an HTTP POST request to the Auth setAccountInfo endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:update?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
oobCodestringThe action code sent to user's email for email verification.
tenantIdstringThe tenant ID of the user verifying the email. Only used in multi-tenancy.
Response Payload
Property NameTypeDescription
emailstringThe email of the account.
displayNamestringThe display name for the account.
photoUrlstringThe photo Url for the account.
passwordHashstringThe password hash.
providerUserInfoList of JSON objectsList of all linked provider objects which contain "providerId" and "federatedId".
emailVerifiedbooleanWhether or not the account's email has been verified.

Sample request

curl'https://identitytoolkit.googleapis.com/v1/accounts:update?key=[API_KEY]'\ -H'Content-Type: application/json'--data-binary'{"oobCode":"[VERIFICATION_CODE]"}'

A successful request is indicated by a 200 OK HTTP status code.

Sample response

{"localId":"FhyStE...","email":"user@example.com","passwordHash":"...","providerUserInfo":[{"providerId":"password","federatedId":"user@example.com"}]}

Common error codes

  • EXPIRED_OOB_CODE: The action code has expired.
  • INVALID_OOB_CODE: The action code is invalid. This can happen if the code is malformed, expired, or has already been used.
  • USER_DISABLED: The user account has been disabled by an administrator.
  • EMAIL_NOT_FOUND: There is no user record corresponding to this identifier. The user may have been deleted.

Delete account

You can delete a current user by issuing an HTTP POST request to the Auth deleteAccount endpoint.

Method: POST

Content-Type: application/json

Endpoint
https://identitytoolkit.googleapis.com/v1/accounts:delete?key=[API_KEY]
Request Body Payload
Property NameTypeDescription
idTokenstringThe Identity Platform ID token of the user to delete.
Response Payload
Property NameTypeDescription

Sample request

curl'https://identitytoolkit.googleapis.com/v1/accounts:delete?key=[API_KEY]'\ -H'Content-Type: application/json'--data-binary'{"idToken":"[GCIP_ID_TOKEN]"}'

A successful request is indicated by a 200 OK HTTP status code.

Common error codes

  • INVALID_ID_TOKEN:The user's credential is no longer valid. The user must sign in again.
  • USER_NOT_FOUND: There is no user record corresponding to this identifier. The user may have been deleted.

Handling errors

The following is an example of a common error returned by Identity Platform:

{ "error": { "errors": [ { "domain": "global", "reason": "invalid", "message": "CREDENTIAL_TOO_OLD_LOGIN_AGAIN" } ], "code": 400, "message": "CREDENTIAL_TOO_OLD_LOGIN_AGAIN" } } 

Obtain the error code from the message field.