A cross platform plugin for Firebase Authentication. A wrapper for Xamarin.Firebase.iOS.Auth and Xamarin.Firebase.Auth.
Install Nuget package to each projects.
- Add GoogleService-Info.plist to iOS project. Select BundleResource as build action.
- Initialize as follows in AppDelegate.
Firebase.Core.App.Configure();
- Add google-services.json to Android project. Select GoogleServicesJson as build action. (If you can't select GoogleServicesJson, reload this android project.)
- This Plugin uses Plugin.CurrentActivity. Setup as follows in MainActivity.
Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);
var result = await CrossFirebaseAuth.Current.Instance.CreateUserWithEmailAndPasswordAsync(email, password);
var result = await CrossFirebaseAuth.Current.Instance.SignInWithEmailAndPasswordAsync(email, password);
var credential = CrossFirebaseAuth.Current.GoogleAuthProvider.GetCredential(idToken, accessToken);
var result = await CrossFirebaseAuth.Current.Instance.SignInWithCredentialAsync(credential);
var credential = CrossFirebaseAuth.Current.FacebookAuthProvider.GetCredential(accessToken);
var result = await CrossFirebaseAuth.Current.Instance.SignInWithCredentialAsync(credential);
var credential = CrossFirebaseAuth.Current.TwitterAuthProvider.GetCredential(token, secret);
var result = await CrossFirebaseAuth.Current.Instance.SignInWithCredentialAsync(credential);
var credential = CrossFirebaseAuth.Current.GitHubAuthProvider.GetCredential(token);
var result = await CrossFirebaseAuth.Current.Instance.SignInWithCredentialAsync(credential);
var verificationResult = await CrossFirebaseAuth.Current.PhoneAuthProvider.VerifyPhoneNumberAsync(CrossFirebaseAuth.Current.Instance, phoneNumber);
var credential = CrossFirebaseAuth.Current.PhoneAuthProvider.GetCredential(CrossFirebaseAuth.Current.Instance, verificationResult.VerificationId, verificationCode);
var result = await CrossFirebaseAuth.Current.Instance.SignInWithCredentialAsync(credential);
var user = await CrossFirebaseAuth.Current.Instance.SignInWithCustomTokenAsync(token);
var result = await CrossFirebaseAuth.Current.Instance.SignInAnonymouslyAsync()
AuthState event invokes when there is a change in the authentication state.
CrossFirebaseAuth.Current.Instance.AuthState += (sender, e) =>
{
...
};
IdToken event invokes when the id token is changed.
CrossFirebaseAuth.Current.Instance.IdToken += (sender, e) =>
{
...
};
var user = CrossFirebaseAuth.Current.Instance.CurrentUser;
By using a listener
var registration = CrossFirebaseAuth.Current.Instance.AddAuthStateChangedListener(auth =>
{
var user = auth.CurrentUser;
});
var request = new UserProfileChangeRequest
{
DisplayName = displayName,
PhotoUrl = photoUrl
};
await CrossFirebaseAuth.Current.Instance.CurrentUser.UpdateProfileAsync(request);
await CrossFirebaseAuth.Current.Instance.CurrentUser.UpdateEmailAsync(email);
await CrossFirebaseAuth.Current.Instance.CurrentUser.SendEmailVerificationAsync();
await CrossFirebaseAuth.Current.Instance.CurrentUser.UpdatePasswordAsync(password);
await CrossFirebaseAuth.Current.Instance.SendPasswordResetEmailAsync(email);
await CrossFirebaseAuth.Current.Instance.CurrentUser.DeleteAsync();
var credential = CrossFirebaseAuth.Current.EmailAuthProvider.GetCredential(email, password);
await CrossFirebaseAuth.Current.Instance.CurrentUser.ReauthenticateAndRetrieveDataAsync(credential);
var credential = CrossFirebaseAuth.Current.GoogleAuthProvider.GetCredential(idToken, accessToken);
var result = await CrossFirebaseAuth.Current.Instance.CurrentUser.LinkWithCredentialAsync(credential);
await CrossFirebaseAuth.Current.Instance.CurrentUser.UnlinkAsync(CrossFirebaseAuth.Current.GoogleAuthProvider.ProviderId);
var actionCodeSettings = new ActionCodeSettings
{
Url = url,
IosBundleId = iosBundleId,
HandleCodeInApp = true
};
actionCodeSettings.SetAndroidPackageName(androidPackageName, true, null);
await CrossFirebaseAuth.Current.Instance.CurrentUser.SendEmailVerificationAsync(actionCodeSettings);
Reset password
var email = await CrossFirebaseAuth.Current.Instance.VerifyPasswordResetCodeAsync(code);
await CrossFirebaseAuth.Current.Instance.ConfirmPasswordResetAsync(code, newPassword);
Recover email
await CrossFirebaseAuth.Current.Instance.CheckActionCodeAsync(code);
await CrossFirebaseAuth.Current.Instance.ApplyActionCodeAsync(code);
Verify email
await CrossFirebaseAuth.Current.Instance.ApplyActionCodeAsync(code);
var result = await CrossFirebaseAuth.Current.GetInstance("SecondAppName").CreateUserWithEmailAndPasswordAsync(email, password);