Giter Site home page Giter Site logo

authy-rs's Introduction

Authy-rs

Bindings for the Authy two factor web service

Usage

Please see the Documentation for more details.

You will need your API key for your application on authy.com.

Be sure to add the authy crate to your Cargo.toml:

[dependencies]
authy = "*"

'low-level' Usage example:

extern crate authy;
use authy::{Client, AuthyError};
use authy::api::user;

fn main() {
    let api_url = "https://sandbox-api.authy.com";
    let api_key = "bf12974d70818a08199d17d5e2bae630";

    let c = Client::new(api_url, api_key);

    let country_code = 1;
    let email = "[email protected]";
    let phone = "949-555-1234";

    let (_, user) = user::create(&c, email, country_code, phone, true).unwrap();
   
    println!("We have a user: {:#?}", user);

    let code = "000000"; // Pretend user has provided a valid code
    match user::verify(&c, user.id, code) {
        Ok(_) => println!("Congrats on being validated!"),
        Err(AuthyError::UnauthorizedKey(e)) => println!("Token provided by the user was wrong"),
        Err(e) => println!("Some server error: {:?}", e),
    };

    // Lets send out a sms token just for fun
    // Must be using a real API key on the production authy server for this to
    // actually send out anything.
    user::sms(&c, user.id, true, Some("login"), Some("Authy documentation example login")).unwrap();
}

'high-level' Usage example:

extern crate authy;
use authy::{Client, User};

fn main() {
    let api_url = "https://sandbox-api.authy.com";
    let api_key = "bf12974d70818a08199d17d5e2bae630";

    let c = Client::new(api_url, api_key);

    let country_code = 1;
    let email = "[email protected]";
    let phone = "949-555-1234";

    let mut user = User::create(&c, email, country_code, phone, true).unwrap();

    println!("We have a user: {:#?}", user);

    let code = "000000"; // Pretend user has provided a valid code
    if user.verify(&c, code).unwrap() {
        println!("Congrats on being validated!");
    }

    // Lets send out a sms token just for fun
    // Must be using a real API key on the production authy server for this to
    // actually send out anything.
    user.sms(&c, true, Some("login"), Some("Authy documentation example login")).unwrap();
}

License

Authy-rs is licensed under either of

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Please see the CONTRIBUTING file for more information.

authy-rs's People

Contributors

bcmyers avatar lholden avatar marcusball avatar

Stargazers

 avatar

Watchers

 avatar  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.