Method: accounts.signInWithPhoneNumber

Completes a phone number authentication attempt. If a user already exists with the given phone number, an ID token is minted for that user. Otherwise, a new user is created and associated with the phone number. This method may also be used to link a phone number to an existing user.

An API key is required in the request in order to identify the Google Cloud project.

HTTP request

POST https://identitytoolkit.googleapis.com/v1/accounts:signInWithPhoneNumber

The URL uses gRPC Transcoding syntax.

Request body

The request body contains data with the following structure:

JSON representation
{
  "sessionInfo": string,
  "phoneNumber": string,
  "code": string,
  "temporaryProof": string,
  "idToken": string
}
Fields
sessionInfo

string

Encrypted session information from the response of sendVerificationCode. In the case of authenticating with an SMS code this must be specified, but in the case of using a temporary proof it can be unspecified.

phoneNumber

string

The user's phone number to sign in with. This is necessary in the case of uing a temporary proof, in which case it must match the phone number that was authenticated in the request that generated the temporary proof. This field is ignored if a session info is passed.

code

string

User-entered verification code from an SMS sent to the user's phone.

temporaryProof

string

A proof of the phone number verification, provided from a previous signInWithPhoneNumber request. If this is passed, the caller must also pass in the phoneNumber field the phone number that was verified in the previous request.

idToken

string

A valid ID token for an Identity Platform account. If passed, this request will link the phone number to the user represented by this ID token if the phone number is not in use, or will reauthenticate the user if the phone number is already linked to the user.

Response body

If successful, the response body contains data with the following structure:

Response message for accounts.signInWithPhoneNumber.

JSON representation
{
  "idToken": string,
  "refreshToken": string,
  "expiresIn": string,
  "localId": string,
  "isNewUser": boolean,
  "temporaryProof": string,
  "phoneNumber": string,
  "temporaryProofExpiresIn": string
}
Fields
idToken

string

Identity Platform ID token for the authenticated user.

refreshToken

string

Refresh token for the authenticated user.

expiresIn

string (int64 format)

The number of seconds until the ID token expires.

localId

string

The id of the authenticated user. Present in the case of a successful authentication. In the case when the phone could be verified but the account operation could not be performed, a temporary proof will be returned instead.

isNewUser

boolean

Whether the authenticated user was created by this request.

temporaryProof

string

A proof of the phone number verification, provided if a phone authentication is successful but the user operation fails. This happens when the request tries to link a phone number to a user with an ID token or reauthenticate with an ID token but the phone number is linked to a different user.

phoneNumber

string

Phone number of the authenticated user. Always present in the response.

temporaryProofExpiresIn

string (int64 format)

The number of seconds until the temporary proof expires.

Authorization Scopes

Requires one of the following OAuth scopes:

  • https://www.googleapis.com/auth/identitytoolkit
  • https://www.googleapis.com/auth/cloud-platform

For more information, see the Authentication Overview.