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.

This class is not supported on tvOS and Desktop platforms.

The verification flow results in a PhoneAuthCredential 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).

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

Note: Both VerificationCompleted_DEPRECATED and VerificationCompleted will be triggered upon completion. Developer should only use only one of them to prevent duplicated event handling.

Inheritance

Inherits from: SystemIDisposable

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.
GetCredential_DEPRECATED(string verificationId, string verificationCode) Deprecated. This is a deprecated method. Please use GetCredential instead.
VerificationCompleted(PhoneAuthCredential credential)
delegate void
Callback used when phone number auto-verification succeeded.
VerificationCompleted_DEPRECATED(Credential credential)
delegate void
Deprecated. This is a deprecated delegate. Please use VerificationCompleted instead.
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_DEPRECATED verificationCompleted, VerificationFailed verificationFailed)
void
Deprecated. This is a deprecated method. Please use VerifyPhoneNumber(PhoneAuthOptions, VerificationCompleted, VerificationFailed, CodeSent, CodeAutoRetrievalTimeOut) instead.
VerifyPhoneNumber(string phoneNumber, uint autoVerifyTimeOutMs, ForceResendingToken forceResendingToken, VerificationCompleted_DEPRECATED verificationCompleted, VerificationFailed verificationFailed, CodeSent codeSent)
void
Deprecated. This is a deprecated method. Please use VerifyPhoneNumber(PhoneAuthOptions, VerificationCompleted, VerificationFailed, CodeSent, CodeAutoRetrievalTimeOut) instead.
VerifyPhoneNumber(string phoneNumber, uint autoVerifyTimeOutMs, ForceResendingToken forceResendingToken, VerificationCompleted_DEPRECATED verificationCompleted, VerificationFailed verificationFailed, CodeAutoRetrievalTimeOut codeAutoRetrievalTimeOut)
void
Deprecated. This is a deprecated method. Please use VerifyPhoneNumber(PhoneAuthOptions, VerificationCompleted, VerificationFailed, CodeSent, CodeAutoRetrievalTimeOut) instead.
VerifyPhoneNumber(string phoneNumber, uint autoVerifyTimeOutMs, ForceResendingToken forceResendingToken, VerificationCompleted_DEPRECATED verificationCompleted, VerificationFailed verificationFailed, CodeSent codeSent, CodeAutoRetrievalTimeOut codeAutoRetrievalTimeOut)
void
Deprecated. This is a deprecated method. Please use VerifyPhoneNumber(PhoneAuthOptions, VerificationCompleted, VerificationFailed, CodeSent, CodeAutoRetrievalTimeOut) instead.
VerifyPhoneNumber(PhoneAuthOptions options, 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.

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

PhoneAuthCredential 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

GetCredential_DEPRECATED

Credential GetCredential_DEPRECATED(
  string verificationId,
  string verificationCode
)

Deprecated. This is a deprecated method. Please use GetCredential instead.

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(
  PhoneAuthCredential credential
)

Callback used when phone number auto-verification succeeded.

VerificationCompleted_DEPRECATED

delegate void VerificationCompleted_DEPRECATED(
  Credential credential
)

Callback used when phone number auto-verification succeeded.

Deprecated. This is a deprecated delegate. Please use VerificationCompleted instead.

VerificationFailed

delegate void VerificationFailed(
  string error
)

Callback used when phone number verification fails.

VerifyPhoneNumber

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

Deprecated. This is a deprecated method. Please use VerifyPhoneNumber(PhoneAuthOptions, VerificationCompleted, VerificationFailed, CodeSent, CodeAutoRetrievalTimeOut) instead.

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. 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_DEPRECATED verificationCompleted,
  VerificationFailed verificationFailed,
  CodeSent codeSent
)

Deprecated. This is a deprecated method. Please use VerifyPhoneNumber(PhoneAuthOptions, VerificationCompleted, VerificationFailed, CodeSent, CodeAutoRetrievalTimeOut) instead.

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. 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_DEPRECATED verificationCompleted,
  VerificationFailed verificationFailed,
  CodeAutoRetrievalTimeOut codeAutoRetrievalTimeOut
)

Deprecated. This is a deprecated method. Please use VerifyPhoneNumber(PhoneAuthOptions, VerificationCompleted, VerificationFailed, CodeSent, CodeAutoRetrievalTimeOut) instead.

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. 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_DEPRECATED verificationCompleted,
  VerificationFailed verificationFailed,
  CodeSent codeSent,
  CodeAutoRetrievalTimeOut codeAutoRetrievalTimeOut
)

Deprecated. This is a deprecated method. Please use VerifyPhoneNumber(PhoneAuthOptions, VerificationCompleted, VerificationFailed, CodeSent, CodeAutoRetrievalTimeOut) instead.

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. 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.

VerifyPhoneNumber

void VerifyPhoneNumber(
  PhoneAuthOptions options,
  VerificationCompleted verificationCompleted,
  VerificationFailed verificationFailed,
  CodeSent codeSent,
  CodeAutoRetrievalTimeOut codeAutoRetrievalTimeOut
)

Start the phone number authentication operation.

Details
Parameters
options
The PhoneAuthOptions struct with a verification configuration.
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.