Expand description

§rocket-firebase-auth

The rocket-firebase-auth crate provides an easy, batteries included firebase authentication library for Rocket. The library is built for servers that use Firebase tokens as a means of authentication from the client.

§Example

use rocket::{get, http::Status, routes, Build, Rocket};
use rocket_firebase_auth::{FirebaseAuth, FirebaseToken};

struct ServerState {
    auth: FirebaseAuth,
}

#[get("/")]
async fn hello_world(token: FirebaseToken) -> Status {
    println!("Authentication succeeded with uid={}", token.sub);
    Status::Ok
}

#[rocket::launch]
async fn rocket() -> Rocket<Build> {
    let firebase_auth = FirebaseAuth::builder()
        .json_file("firebase-credentials.json")
        .build()
        .unwrap();

    rocket::build()
        .mount("/", routes![hello_world])
        .manage(ServerState {
            auth: firebase_auth,
        })
}

§Optional Features

By default env and rocket as included as features. The following are a list of [Cargo features][cargo-features] that can be enabled or disabled:

  • env: Includes functions that helps in initializing Firebase Auth from dotenv files
  • encode: Adds support for encoding tokens
  • rocket: Implements the FromRequest trait for BearerToken, so that rocket endpoints can easily access the token as an input parameter.

Re-exports§

Modules§

Structs§

  • The bearer token included in request headers
  • All the different kind of keys we can use to decode a JWT. This key can be re-used so make sure you only initialize it once if you can for better performance.
  • A partial representation of firebase admin object provided by firebase.
  • Firebase Auth instance
  • The claims of a decoded JWT token used in firebase
  • Contains the various validations that are applied after decoding a JWT.

Enums§

Functions§

  • Decode a JWT without any signature verification/validations and return its Header.