Firebase. Auth. FirebaseAuth
Firebase authentication object.
Summary
EachFirebase.FirebaseApp has up to oneFirebase.Auth.FirebaseAuth class. You acquire theFirebase.Auth.FirebaseAuth class through the static functionFirebase.Auth.FirebaseAuth.GetAuth.
For example:
// Get the Auth class for your App.Firebase.Auth.FirebaseAuthauth=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.");}elseif(authTask.IsFaulted){DebugLog("Sign-in encountered an error.");DebugLog(authTask.Exception.ToString());}elseif(authTask.IsCompleted){Firebase.Auth.Useruser=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: SystemIDisposableProperties | |
|---|---|
App | Get theFirebaseApp associated with this object. |
CurrentUser | Synchronously gets the cached current user, or null if there is none. |
DefaultInstance | staticFirebaseAuthReturns theFirebaseAuth associated with FirebaseApp.DefaultApp. |
IdTokenChanged | System.EventHandlerEvent raised on ID token changes. |
LanguageCode | System.StringThe user-facing language code for auth operations that can be internationalized, such as FirebaseUser.sendEmailVerification(). |
StateChanged | System.EventHandlerEvent 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 intoFirebase 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 theFirebaseAuth object for an App. |
Properties
App
FirebaseAppApp
Get theFirebaseApp associated with this object.
| Details | |
|---|---|
| Returns | FirebaseApp associated with this object. |
CurrentUser
FirebaseUserCurrentUser
Synchronously gets the cached current user, or null if there is none.
Note: Accessing this property may block and wait until theFirebaseAuth instance finishes loading the saved user's state. This should only happen for a short period of time after theFirebaseAuth instance is created.
DefaultInstance
staticFirebaseAuthDefaultInstance
Returns theFirebaseAuth associated with FirebaseApp.DefaultApp.
FirebaseAuth will be created if required.
| Details | |||
|---|---|---|---|
| Exceptions |
|
IdTokenChanged
System.EventHandlerIdTokenChanged
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.StringLanguageCode
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.EventHandlerStateChanged
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
asyncSystem.Threading.Tasks.Task<AuthResult>CreateUserWithEmailAndPasswordAsync(stringemail,stringpassword)
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
voidDispose()
Dispose
voidDispose(booldisposing)
FetchProvidersForEmailAsync
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<string>>FetchProvidersForEmailAsync(stringemail)
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.voidDisplayIdentityProviders(Firebase.Auth.FirebaseAuthauth,Stringemail){auth.FetchProvidersForEmailAsync().ContinueWith((authTask)=>{if(authTask.IsCanceled){DebugLog("Provider fetch canceled.");}elseif(authTask.IsFaulted){DebugLog("Provider fetch encountered an error.");DebugLog(authTask.Exception.ToString());}elseif(authTask.IsCompleted){DebugLog("Email Providers:");foreach(stringproviderinauthTask.result){DebugLog(provider);}}});}
SendPasswordResetEmailAsync
System.Threading.Tasks.TaskSendPasswordResetEmailAsync(stringemail)
SignInAndRetrieveDataWithCredentialAsync
asyncSystem.Threading.Tasks.Task<AuthResult>SignInAndRetrieveDataWithCredentialAsync(Credentialcredential)
Asynchronously logs intoFirebase 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 theFirebaseUser (which can be null if the sign in failed), andAdditionalUserInfo, 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
asyncSystem.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.
boolSignIn(Firebase.Auth.FirebaseAuthauth){auth.SignInAnonymouslyAsync().ContinueWith((authTask)=>{if(authTask.IsCanceled){DebugLog("Anonymous sign in canceled.");}elseif(authTask.IsFaulted){DebugLog("Anonymous sign in encountered an error.");DebugLog(authTask.Exception.ToString());}elseif(authTask.IsCompleted){DebugLog("Anonymous sign in successful!");}});}
SignInWithCredentialAsync
asyncSystem.Threading.Tasks.Task<FirebaseUser>SignInWithCredentialAsync(Credentialcredential)
SignInWithCustomTokenAsync
asyncSystem.Threading.Tasks.Task<AuthResult>SignInWithCustomTokenAsync(stringtoken)
SignInWithEmailAndPasswordAsync
asyncSystem.Threading.Tasks.Task<AuthResult>SignInWithEmailAndPasswordAsync(stringemail,stringpassword)
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
asyncSystem.Threading.Tasks.Task<AuthResult>SignInWithProviderAsync(FederatedAuthProviderprovider)
Sign-in a user authenticated via a federated auth provider.
SignOut
voidSignOut()
UseAppLanguage
voidUseAppLanguage()
Public static functions
GetAuth
FirebaseAuthGetAuth(FirebaseAppapp)
Returns theFirebaseAuth object for an App.
Creates theFirebaseAuth if required.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Exceptions |
|
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-05-09 UTC.