firestore_db_and_auth/
lib.rs

1#![deny(warnings)]
2#![cfg_attr(not(doctest), doc = include_str!("../readme.md"))]
3
4pub mod credentials;
5pub mod documents;
6pub mod dto;
7pub mod errors;
8pub mod firebase_rest_to_rust;
9pub mod jwt;
10pub mod sessions;
11pub mod users;
12
13#[cfg(feature = "rocket_support")]
14pub mod rocket;
15
16// Forward declarations
17pub use credentials::Credentials;
18pub use jwt::JWKSet;
19pub use sessions::service_account::Session as ServiceSession;
20pub use sessions::user::Session as UserSession;
21
22/// Authentication trait.
23///
24/// This trait is implemented by [`crate::sessions`].
25///
26/// Firestore document methods in [`crate::documents`] expect an object that implements this `FirebaseAuthBearer` trait.
27///
28/// Implement this trait for your own data structure and provide the Firestore project id and a valid access token.
29#[async_trait::async_trait]
30pub trait FirebaseAuthBearer {
31    /// Return the project ID. This is required for the firebase REST API.
32    fn project_id(&self) -> &str;
33
34    /// An access token. If a refresh token is known and the access token expired,
35    /// the implementation should try to refresh the access token before returning.
36    async fn access_token(&self) -> String;
37
38    /// The access token, unchecked. Might be expired or in other ways invalid.
39    async fn access_token_unchecked(&self) -> String;
40
41    /// The reqwest http client.
42    /// The `Client` holds a connection pool internally, so it is advised that it is reused for multiple, successive connections.
43    fn client(&self) -> &reqwest::Client;
44}