Firebase.Auth.PhoneAuthProvider

Use phone number text messages to authenticate.

Summary

Allows developers to use the phone number and SMS verification codes to authenticate a user.

The verification flow results in a Credential that can be used to,

  • Sign in to an existing phone number account/sign up with a new phone number
  • Link a phone number to a current user. This provider will be added to the user.
  • Update a phone number on an existing user.
  • Re-authenticate an existing user. This may be needed when a sensitive operation requires the user to be recently logged in.

Possible verification flows: (1) User manually enters verification code.

  • App calls VerifyPhoneNumber.
  • Web verification page is displayed to user where they may need to solve a CAPTCHA. [iOS only].
  • Auth server sends the verification code via SMS to the provided phone number. App receives verification id via CodeSent.
  • User receives SMS and enters verification code in app's GUI.
  • App uses user's verification code to call PhoneAuthProvider.GetCredential.

(2) SMS is automatically retrieved (Android only).

  • App calls VerifyPhoneNumber with timeout_ms > 0.
  • Auth server sends the verification code via SMS to the provided phone number.
  • SMS arrives and is automatically retrieved by the operating system. Credential is automatically created and passed to the app via VerificationCompleted.

(3) Phone number is instantly verified (Android only).

Inheritance

Inherits from: SystemIDisposable

Properties

MaxTimeoutMs
static uint
Maximum value of autoVerifyTimeOutMs in VerifyPhoneNumber.

Public functions

CodeAutoRetrievalTimeOut(string verificationId)
delegate void
Callback used when a timeout occurs.
CodeSent(string verificationId, ForceResendingToken forceResendingToken)
delegate void
Callback used when a verification code is sent to the given number.
Dispose()
void
GetCredential(string verificationId, string verificationCode)
Generate a credential for the given phone number.
VerificationCompleted(Credential credential)
delegate void
Callback used when phone number auto-verification succeeded.
VerificationFailed(string error)
delegate void
Callback used when phone number verification fails.
VerifyPhoneNumber(string phoneNumber, uint autoVerifyTimeOutMs, ForceResendingToken forceResendingToken, VerificationCompleted verificationCompleted, VerificationFailed verificationFailed)
void
Start the phone number authentication operation.
VerifyPhoneNumber(string phoneNumber, uint autoVerifyTimeOutMs, ForceResendingToken forceResendingToken, VerificationCompleted verificationCompleted, VerificationFailed verificationFailed, CodeSent codeSent)
void
Start the phone number authentication operation.
VerifyPhoneNumber(string phoneNumber, uint autoVerifyTimeOutMs, ForceResendingToken forceResendingToken, VerificationCompleted verificationCompleted, VerificationFailed verificationFailed, CodeAutoRetrievalTimeOut codeAutoRetrievalTimeOut)
void
Start the phone number authentication operation.
VerifyPhoneNumber(string phoneNumber, uint autoVerifyTimeOutMs, ForceResendingToken forceResendingToken, VerificationCompleted verificationCompleted, VerificationFailed verificationFailed, CodeSent codeSent, CodeAutoRetrievalTimeOut codeAutoRetrievalTimeOut)
void
Start the phone number authentication operation.

Public static functions

GetInstance(FirebaseAuth auth)
Return the PhoneAuthProvider for the specified auth.

Properties

MaxTimeoutMs

static uint MaxTimeoutMs

Maximum value of autoVerifyTimeOutMs in VerifyPhoneNumber.

VerifyPhoneNumber will automatically clamp values to this amount.

Public functions

CodeAutoRetrievalTimeOut

delegate void CodeAutoRetrievalTimeOut(
  string verificationId
)

Callback used when a timeout occurs.

CodeSent

delegate void CodeSent(
  string verificationId,
  ForceResendingToken forceResendingToken
)

Callback used when a verification code is sent to the given number.

Dispose

void Dispose()

GetCredential

Credential GetCredential(
  string verificationId,
  string verificationCode
)

Generate a credential for the given phone number.

Details
Parameters
verification_id
The id returned when sending the verification code. Sent to the caller via Listener::OnCodeSent.
verification_code
The verification code supplied by the user, most likely by a GUI where the user manually enters the code received in the SMS sent by VerifyPhoneNumber.
Returns

VerificationCompleted

delegate void VerificationCompleted(
  Credential credential
)

Callback used when phone number auto-verification succeeded.

VerificationFailed

delegate void VerificationFailed(
  string error
)

Callback used when phone number verification fails.

VerifyPhoneNumber

void VerifyPhoneNumber(
  string phoneNumber,
  uint autoVerifyTimeOutMs,
  ForceResendingToken forceResendingToken,
  VerificationCompleted verificationCompleted,
  VerificationFailed verificationFailed
)

Start the phone number authentication operation.

Details
Parameters
phoneNumber
The phone number identifier supplied by the user. Its format is normalized on the server, so it can be in any format here.
autoVerifyTimeOutMs
The time out for SMS auto retrieval, in miliseconds. Currently SMS auto retrieval is only supported on Android. If 0, do not do SMS auto retrieval. If positive, try to auto-retrieve the SMS verification code. If larger than MaxTimeoutMs, clamped to MaxTimeoutMs. When the time out is exceeded, codeAutoRetrievalTimeOut is called.
forceResendingToken
If NULL, assume this is a new phone number to verify. If not-NULL, bypass the verification session deduping and force resending a new SMS. This token is received by the CodeSent callback. This should only be used when the user presses a Resend SMS button.
verificationCompleted
Phone number auto-verification succeeded. Called when auto-sms-retrieval or instant validation succeeds. Provided with the completed credential.
verificationFailed
Phone number verification failed with an error. For example, quota exceeded or unknown phone number format. Provided with a description of the error.

