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

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.
VerificationCompleted(PhoneAuthCredential credential)
delegate void
Callback used when phone number auto-verification succeeded.
VerificationFailed(string error)
delegate void
Callback used when phone number verification fails.
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

VerificationCompleted

delegate void VerificationCompleted(
  PhoneAuthCredential 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(
  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.