Crates.io | firebase-auth-sdk |
lib.rs | firebase-auth-sdk |
version | 0.1.0 |
source | src |
created_at | 2023-02-10 16:52:06.750219 |
updated_at | 2023-02-10 16:52:06.750219 |
description | Firebase authentication SDK for rust. |
homepage | https://github.com/federicofusco/firebase-auth-sdk |
repository | https://github.com/federicofusco/firebase-auth-sdk |
max_upload_size | |
id | 781995 |
size | 84,346 |
Rust wrapper for Firebase Authentication REST API
Add the following to Cargo.toml:
firebase-auth-sdk = "0.1.5"
First you need to get a web API_KEY
from firebase project settings.
let api_key: String = String::from("s6FqaFcRFd...njhB8cCjN7");
let auth = firebase_auth_sdk::Auth::new(API_KEY);
Don't see what you need? See below for unsupported features for now.
let email = "something@email.com";
let password = "supersecret";
let return_secure_token = true;
match auth.sign_up_email(email, password, return_secure_token).await {
Ok(response) => ...,
Err(error) => ...,
}
// response structure
pub struct firebase_auth_sdk::api::SignUpResponse {
pub id_token: String,
pub email: String,
pub refresh_token: String,
pub expires_in: String,
pub local_id: String,
}
match auth.sign_in_email(email, password, return_secure_token).await {
Ok(response) => ...,
Err(error) => ...,
}
// response structure
pub struct firebase_auth_sdk::api::SignInResponse {
pub kind: String,
pub local_id: String,
pub email: String,
pub display_name: String,
pub id_token: String,
pub registered: bool,
pub refresh_token: Option<String>,
pub expires_in: Option<String>,
}
match auth.verify_email(id_token).await {
Ok(send_oob_code) => ...
Err(error) => ...
}
// response structure
pub struct firebase_auth_sdk::api::SendOobCode {
pub kind: String,
pub email: String,
}
match auth.reset_password(email).await {
Ok(send_oob_code) => ...
Err(error) => ...
}
match auth.refresh_id_token(refresh_token).await {
Ok(refresh_id_token_response) => ...
Err(error) => ...
}
// response structure
pub struct firebase_auth_sdk::api::RefreshIdToken {
pub access_token: String,
pub expires_in: String,
pub token_type: String,
pub refresh_token: String,
pub id_token: String,
pub user_id: String,
pub project_id: String,
}
match auth.get_user_info(id_token).await {
Ok(user) => ...,
Err(error) => ...,
}
// response structure
pub struct firebase_auth_sdk::api::User {
pub local_id: String,
pub email: String,
pub password_hash: String,
pub email_verified: bool,
pub password_updated_at: u64,
pub provider_user_info: Vec<ProviderUserInfo>,
pub valid_since: String,
pub last_login_at: String,
pub created_at: String,
pub last_refresh_at: String,
}
pub struct firebase_auth_sdk::api::ProviderUserInfo {
pub provider_id: String,
pub federated_id: String,
pub email: String,
pub raw_id: String,
}
match auth.change_email(id_token, email, return_secure_token).await {
Ok(update_user) => ...
Err(error) => ...
}
// response structure
pub struct firebase_auth_sdk::api::UpdateUser {
pub kind: String,
pub local_id: String,
pub email: String,
pub provider_user_info: Vec<ProviderUserInfo>,
pub password_hash: String,
pub email_verified: bool,
pub id_token: Option<String>,
pub refresh_token: Option<String>,
pub expires_in: Option<String>,
}
pub struct firebase_auth_sdk::api::ProviderUserInfo {
pub provider_id: String,
pub federated_id: String,
pub email: String,
pub raw_id: String,
}
match auth.change_password(id_token, password, return_secure_token).await {
Ok(update_user) => ...
Err(error) => ...
}
match auth.verify_id_token(id_token).await {
Ok(decoded) => ...
Err(error) => ...
}
pub struct firebase_auth_sdk::api::IdTokenClaims {
pub exp: u64,
pub iat: u64,
pub iss: String,
pub sub: String,
pub auth_time: u64,
}