Crate actix_firebase_auth

Source
Expand description

§actix-firebase-auth

This crate provides Firebase JWT verification for the actix-web framework, using Google’s public JWKs to validate ID tokens issued by Firebase Authentication.

§Example

use actix_web::{web, App, HttpServer, HttpResponse, Responder};
use actix_firebase_auth::{FirebaseAuth, FirebaseUser, Result};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let auth = FirebaseAuth::new("your-project-id").await.unwrap(); // Don't forget to handle this error

    HttpServer::new(move || {
        App::new()
            .app_data(web::Data::new(auth.clone()))
            .route("/profile", web::get().to(get_profile))
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
}

async fn get_profile(
    auth: web::Data<FirebaseAuth>,
    user: FirebaseUser,
) -> HttpResponse {
    HttpResponse::Ok().json(user)
}

Structs§

FirebaseAuth
FirebaseAuth is responsible for verifying Firebase JWT tokens and keeping the Google public keys up to date by periodically fetching them.
FirebaseProvider
Firebase-specific metadata included in the token under the firebase field.
FirebaseUser
Represents the decoded JWT claims from a Firebase Authentication token.

Enums§

Error
Unified error type for Firebase authentication-related failures.

Type Aliases§

Result
A crate-wide result type alias using the custom Error enum.