Auth

Struct Auth 

Source
pub struct Auth { /* private fields */ }

Implementations§

Source§

impl Auth

Source

pub fn multi_factor(self: &Arc<Self>) -> MultiFactorUser

Returns a multi-factor helper tied to this auth instance.

Source

pub fn builder(app: FirebaseApp) -> AuthBuilder

Creates a builder for configuring an Auth instance before construction.

Source

pub fn new(app: FirebaseApp) -> AuthResult<Self>

Constructs an Auth instance using in-memory persistence.

Source

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.

Source

pub fn initialize(self: &Arc<Self>) -> AuthResult<()>

Finishes initialization by restoring persisted state and wiring listeners.

Source

pub fn app(&self) -> &FirebaseApp

Returns the FirebaseApp associated with this Auth instance.

Source

pub fn current_user(&self) -> Option<Arc<User>>

Returns the currently signed-in user, if any.

Source

pub fn sign_out(&self)

Signs out the current user and clears persisted credentials.

Source

pub fn email_auth_provider(&self) -> EmailAuthProvider

Returns the email/password auth provider helper.

Source

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.

Source

pub async fn create_user_with_email_and_password( &self, email: &str, password: &str, ) -> AuthResult<UserCredential>

Creates a new user using email/password credentials.

Source

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

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

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.

Source

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

Links the currently signed-in account with the provided phone number.

Source

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.

Source

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?;

Links the current user with the provided phone credential.

Source

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?;
Source

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.

Source

pub async fn get_token(&self, force_refresh: bool) -> AuthResult<Option<String>>

Returns the current user’s ID token, refreshing when requested.

Source

pub async fn get_token_async( &self, force_refresh: bool, ) -> AuthResult<Option<String>>

Source

pub fn token_provider(self: &Arc<Self>) -> TokenProviderArc

Exposes this auth instance as a Firestore token provider.

Source

pub fn set_oauth_request_uri(&self, value: impl Into<String>)

Overrides the default OAuth request URI used during flows.

Source

pub fn oauth_request_uri(&self) -> String

Returns the OAuth request URI for popup/redirect flows.

Source

pub fn set_identity_toolkit_endpoint(&self, endpoint: impl Into<String>)

Updates the Identity Toolkit REST endpoint.

Source

pub fn identity_toolkit_endpoint(&self) -> String

Returns the Identity Toolkit REST endpoint in use.

Source

pub fn set_secure_token_endpoint(&self, endpoint: impl Into<String>)

Sets the Secure Token endpoint used for refresh operations.

Source

pub fn set_popup_handler(&self, handler: Arc<dyn OAuthPopupHandler>)

Installs an OAuth popup handler implementation.

Source

pub fn clear_popup_handler(&self)

Clears any installed popup handler.

Source

pub fn popup_handler(&self) -> Option<Arc<dyn OAuthPopupHandler>>

Retrieves the currently configured popup handler.

Source

pub fn set_redirect_handler(&self, handler: Arc<dyn OAuthRedirectHandler>)

Installs an OAuth redirect handler implementation.

Source

pub fn clear_redirect_handler(&self)

Clears any installed redirect handler.

Source

pub fn redirect_handler(&self) -> Option<Arc<dyn OAuthRedirectHandler>>

Retrieves the currently configured redirect handler.

Source

pub fn set_redirect_persistence( &self, persistence: Arc<dyn RedirectPersistence>, )

Replaces the persistence mechanism used for redirect state.

Source

pub async fn sign_in_with_oauth_credential( &self, credential: AuthCredential, ) -> AuthResult<UserCredential>

Signs in using an OAuth credential produced by popup/redirect flows.

Source

pub async fn send_password_reset_email(&self, email: &str) -> AuthResult<()>

Sends a password reset email to the specified address.

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?;
Source

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.

Source

pub async fn send_email_verification(&self) -> AuthResult<()>

Sends an email verification message to the currently signed-in user.

Returns true if the supplied link is an email sign-in link.

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());
}
Source

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?;
Source

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);
Source

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}");
Source

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.

Source

pub async fn update_email(&self, email: &str) -> AuthResult<Arc<User>>

Updates the current user’s email address.

Source

pub async fn update_password(&self, password: &str) -> AuthResult<Arc<User>>

Updates the current user’s password.

Source

pub async fn delete_user(&self) -> AuthResult<()>

Deletes the current user from Firebase Auth.

Unlinks the specified providers from the current user.

Source

pub async fn get_account_info(&self) -> AuthResult<GetAccountInfoResponse>

Fetches the latest account info for the current user.

Links an OAuth credential with the currently signed-in user.

Source

pub async fn reauthenticate_with_password( &self, email: &str, password: &str, ) -> AuthResult<Arc<User>>

Reauthenticates the current user with email and password.

Source

pub async fn reauthenticate_with_oauth_credential( &self, credential: AuthCredential, ) -> AuthResult<Arc<User>>

Reauthenticates the current user with an OAuth credential.

Auto Trait Implementations§

§

impl !Freeze for Auth

§

impl !RefUnwindSafe for Auth

§

impl Send for Auth

§

impl Sync for Auth

§

impl Unpin for Auth

§

impl !UnwindSafe for Auth

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,