VerifyPhoneNumber

void VerifyPhoneNumber(
  string phoneNumber,
  uint autoVerifyTimeOutMs,
  ForceResendingToken forceResendingToken,
  VerificationCompleted verificationCompleted,
  VerificationFailed verificationFailed,
  CodeSent codeSent
)

Start the phone number authentication operation.

Details
Parameters
phoneNumber
The phone number identifier supplied by the user. Its format is normalized on the server, so it can be in any format here.
autoVerifyTimeOutMs
The time out for SMS auto retrieval, in miliseconds. Currently SMS auto retrieval is only supported on Android. If 0, do not do SMS auto retrieval. If positive, try to auto-retrieve the SMS verification code. If larger than MaxTimeoutMs, clamped to MaxTimeoutMs. When the time out is exceeded, codeAutoRetrievalTimeOut is called.
forceResendingToken
If NULL, assume this is a new phone number to verify. If not-NULL, bypass the verification session deduping and force resending a new SMS. This token is received by the CodeSent callback. This should only be used when the user presses a Resend SMS button.
verificationCompleted
Phone number auto-verification succeeded. Called when auto-sms-retrieval or instant validation succeeds. Provided with the completed credential.
verificationFailed
Phone number verification failed with an error. For example, quota exceeded or unknown phone number format. Provided with a description of the error.
codeSent
SMS message with verification code sent to phone number. Provided with the verification id to pass along to GetCredential along with the sent code, and a token to use if the user requests another SMS message be sent.

VerifyPhoneNumber

void VerifyPhoneNumber(
  string phoneNumber,
  uint autoVerifyTimeOutMs,
  ForceResendingToken forceResendingToken,
  VerificationCompleted verificationCompleted,
  VerificationFailed verificationFailed,
  CodeAutoRetrievalTimeOut codeAutoRetrievalTimeOut
)

Start the phone number authentication operation.

Details
Parameters
phoneNumber
The phone number identifier supplied by the user. Its format is normalized on the server, so it can be in any format here.
autoVerifyTimeOutMs
The time out for SMS auto retrieval, in miliseconds. Currently SMS auto retrieval is only supported on Android. If 0, do not do SMS auto retrieval. If positive, try to auto-retrieve the SMS verification code. If larger than MaxTimeoutMs, clamped to MaxTimeoutMs. When the time out is exceeded, codeAutoRetrievalTimeOut is called.
forceResendingToken
If NULL, assume this is a new phone number to verify. If not-NULL, bypass the verification session deduping and force resending a new SMS. This token is received by the CodeSent callback. This should only be used when the user presses a Resend SMS button.
verificationCompleted
Phone number auto-verification succeeded. Called when auto-sms-retrieval or instant validation succeeds. Provided with the completed credential.
verificationFailed
Phone number verification failed with an error. For example, quota exceeded or unknown phone number format. Provided with a description of the error.

VerifyPhoneNumber

void VerifyPhoneNumber(
  string phoneNumber,
  uint autoVerifyTimeOutMs,
  ForceResendingToken forceResendingToken,
  VerificationCompleted verificationCompleted,
  VerificationFailed verificationFailed,
  CodeSent codeSent,
  CodeAutoRetrievalTimeOut codeAutoRetrievalTimeOut
)

Start the phone number authentication operation.

Details
Parameters
phoneNumber
The phone number identifier supplied by the user. Its format is normalized on the server, so it can be in any format here.
autoVerifyTimeOutMs
The time out for SMS auto retrieval, in miliseconds. Currently SMS auto retrieval is only supported on Android. If 0, do not do SMS auto retrieval. If positive, try to auto-retrieve the SMS verification code. If larger than MaxTimeoutMs, clamped to MaxTimeoutMs. When the time out is exceeded, codeAutoRetrievalTimeOut is called.
forceResendingToken
If NULL, assume this is a new phone number to verify. If not-NULL, bypass the verification session deduping and force resending a new SMS. This token is received by the CodeSent callback. This should only be used when the user presses a Resend SMS button.
verificationCompleted
Phone number auto-verification succeeded. Called when auto-sms-retrieval or instant validation succeeds. Provided with the completed credential.
verificationFailed
Phone number verification failed with an error. For example, quota exceeded or unknown phone number format. Provided with a description of the error.
codeSent
SMS message with verification code sent to phone number. Provided with the verification id to pass along to GetCredential along with the sent code, and a token to use if the user requests another SMS message be sent.
codeAutoRetrievalTimeOut
The timeout specified has expired. Provided with the verification id for the transaction that timed out.

Public static functions

GetInstance

PhoneAuthProvider GetInstance(
  FirebaseAuth auth
)

Return the PhoneAuthProvider for the specified auth.

Details
Parameters
auth
The Auth session for which we want to get a PhoneAuthProvider.
Returns
a PhoneAuthProvider for the given auth object.

Send feedback about...

Need help? Visit our support page.