I need to create a Xamarin Forms app that has Firebase Phone Auth. There is a package for Xamarin Firebase Authentication, with phone authentication, but there is no documentation for Xamarin Forms.
So far, for Android, I have:
public class FirebaseAuthenticator : IFirebaseAuthenticator
{
public async Task<string> RegisterWithPhoneNumber(string number)
{
PhoneAuthCallbacks phoneAuthCallbacks = new PhoneAuthCallbacks();
var user = await PhoneAuthProvider.Instance.VerifyPhoneNumber(number, 60, TimeUnit.Seconds, this, phoneAuthCallbacks);
return user;
}
}
My PhoneAuthCallbacks class:
public class PhoneAuthCallbacks : PhoneAuthProvider.OnVerificationStateChangedCallbacks
{
public override void OnVerificationCompleted(PhoneAuthCredential credential)
{
// This callback will be invoked in two situations:
// 1 - Instant verification. In some cases the phone number can be instantly
// verified without needing to send or enter a verification code.
// 2 - Auto-retrieval. On some devices Google Play services can automatically
// detect the incoming verification SMS and perform verification without
// user action.
FirebaseAuth.Instance.SignInWithCredential(credential);
System.Diagnostics.Debug.WriteLine("onVerificationCompleted");
}
public override void OnVerificationFailed(FirebaseException exception)
{
// This callback is invoked in an invalid request for verification is made,
// for instance if the the phone number format is not valid.
System.Diagnostics.Debug.WriteLine("onVerificationFailed: " + exception);
}
public override void OnCodeSent(string verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken)
{
// The SMS verification code has been sent to the provided phone number, we
// now need to ask the user to enter the code and then construct a credential
// by combining the code with a verification ID.
base.OnCodeSent(verificationId, forceResendingToken);
System.Diagnostics.Debug.WriteLine("onCodeSent" + verificationId);
}
}
But it doesn't work. In RegisterWithPhoneNumber, 'this' gives an error "Cannot convert from xx.Droid.FirebaseAuthenticator to Android.App.Activity"