Crates.io | firebase_jwt_rs |
lib.rs | firebase_jwt_rs |
version | 0.1.2 |
source | src |
created_at | 2023-01-05 15:07:01.7224 |
updated_at | 2023-01-06 05:50:26.659462 |
description | Firebase utils for JWT client token decoding |
homepage | |
repository | https://github.com/antonybudianto/firebase-rs |
max_upload_size | |
id | 751598 |
size | 9,418 |
Firebase JWT decoding utility for Rust.
If you have a Rust server and plan to have API for verifying your firebase users' client token, then it's just for you!
It only contains small utility to decode your client token.
Read more:
In your frontend, you can get your uid + client-token by using Firebase Client SDK.
Sample: https://firebase.google.com/docs/auth/admin/verify-id-tokens#retrieve_id_tokens_on_clients
Then your frontend can hit the backend Rust API and send over uid+client-token to the HTTP Header/POST body (up to you), which will be passed to verify_token(uid, client_token)
util.
Add FIREBASE_PROJECT_ID
environment variable to your backend on local and production server
Backend Rust will verify and send back the JWT claim response (including extracted user's data, and verified user_id) back as json
use firebase_jwt_rs::*;
use jsonwebtoken::TokenData;
use std::error::Error;
let uid = "your-user-uid";
let client_token = "your-client-token";
let result: Result<TokenData<Claims>, Box<dyn Error>> = verify_token(uid, client_token).await;
match result {
Ok(res: TokenData<Claims>) => {
let text: String = serde_json::to_string(&res.claims).unwrap();
println!("result:{text}");
}
Err(e) => {
println!("err:{e}");
}
}
MIT