rocket-firebase-auth
Encode/decode Firebase tokens in Rocket apps with ease.
Getting started
1. Set Firebase service account keys as env variables
If you haven't already, create a service account for the Rocket server you are
adding firebase to. Generate a new private key and copy paste the generated json
into a .env
file.
FIREBASE_ADMIN_CERTS='{ "type": "service_account", ... }'
2. Create a FirebaseAuth
instance by reading the env variable
You can create a FirebaseAuth
struct by deserializing the env string that we set
into FirebaseAdmin
struct and call the FirebaseAuth::with_firebase_admin()
function.
dotenv.ok;
let firebase_admin_certs = var.unwrap;
let firebase_admin =
.unwrap;
let firebase_auth = with_firebase_admin;
3. Add FirebaseAuth
to the managed server state in Rocket
In order to access the FirebaseAuth
instance from our endpoint functions, add
it to the server state.
async
4. Verify the token from the endpoint function
On endpoints that we except to receive Authorization headers containing our encoded
Firebase tokens from the client, we can add a field to the endpoint function.
Running the Jwt::verify()
function will decode the token, where you can get the
Firebase uid
.
async
Example project
For a more detailed example with a frontend example as well, checkout the example projects .
Contribute
Any contributions (PRs, Issues) are welcomed!
License
MIT