fireauth 0.1.0

Firebase authentication for rust.
Documentation

How to use

First you need to get a web API_KEY from firebase project settings.

let api_key: String = "s6FqaFcRFd...njhB8cCjN7".to_owned();

let fireauth = fireauth::FireAuth::new(API_KEY);

Features

  1. Sign Up (email)
  2. Sign In (email)
  3. Send OOB Code
  4. Refresh ID Token
  5. Get User Information
  6. Update Email and Password

Don't see what you need? See below for unsupported features for now.

1. Sign Up (email)

let email = "something@email.com".to_owned();
let password = "supersecret".to_owned();
let return_secure_token = true;

match fireauth.sign_up_email(email, password, return_secure_token).await {
    Ok(response) => ...,
    Err(error) => ...,
}

// response structure
struct SignUpResponse {
    id_token: String,
    email: String,
    refresh_token: String,
    expires_in: String,
    local_id: String,
}

2. Sign In (email)

match fireauth.sign_in_email(email, password, return_secure_token).await {
    Ok(response) => ...,
    Err(error) => ...,
}

// response structure
struct SignInResponse {
    kind: String,
    local_id: String,
    email: String,
    display_name: String,
    id_token: String,
    registered: bool,
    refresh_token: Option<String>,
    expires_in: Option<String>,
}

3. Send OOB Code

Send verification email

match fireauth.verify_email(id_token).await {
    Ok(send_oob_code) => ...
    Err(error) => ...
}

// response structure
struct SendOobCode {
    kind: String,
    email: String,
}

Send reset password

match fireauth.reset_password(email).await {
    Ok(send_oob_code) => ...
    Err(error) => ...
}

4. Refresh ID Token

match fireauth.refresh_id_token(refresh_token).await {
    Ok(refresh_id_token_response) => ...
    Err(error) => ...
}

// response structure
struct RefreshIdToken {
    access_token: String,
    expires_in: String,
    token_type: String,
    refresh_token: String,
    id_token: String,
    user_id: String,
    project_id: String,
}

5. Get User Information

match fireauth.get_user_info(id_token).await {
    Ok(user) => ...,
    Err(error) => ...,
}

// response structure
struct User {
    local_id: String,
    email: String,
    password_hash: String,
    email_verified: bool,
    password_updated_at: u64,
    provider_user_info: Vec<ProviderUserInfo>,
    valid_since: String,
    last_login_at: String,
    created_at: String,
    last_refresh_at: String,
}

struct ProviderUserInfo {
    provider_id: String,
    federated_id: String,
    email: String,
    raw_id: String,
}

6. Update Email and Password

Email

match fireauth.change_email(id_token, email, false).await {
    Ok(update_user) => ...
    Err(error) => ...
}

// response structure
struct UpdateUser {
    kind: String,
    local_id: String,
    email: String,
    provider_user_info: Vec<ProviderUserInfo>,
    password_hash: String,
    email_verified: bool,
    id_token: Option<String>,
    refresh_token: Option<String>,
    expires_in: Option<String>,
}

struct ProviderUserInfo {
    provider_id: String,
    federated_id: String,
    email: String,
    raw_id: String,
}

Password

match fireauth.change_password(id_token, password, true).await {
    Ok(update_user) => ...
    Err(error) => ...
}

What are not supported yet

Sign In

  • Sign in anonymously
  • Sign in with OAuth credential

Password

  • Verify password reset code
  • Confirm password reset

User

  • Update profile
  • Delete account