Crate rocket_firebase_auth

Source
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§

pub use dotenvy;
pub use serde_json;

Modules§

errors
Error management for the library
jwk
JWKs fetcher module
plugins

Structs§

BearerToken
The bearer token included in request headers
DecodingKey
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.
FirebaseAdminCredentials
A partial representation of firebase admin object provided by firebase.
FirebaseAuth
Firebase Auth instance
FirebaseAuthBuilder
FirebaseToken
The claims of a decoded JWT token used in firebase
Validation
Contains the various validations that are applied after decoding a JWT.

Enums§

Algorithm
The algorithms supported for signing/verifying JWTs
EnvSource

Functions§

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