pub struct Auth { /* private fields */ }Implementations§
Source§impl Auth
impl Auth
Sourcepub fn multi_factor(self: &Arc<Self>) -> MultiFactorUser
pub fn multi_factor(self: &Arc<Self>) -> MultiFactorUser
Returns a multi-factor helper tied to this auth instance.
Sourcepub fn builder(app: FirebaseApp) -> AuthBuilder
pub fn builder(app: FirebaseApp) -> AuthBuilder
Creates a builder for configuring an Auth instance before construction.
Sourcepub fn new(app: FirebaseApp) -> AuthResult<Self>
pub fn new(app: FirebaseApp) -> AuthResult<Self>
Constructs an Auth instance using in-memory persistence.
Sourcepub fn new_with_persistence(
app: FirebaseApp,
persistence: Arc<dyn AuthPersistence + Send + Sync>,
) -> AuthResult<Self>
pub fn new_with_persistence( app: FirebaseApp, persistence: Arc<dyn AuthPersistence + Send + Sync>, ) -> AuthResult<Self>
Constructs an Auth instance with a caller-provided persistence backend.
Sourcepub fn initialize(self: &Arc<Self>) -> AuthResult<()>
pub fn initialize(self: &Arc<Self>) -> AuthResult<()>
Finishes initialization by restoring persisted state and wiring listeners.
Sourcepub fn app(&self) -> &FirebaseApp
pub fn app(&self) -> &FirebaseApp
Returns the FirebaseApp associated with this Auth instance.
Sourcepub fn current_user(&self) -> Option<Arc<User>>
pub fn current_user(&self) -> Option<Arc<User>>
Returns the currently signed-in user, if any.
Sourcepub fn email_auth_provider(&self) -> EmailAuthProvider
pub fn email_auth_provider(&self) -> EmailAuthProvider
Returns the email/password auth provider helper.
Sourcepub async fn sign_in_with_email_and_password(
&self,
email: &str,
password: &str,
) -> AuthResult<UserCredential>
pub async fn sign_in_with_email_and_password( &self, email: &str, password: &str, ) -> AuthResult<UserCredential>
Signs a user in using the email/password REST endpoint.
Sourcepub async fn create_user_with_email_and_password(
&self,
email: &str,
password: &str,
) -> AuthResult<UserCredential>
pub async fn create_user_with_email_and_password( &self, email: &str, password: &str, ) -> AuthResult<UserCredential>
Creates a new user using email/password credentials.
Sourcepub async fn sign_in_with_custom_token(
&self,
token: &str,
) -> AuthResult<UserCredential>
pub async fn sign_in_with_custom_token( &self, token: &str, ) -> AuthResult<UserCredential>
Exchanges a custom authentication token for Firebase credentials.
§Examples
let credential = auth.sign_in_with_custom_token("CUSTOM-TOKEN").await?;
println!("Signed in as {}", credential.user.uid());Sourcepub async fn sign_in_anonymously(&self) -> AuthResult<UserCredential>
pub async fn sign_in_anonymously(&self) -> AuthResult<UserCredential>
Signs the user in anonymously, creating an anonymous user if needed.
§Examples
let anon = auth.sign_in_anonymously().await?;
assert!(anon.user.is_anonymous());Sourcepub async fn sign_in_with_phone_number(
self: &Arc<Self>,
phone_number: &str,
verifier: Arc<dyn ApplicationVerifier>,
) -> AuthResult<ConfirmationResult>
pub async fn sign_in_with_phone_number( self: &Arc<Self>, phone_number: &str, verifier: Arc<dyn ApplicationVerifier>, ) -> AuthResult<ConfirmationResult>
Starts a phone number sign-in flow, returning a confirmation handle.
Sourcepub async fn send_phone_verification_code(
&self,
phone_number: &str,
verifier: Arc<dyn ApplicationVerifier>,
) -> AuthResult<String>
pub async fn send_phone_verification_code( &self, phone_number: &str, verifier: Arc<dyn ApplicationVerifier>, ) -> AuthResult<String>
Sends an SMS verification code and returns the verification identifier.
§Examples
let verification_id = auth
.send_phone_verification_code("+15551234567", verifier)
.await?;
println!("Sent verification code, id: {}", verification_id);Sourcepub async fn link_with_phone_number(
self: &Arc<Self>,
phone_number: &str,
verifier: Arc<dyn ApplicationVerifier>,
) -> AuthResult<ConfirmationResult>
pub async fn link_with_phone_number( self: &Arc<Self>, phone_number: &str, verifier: Arc<dyn ApplicationVerifier>, ) -> AuthResult<ConfirmationResult>
Links the currently signed-in account with the provided phone number.
Sourcepub async fn reauthenticate_with_phone_number(
self: &Arc<Self>,
phone_number: &str,
verifier: Arc<dyn ApplicationVerifier>,
) -> AuthResult<ConfirmationResult>
pub async fn reauthenticate_with_phone_number( self: &Arc<Self>, phone_number: &str, verifier: Arc<dyn ApplicationVerifier>, ) -> AuthResult<ConfirmationResult>
Reauthenticates the current user via an SMS verification code.
Sourcepub async fn sign_in_with_phone_credential(
self: &Arc<Self>,
credential: PhoneAuthCredential,
) -> AuthResult<UserCredential>
pub async fn sign_in_with_phone_credential( self: &Arc<Self>, credential: PhoneAuthCredential, ) -> AuthResult<UserCredential>
Signs in using a credential produced by [PhoneAuthProvider::credential].
§Examples
let verification_id = "verification-id-from-sms";
let sms_code = "123456";
let credential = firebase_rs_sdk::auth::PhoneAuthProvider::credential(verification_id, sms_code);
let user = auth.sign_in_with_phone_credential(credential).await?;Sourcepub async fn link_with_phone_credential(
self: &Arc<Self>,
credential: PhoneAuthCredential,
) -> AuthResult<UserCredential>
pub async fn link_with_phone_credential( self: &Arc<Self>, credential: PhoneAuthCredential, ) -> AuthResult<UserCredential>
Links the current user with the provided phone credential.
Sourcepub async fn reauthenticate_with_phone_credential(
self: &Arc<Self>,
credential: PhoneAuthCredential,
) -> AuthResult<Arc<User>>
pub async fn reauthenticate_with_phone_credential( self: &Arc<Self>, credential: PhoneAuthCredential, ) -> AuthResult<Arc<User>>
Reauthenticates the current user with an SMS credential.
§Examples
let verification_id = "verification-id-from-sms";
let sms_code = "123456";
let credential = firebase_rs_sdk::auth::PhoneAuthProvider::credential(verification_id, sms_code);
let user = auth.reauthenticate_with_phone_credential(credential).await?;Sourcepub fn on_auth_state_changed(
&self,
observer: PartialObserver<Arc<User>>,
) -> impl FnOnce() + Send + 'static
pub fn on_auth_state_changed( &self, observer: PartialObserver<Arc<User>>, ) -> impl FnOnce() + Send + 'static
Registers an observer that is invoked whenever auth state changes.
Sourcepub async fn get_token(&self, force_refresh: bool) -> AuthResult<Option<String>>
pub async fn get_token(&self, force_refresh: bool) -> AuthResult<Option<String>>
Returns the current user’s ID token, refreshing when requested.
pub async fn get_token_async( &self, force_refresh: bool, ) -> AuthResult<Option<String>>
Sourcepub fn token_provider(self: &Arc<Self>) -> TokenProviderArc
pub fn token_provider(self: &Arc<Self>) -> TokenProviderArc
Exposes this auth instance as a Firestore token provider.
Sourcepub fn set_oauth_request_uri(&self, value: impl Into<String>)
pub fn set_oauth_request_uri(&self, value: impl Into<String>)
Overrides the default OAuth request URI used during flows.
Sourcepub fn oauth_request_uri(&self) -> String
pub fn oauth_request_uri(&self) -> String
Returns the OAuth request URI for popup/redirect flows.
Sourcepub fn set_identity_toolkit_endpoint(&self, endpoint: impl Into<String>)
pub fn set_identity_toolkit_endpoint(&self, endpoint: impl Into<String>)
Updates the Identity Toolkit REST endpoint.
Sourcepub fn identity_toolkit_endpoint(&self) -> String
pub fn identity_toolkit_endpoint(&self) -> String
Returns the Identity Toolkit REST endpoint in use.
Sourcepub fn set_secure_token_endpoint(&self, endpoint: impl Into<String>)
pub fn set_secure_token_endpoint(&self, endpoint: impl Into<String>)
Sets the Secure Token endpoint used for refresh operations.
Sourcepub fn set_popup_handler(&self, handler: Arc<dyn OAuthPopupHandler>)
pub fn set_popup_handler(&self, handler: Arc<dyn OAuthPopupHandler>)
Installs an OAuth popup handler implementation.
Sourcepub fn clear_popup_handler(&self)
pub fn clear_popup_handler(&self)
Clears any installed popup handler.
Sourcepub fn popup_handler(&self) -> Option<Arc<dyn OAuthPopupHandler>>
pub fn popup_handler(&self) -> Option<Arc<dyn OAuthPopupHandler>>
Retrieves the currently configured popup handler.
Sourcepub fn set_redirect_handler(&self, handler: Arc<dyn OAuthRedirectHandler>)
pub fn set_redirect_handler(&self, handler: Arc<dyn OAuthRedirectHandler>)
Installs an OAuth redirect handler implementation.
Sourcepub fn clear_redirect_handler(&self)
pub fn clear_redirect_handler(&self)
Clears any installed redirect handler.
Sourcepub fn redirect_handler(&self) -> Option<Arc<dyn OAuthRedirectHandler>>
pub fn redirect_handler(&self) -> Option<Arc<dyn OAuthRedirectHandler>>
Retrieves the currently configured redirect handler.
Sourcepub fn set_redirect_persistence(
&self,
persistence: Arc<dyn RedirectPersistence>,
)
pub fn set_redirect_persistence( &self, persistence: Arc<dyn RedirectPersistence>, )
Replaces the persistence mechanism used for redirect state.
Sourcepub async fn sign_in_with_oauth_credential(
&self,
credential: AuthCredential,
) -> AuthResult<UserCredential>
pub async fn sign_in_with_oauth_credential( &self, credential: AuthCredential, ) -> AuthResult<UserCredential>
Signs in using an OAuth credential produced by popup/redirect flows.
Sourcepub async fn send_password_reset_email(&self, email: &str) -> AuthResult<()>
pub async fn send_password_reset_email(&self, email: &str) -> AuthResult<()>
Sends a password reset email to the specified address.
Sourcepub async fn send_sign_in_link_to_email(
&self,
email: &str,
settings: &ActionCodeSettings,
) -> AuthResult<()>
pub async fn send_sign_in_link_to_email( &self, email: &str, settings: &ActionCodeSettings, ) -> AuthResult<()>
Sends a sign-in link to the provided email address.
§Examples
let settings = firebase_rs_sdk::auth::ActionCodeSettings {
url: "https://example.com/finish".into(),
handle_code_in_app: true,
..Default::default()
};
auth.send_sign_in_link_to_email("user@example.com", &settings).await?;Sourcepub async fn confirm_password_reset(
&self,
oob_code: &str,
new_password: &str,
) -> AuthResult<()>
pub async fn confirm_password_reset( &self, oob_code: &str, new_password: &str, ) -> AuthResult<()>
Confirms a password reset OOB code and applies the new password.
Sourcepub async fn send_email_verification(&self) -> AuthResult<()>
pub async fn send_email_verification(&self) -> AuthResult<()>
Sends an email verification message to the currently signed-in user.
Sourcepub fn is_sign_in_with_email_link(&self, email_link: &str) -> bool
pub fn is_sign_in_with_email_link(&self, email_link: &str) -> bool
Returns true if the supplied link is an email sign-in link.
Sourcepub async fn sign_in_with_email_link(
&self,
email: &str,
email_link: &str,
) -> AuthResult<UserCredential>
pub async fn sign_in_with_email_link( &self, email: &str, email_link: &str, ) -> AuthResult<UserCredential>
Completes the email link sign-in flow for the given email address.
§Examples
let link = "link-to-sign-in";
if auth.is_sign_in_with_email_link(&link) {
let credential = auth.sign_in_with_email_link("user@example.com", &link).await?;
println!("Signed in as {}", credential.user.uid());
}Sourcepub async fn apply_action_code(&self, oob_code: &str) -> AuthResult<()>
pub async fn apply_action_code(&self, oob_code: &str) -> AuthResult<()>
Applies an out-of-band action code issued by Firebase Auth.
§Examples
auth.apply_action_code("ACTION_CODE_FROM_EMAIL").await?;Sourcepub async fn check_action_code(
&self,
oob_code: &str,
) -> AuthResult<ActionCodeInfo>
pub async fn check_action_code( &self, oob_code: &str, ) -> AuthResult<ActionCodeInfo>
Retrieves metadata describing the provided action code.
§Examples
let info = auth.check_action_code("ACTION_CODE").await?;
println!("Operation: {:?}", info.operation);Sourcepub async fn verify_password_reset_code(
&self,
oob_code: &str,
) -> AuthResult<String>
pub async fn verify_password_reset_code( &self, oob_code: &str, ) -> AuthResult<String>
Returns the email address associated with the provided password reset code.
§Examples
let email = auth.verify_password_reset_code("RESET_CODE").await?;
println!("Reset applies to {email}");Sourcepub async fn update_profile(
&self,
display_name: Option<&str>,
photo_url: Option<&str>,
) -> AuthResult<Arc<User>>
pub async fn update_profile( &self, display_name: Option<&str>, photo_url: Option<&str>, ) -> AuthResult<Arc<User>>
Updates the current user’s display name and photo URL.
Sourcepub async fn update_email(&self, email: &str) -> AuthResult<Arc<User>>
pub async fn update_email(&self, email: &str) -> AuthResult<Arc<User>>
Updates the current user’s email address.
Sourcepub async fn update_password(&self, password: &str) -> AuthResult<Arc<User>>
pub async fn update_password(&self, password: &str) -> AuthResult<Arc<User>>
Updates the current user’s password.
Sourcepub async fn delete_user(&self) -> AuthResult<()>
pub async fn delete_user(&self) -> AuthResult<()>
Deletes the current user from Firebase Auth.
Sourcepub async fn unlink_providers(
&self,
provider_ids: &[&str],
) -> AuthResult<Arc<User>>
pub async fn unlink_providers( &self, provider_ids: &[&str], ) -> AuthResult<Arc<User>>
Unlinks the specified providers from the current user.
Sourcepub async fn get_account_info(&self) -> AuthResult<GetAccountInfoResponse>
pub async fn get_account_info(&self) -> AuthResult<GetAccountInfoResponse>
Fetches the latest account info for the current user.
Sourcepub async fn link_with_oauth_credential(
&self,
credential: AuthCredential,
) -> AuthResult<UserCredential>
pub async fn link_with_oauth_credential( &self, credential: AuthCredential, ) -> AuthResult<UserCredential>
Links an OAuth credential with the currently signed-in user.
Sourcepub async fn reauthenticate_with_password(
&self,
email: &str,
password: &str,
) -> AuthResult<Arc<User>>
pub async fn reauthenticate_with_password( &self, email: &str, password: &str, ) -> AuthResult<Arc<User>>
Reauthenticates the current user with email and password.
Sourcepub async fn reauthenticate_with_oauth_credential(
&self,
credential: AuthCredential,
) -> AuthResult<Arc<User>>
pub async fn reauthenticate_with_oauth_credential( &self, credential: AuthCredential, ) -> AuthResult<Arc<User>>
Reauthenticates the current user with an OAuth credential.