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.
IdTokenChanged
System.EventHandler
Event raised on ID token changes.
LanguageCode
System.String
The user-facing language code for auth operations that can be internationalized, such as FirebaseUser.sendEmailVerification().
StateChanged
System.EventHandler
Event raised on changes in the authentication state.

Public functions

CreateUserWithEmailAndPasswordAsync(string email, string password)
async System.Threading.Tasks.Task< AuthResult >
Creates, and on success, logs in a user with the given email address and password.
CreateUserWithEmailAndPasswordAsync_DEPRECATED(string email, string password)
async System.Threading.Tasks.Task< FirebaseUser >
Deprecated. This method is deprecated in favor of methods that return Task<AuthResult>. Please use Task<AuthResult> CreateUserWithEmailAndPasswordAsync(string, string) instead.
Dispose()
void
Dispose(bool disposing)
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)
System.Threading.Tasks.Task
SignInAndRetrieveDataWithCredentialAsync(Credential credential)
async System.Threading.Tasks.Task< AuthResult >
Asynchronously logs into Firebase with the given credentials.
SignInAndRetrieveDataWithCredentialAsync_DEPRECATED(Credential credential)
async System.Threading.Tasks.Task< SignInResult >
Deprecated. This method is deprecated in favor of methods that return Task<AuthResult>. Please use SignInAndRetrieveDataWithCredentialAsync(Credential) instead.
SignInAnonymouslyAsync()
async System.Threading.Tasks.Task< AuthResult >
Asynchronously creates and becomes an anonymous user.
SignInAnonymouslyAsync_DEPRECATED()
async System.Threading.Tasks.Task< FirebaseUser >
Deprecated. This method is deprecated in favor of methods that return Task<AuthResult>. Please use SignInAnonymouslyAsync() instead.
SignInWithCredentialAsync(Credential credential)
async System.Threading.Tasks.Task< FirebaseUser >
Asynchronously logs into Firebase with the given Auth token.
SignInWithCredentialAsync_DEPRECATED(Credential credential)
async System.Threading.Tasks.Task< FirebaseUser >
SignInWithCustomTokenAsync(string token)
async System.Threading.Tasks.Task< AuthResult >
Asynchronously logs into Firebase with the given Auth token.
SignInWithCustomTokenAsync_DEPRECATED(string token)
async System.Threading.Tasks.Task< FirebaseUser >
Deprecated. This method is deprecated in favor of methods that return Task<AuthResult>. Please use SignInWithCustomTokenAsync(string) instead.
SignInWithEmailAndPasswordAsync(string email, string password)
async System.Threading.Tasks.Task< AuthResult >
Signs in using provided email address and password.
SignInWithEmailAndPasswordAsync_DEPRECATED(string email, string password)
async System.Threading.Tasks.Task< FirebaseUser >
Deprecated. This method is deprecated in favor of methods that return Task<AuthResult>. Please use Task<AuthResult> SignInAnonymouslyAsync() instead.
SignInWithProviderAsync(FederatedAuthProvider provider)
async System.Threading.Tasks.Task< AuthResult >
Sign-in a user authenticated via a federated auth provider.
SignInWithProviderAsync_DEPRECATED(FederatedAuthProvider provider)
async System.Threading.Tasks.Task< SignInResult >
Deprecated. This method is deprecated in favor of methods that return Task<AuthResult>. Please use SignInWithProviderAsync(FederatedAuthProvider) instead.
SignOut()
void
UseAppLanguage()
void

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.

IdTokenChanged

System.EventHandler IdTokenChanged

Event raised on ID token changes.

Authentication ID token changes are:

  • Right after the listener has been registered
  • 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

LanguageCode

System.String LanguageCode

The user-facing language code for auth operations that can be internationalized, such as FirebaseUser.sendEmailVerification().

This language code should follow the conventions defined by the IETF in BCP 47.

StateChanged

System.EventHandler StateChanged

Event raised on changes in the authentication state.

Authentication state changes are:

  • Right after the listener has been registered
  • When a user signs in
  • When the current user signs out
  • When the current user changes

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

async System.Threading.Tasks.Task< AuthResult > 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.).

CreateUserWithEmailAndPasswordAsync_DEPRECATED

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

Deprecated. This method is deprecated in favor of methods that return Task<AuthResult>. Please use Task<AuthResult> CreateUserWithEmailAndPasswordAsync(string, string) instead.

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

Dispose

void Dispose(
  bool disposing
)

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
)

SignInAndRetrieveDataWithCredentialAsync

async System.Threading.Tasks.Task< AuthResult > SignInAndRetrieveDataWithCredentialAsync(
  Credential credential
)

Asynchronously logs into Firebase with the given credentials.

For example, the credential could wrap a Facebook login access token, a Twitter token/token-secret pair).

AuthResult contains both a reference to the FirebaseUser (which can be null if the sign in failed), and AdditionalUserInfo, which holds details specific to the Identity Provider used to sign in.

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

SignInAndRetrieveDataWithCredentialAsync_DEPRECATED

async System.Threading.Tasks.Task< SignInResult > SignInAndRetrieveDataWithCredentialAsync_DEPRECATED(
  Credential credential
)

Deprecated. This method is deprecated in favor of methods that return Task<AuthResult>. Please use SignInAndRetrieveDataWithCredentialAsync(Credential) instead.

Asynchronously logs into Firebase with the given credentials.

For example, the credential could wrap a Facebook login access token, a Twitter token/token-secret pair).

The SignInResult contains both a reference to the User (which can be null if the sign in failed), and AdditionalUserInfo, which holds details specific to the Identity Provider used to sign in.

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

SignInAnonymouslyAsync

async System.Threading.Tasks.Task< AuthResult > 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!");
    }
  });
}

SignInAnonymouslyAsync_DEPRECATED

async System.Threading.Tasks.Task< FirebaseUser > SignInAnonymouslyAsync_DEPRECATED()

Deprecated. This method is deprecated in favor of methods that return Task<AuthResult>. Please use SignInAnonymouslyAsync() instead.

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

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

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.

SignInWithCredentialAsync_DEPRECATED

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

SignInWithCustomTokenAsync

async System.Threading.Tasks.Task< AuthResult > 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.

SignInWithCustomTokenAsync_DEPRECATED

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

Deprecated. This method is deprecated in favor of methods that return Task<AuthResult>. Please use SignInWithCustomTokenAsync(string) instead.

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

async System.Threading.Tasks.Task< AuthResult > 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.

SignInWithEmailAndPasswordAsync_DEPRECATED

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

Deprecated. This method is deprecated in favor of methods that return Task<AuthResult>. Please use Task<AuthResult> SignInAnonymouslyAsync() instead.

Signs in using provided email address and password. An error is returned if the password is wrong or otherwise not accepted by the server.

SignInWithProviderAsync

async System.Threading.Tasks.Task< AuthResult > SignInWithProviderAsync(
  FederatedAuthProvider provider
)

Sign-in a user authenticated via a federated auth provider.

SignInWithProviderAsync_DEPRECATED

async System.Threading.Tasks.Task< SignInResult > SignInWithProviderAsync_DEPRECATED(
  FederatedAuthProvider provider
)

Deprecated. This method is deprecated in favor of methods that return Task<AuthResult>. Please use SignInWithProviderAsync(FederatedAuthProvider) instead.

Sign-in a user authenticated via a federated auth provider.

SignOut

void SignOut()

UseAppLanguage

void UseAppLanguage()

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.