firebase_auth/lib.rs
1//! [Firebase](https://firebase.google.com) authentication layer for popular frameworks.
2//!
3//! Support:
4//!
5//! - [Axum](https://github.com/tokio-rs/axum)
6//! - [Actix](https://github.com/actix/actix-web)
7//!
8//! ## Example:
9//!
10//! ### Actix
11//!
12//! ```rust
13//! use actix_web::{get, middleware::Logger, web::Data, App, HttpServer, Responder};
14//! use firebase_auth::{FirebaseAuth, FirebaseUser};
15//!
16//! #[get("/hello")]
17//! async fn greet(user: FirebaseUser) -> impl Responder {
18//! let email = user.email.unwrap_or("empty email".to_string());
19//! format!("Hello {}!", email)
20//! }
21//!
22//! #[get("/public")]
23//! async fn public() -> impl Responder {
24//! "ok"
25//! }
26//!
27//! #[actix_web::main]
28//! async fn main() -> std::io::Result<()> {
29//! let firebase_auth = FirebaseAuth::new("my-project-id").await;
30//!
31//! let app_data = Data::new(firebase_auth);
32//!
33//! HttpServer::new(move || {
34//! App::new()
35//! .wrap(Logger::default())
36//! .app_data(app_data.clone())
37//! .service(greet)
38//! .service(public)
39//! })
40//! .bind(("127.0.0.1", 8080))?
41//! .run()
42//! .await
43//! }
44//! ```
45//!
46//! ### Axum
47//!
48//! ```rust
49//! use axum::{routing::get, Router};
50//! use firebase_auth::{FirebaseAuth, FirebaseAuthState, FirebaseUser};
51//!
52//! async fn greet(user: FirebaseUser) -> String {
53//! let email = user.email.unwrap_or("empty email".to_string());
54//! format!("hello {}", email)
55//! }
56//!
57//! async fn public() -> &'static str {
58//! "ok"
59//! }
60//!
61//! #[tokio::main]
62//! async fn main() {
63//! let firebase_auth = FirebaseAuth::new("my-project-id").await;
64//!
65//! let app = Router::new()
66//! .route("/hello", get(greet))
67//! .route("/", get(public))
68//! .with_state(FirebaseAuthState { firebase_auth });
69//!
70//!
71//! let addr = "127.0.0.1:8080";
72//! let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
73//!
74//! axum::serve(listener, app).await.unwrap();
75//! }
76//! ```
77//!
78//!Visit [README.md](https://github.com/trchopan/firebase-auth/) for more details.
79
80mod firebase_auth;
81pub use firebase_auth::FirebaseAuth;
82
83mod structs;
84pub use structs::{FirebaseUser, PublicKeysError, FirebaseProvider};
85
86#[cfg(feature = "actix-web")]
87mod actix_feature;
88
89#[cfg(feature = "axum")]
90mod axum_feature;
91
92#[cfg(feature = "axum")]
93pub use axum_feature::FirebaseAuthState;