firebase_rs_sdk/platform/
token.rs

1use std::error::Error;
2use std::fmt;
3
4/// Error type returned by async token providers when token acquisition fails.
5#[derive(Debug, Clone)]
6pub struct TokenError {
7    message: String,
8}
9
10impl TokenError {
11    pub fn new(message: impl Into<String>) -> Self {
12        Self {
13            message: message.into(),
14        }
15    }
16
17    pub fn from_error(err: impl Error) -> Self {
18        Self::new(err.to_string())
19    }
20}
21
22impl fmt::Display for TokenError {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        write!(f, "{}", self.message)
25    }
26}
27
28impl Error for TokenError {}
29
30/// Shared trait used by modules that need to retrieve auth/app-check tokens asynchronously.
31#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
32#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
33pub trait AsyncTokenProvider: Send + Sync {
34    async fn get_token(&self, force_refresh: bool) -> Result<Option<String>, TokenError>;
35}