Firebase.Auth.FirebaseAuth

Firebase authentication object.

Summary

Firebase.Auth.FirebaseAuth is the gateway to the Firebase authentication API. With it, you can reference Firebase.Auth.FirebaseAuth objects to manage user accounts and credentials.

Each Firebase.FirebaseApp has up to one Firebase.Auth.FirebaseAuth class. You acquire the Firebase.Auth.FirebaseAuth class through the static function Firebase.Auth.FirebaseAuth.GetAuth.

For example:

// Get the Auth class for your App.
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.GetAuth(app);

// Request anonymous sign-in and wait until asynchronous call completes.
auth.SignInAnonymouslyAsync().ContinueWith((authTask) => {
// Print sign in results.
  if (authTask.IsCanceled) {
    DebugLog("Sign-in canceled.");
  } else if (authTask.IsFaulted) {
    DebugLog("Sign-in encountered an error.");
    DebugLog(authTask.Exception.ToString());
  } else if (authTask.IsCompleted) {
    Firebase.Auth.User user = authTask.Result;
    DebugLog(String.Format("Signed in as {0} user.",
        user.Anonymous ? "an anonymous" : "a non-anonymous"));
    DebugLog("Signing out.");
    auth.SignOut();
});

Inheritance

Inherits from: SystemIDisposable

Properties

App
Get the FirebaseApp associated with this object.
CurrentUser
Synchronously gets the cached current user, or null if there is none.
DefaultInstance
static FirebaseAuth
Returns the FirebaseAuth associated with FirebaseApp.DefaultApp.

Events

StateChanged
System.EventHandler
Event raised on changes in the authentication state.

Public functions

CreateUserWithEmailAndPasswordAsync(string email, string password)
Creates, and on success, logs in a user with the given email address and password.
Dispose()
void
FetchProvidersForEmailAsync(string email)
System.Threading.Tasks.Task< System.Collections.Generic.IEnumerable< string > >
Asynchronously requests the IDPs (identity providers) that can be used for the given email address.
SendPasswordResetEmailAsync(string email)
Initiates a password reset for the given email address.
SignInAnonymouslyAsync()
Asynchronously creates and becomes an anonymous user.
SignInWithCredentialAsync(Credential credential)
Asynchronously logs into Firebase with the given credentials.
SignInWithCustomTokenAsync(string token)
Asynchronously logs into Firebase with the given Auth token.
SignInWithEmailAndPasswordAsync(string email, string password)
Signs in using provided email address and password.
SignOut()
void
Removes any existing authentication credentials from this client.

Public static functions

GetAuth(FirebaseApp app)
Returns the FirebaseAuth object for an App.

Properties

App

FirebaseApp App

Get the FirebaseApp associated with this object.

Details
Returns
FirebaseApp associated with this object.

CurrentUser

FirebaseUser CurrentUser

Synchronously gets the cached current user, or null if there is none.

DefaultInstance

static FirebaseAuth DefaultInstance

Returns the FirebaseAuth associated with FirebaseApp.DefaultApp.

FirebaseAuth will be created if required.

Details
Exceptions
InitializationException
Thrown with the invalid InitResult if initialization failed.

Events

StateChanged

System.EventHandler StateChanged

Event raised on changes in the authentication state.

Authentication state changes are:

  • When a user signs in
  • When the current user signs out
  • When the current user changes
  • When there is a change in the current user's token

It is a recommended practice to always listen to sign-out events, as you may want to prompt the user to sign in again and maybe restrict the information or actions they have access to.

Public functions

CreateUserWithEmailAndPasswordAsync

System.Threading.Tasks.Task< FirebaseUser > CreateUserWithEmailAndPasswordAsync(
  string email,
  string password
)

Creates, and on success, logs in a user with the given email address and password.

An error is returned when account creation is unsuccessful (due to another existing account, invalid password, etc.).

Dispose

void Dispose()

FetchProvidersForEmailAsync

System.Threading.Tasks.Task< System.Collections.Generic.IEnumerable< string > > FetchProvidersForEmailAsync(
  string email
)

Asynchronously requests the IDPs (identity providers) that can be used for the given email address.

Useful for an "identifier-first" login flow.

// Print out all available providers for a given email.
void DisplayIdentityProviders(Firebase.Auth.FirebaseAuth auth,
                              String email) {
  auth.FetchProvidersForEmailAsync().ContinueWith((authTask) => {
    if (authTask.IsCanceled) {
      DebugLog("Provider fetch canceled.");
    } else if (authTask.IsFaulted) {
      DebugLog("Provider fetch encountered an error.");
      DebugLog(authTask.Exception.ToString());
    } else if (authTask.IsCompleted) {
      DebugLog("Email Providers:");
      foreach (string provider in authTask.result) {
        DebugLog(provider);
      }
    }
  });
}

SendPasswordResetEmailAsync

System.Threading.Tasks.Task SendPasswordResetEmailAsync(
  string email
)

Initiates a password reset for the given email address.

If the email address is not registered, then the returned task has a status of IsFaulted.

void ResetPassword(string email) {
  auth.SendPasswordResetEmail(email).ContinueWith((authTask) => {
    if (authTask.IsCanceled) {
      DebugLog("Password reset was canceled.");
    } else if (authTask.IsFaulted) {
      DebugLog("Password reset encountered an error.");
      DebugLog(authTask.Exception.ToString());
    } else if (authTask.IsCompleted) {
      DebugLog("Password reset successful!");
    }
  });
}  

SignInAnonymouslyAsync

System.Threading.Tasks.Task< FirebaseUser > SignInAnonymouslyAsync()

Asynchronously creates and becomes an anonymous user.

If there is already an anonymous user signed in, that user will be returned instead. If there is any other existing user, that user will be signed out.

bool SignIn(Firebase.Auth.FirebaseAuth auth) {
  auth.SignInAnonymouslyAsync().ContinueWith((authTask) => {
    if (authTask.IsCanceled) {
      DebugLog("Anonymous sign in canceled.");
    } else if (authTask.IsFaulted) {
      DebugLog("Anonymous sign in encountered an error.");
      DebugLog(authTask.Exception.ToString());
    } else if (authTask.IsCompleted) {
      DebugLog("Anonymous sign in successful!");
    }
  });
}  

SignInWithCredentialAsync

System.Threading.Tasks.Task< FirebaseUser > SignInWithCredentialAsync(
  Credential credential
)

Asynchronously logs into Firebase with the given credentials.

For example, a Facebook login access token, a Twitter token/token-secret pair).

An error is returned if the token is invalid, expired, or otherwise not accepted by the server.

SignInWithCustomTokenAsync

System.Threading.Tasks.Task< FirebaseUser > SignInWithCustomTokenAsync(
  string token
)

Asynchronously logs into Firebase with the given Auth token.

An error is returned, if the token is invalid, expired or otherwise not accepted by the server.

SignInWithEmailAndPasswordAsync

System.Threading.Tasks.Task< FirebaseUser > SignInWithEmailAndPasswordAsync(
  string email,
  string password
)

Signs in using provided email address and password.

An error is returned if the password is wrong or otherwise not accepted by the server.

SignOut

void SignOut()

Removes any existing authentication credentials from this client.

This function always succeeds.

Public static functions

GetAuth

FirebaseAuth GetAuth(
  FirebaseApp app
)

Returns the FirebaseAuth object for an App.

Creates the FirebaseAuth if required.

Details
Parameters
app
The FirebaseApp to use for the FirebaseAuth object.
Exceptions
InitializationException
Thrown with the invalid InitResult if initialization failed.

Send feedback about...

Need help? Visit our support page.