1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
pub mod api_uri;
pub mod auth;
pub mod client;
pub mod credentials;
pub mod util;
use auth::{
token::{error::TokenVerificationError, EmulatedTokenVerifier, LiveTokenVerifier},
FirebaseAuth,
};
use client::{build_https_client, HyperApiClient, HyperClient};
use credentials::emulator::EmulatorCredentials;
pub use credentials::gcp::GcpCredentials;
use error_stack::Report;
pub use gcp_auth::CustomServiceAccount;
use http::uri::Authority;
use std::sync::Arc;
pub type LiveAuthAdmin = FirebaseAuth<HyperApiClient<GcpCredentials>>;
pub type EmulatorAuthAdmin = FirebaseAuth<HyperApiClient<EmulatorCredentials>>;
pub struct App<CredentialsT> {
credentials: Arc<CredentialsT>,
project_id: String,
}
impl App<EmulatorCredentials> {
pub fn emulated(project_id: String) -> Self {
Self {
credentials: Arc::new(EmulatorCredentials {}),
project_id,
}
}
pub fn auth(&self, emulator_auth: Authority) -> EmulatorAuthAdmin {
let client = HyperApiClient::new(self.credentials.clone());
FirebaseAuth::emulated(emulator_auth, &self.project_id, client)
}
pub fn id_token_verifier(&self) -> EmulatedTokenVerifier {
EmulatedTokenVerifier::new(self.project_id.clone())
}
}
impl App<GcpCredentials> {
pub fn live(project_id: String, service_account: CustomServiceAccount) -> Self {
Self {
credentials: Arc::new(service_account.into()),
project_id,
}
}
pub fn auth(&self) -> LiveAuthAdmin {
let client = HyperApiClient::new(self.credentials.clone());
FirebaseAuth::live(&self.project_id, client)
}
pub async fn id_token_verifier(
&self,
) -> Result<LiveTokenVerifier<HyperClient>, Report<TokenVerificationError>> {
LiveTokenVerifier::new(self.project_id.clone(), build_https_client()).await
}
}