Firebase. Auth. FirebaseAuth
Firebase authentication object.
Summary
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.
|
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.
|
SignInAnonymouslyAsync()
|
async System.Threading.Tasks.Task< AuthResult >
Asynchronously creates and becomes an anonymous user.
|
SignInWithCredentialAsync(Credential credential)
|
async System.Threading.Tasks.Task< FirebaseUser >
|
SignInWithCustomTokenAsync(string token)
|
async System.Threading.Tasks.Task< AuthResult >
|
SignInWithEmailAndPasswordAsync(string email, string password)
|
async System.Threading.Tasks.Task< AuthResult >
Signs in using provided email address and password.
|
SignInWithProviderAsync(FederatedAuthProvider provider)
|
async System.Threading.Tasks.Task< AuthResult >
Sign-in a user authenticated via a federated auth provider.
|
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 |
|
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.).
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.
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!");
}
});
}
SignInWithCredentialAsync
async System.Threading.Tasks.Task< FirebaseUser > SignInWithCredentialAsync( Credential credential )
SignInWithCustomTokenAsync
async System.Threading.Tasks.Task< AuthResult > SignInWithCustomTokenAsync( string token )
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.
SignInWithProviderAsync
async System.Threading.Tasks.Task< AuthResult > SignInWithProviderAsync( FederatedAuthProvider provider )
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 |
|
||
Exceptions |
|