Giter Site home page Giter Site logo

firebase-user's Introduction

Fire Auth

Rust wrapper for Firebase Authentication REST API

WTFPL WTFPL

Installation

Add the following to Cargo.toml:

firebase-user = "0.2"

How to use

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

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

let auth = firebase_user::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 = "[email protected]";
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_user::api::SignUpResponse {
    pub id_token: String,
    pub email: String,
    pub refresh_token: String,
    pub expires_in: String,
    pub local_id: String,
}

2. Sign In (email)

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

// response structure
pub struct firebase_user::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>,
}

3. Send OOB Code

Send verification email

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

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

Send reset password

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

4. Refresh ID Token

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

// response structure
pub struct firebase_user::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,
}

5. Get User Information

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

// response structure
pub struct firebase_user::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_user::api::ProviderUserInfo {
    pub provider_id: String,
    pub federated_id: String,
    pub email: String,
    pub raw_id: String,
}

6. Update Email and Password

Email

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

// response structure
pub struct firebase_user::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_user::api::ProviderUserInfo {
    pub provider_id: String,
    pub federated_id: String,
    pub email: String,
    pub raw_id: String,
}

Password

match auth.change_password(id_token, password, return_secure_token).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

firebase-user's People

Contributors

the-robot avatar nottxy avatar jadkhaddad avatar

Stargazers

TANIGUCHI Takaki avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.