GithubHelp home page GithubHelp logo

alex1607 / yubico_otp Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 25 KB

A Rust library for working and verifying YubiKey OTPs

Home Page: https://crates.io/crates/yubi_opt

Rust 100.00%
multifactor otp verification yubicloud-otp yubico yubico-otp yubikey

yubico_otp's Introduction

Rust YubicoOTP

This crate allows you to verify Yubico OTPs. To get details about what a Yubico OTP is you can read about it here: https://developers.yubico.com/OTP/

In order to use this crate you should first check the OTP of the user with the is_valid_otp function. If the OTP has the correct format you can send the OTP to Yubico for verification. To do that you will have to create a YubicoClient with your credentials. You can then call the verify function on it to send the request. Check if the result has the state Ok, if its any other state the OTP is invalid!

In case the state was Ok you will probably also want to check the public id of the key to compare it against the one you have on record. To get the public id of any OTP you can call the get_public_id function.

Code Example:

Do NOT use the credentials here, these are example credentials from the documentation!
Instead get your own api_key and client_id from here: https://upgrade.yubico.com/getapikey/

let client = YubicoClient::new(1, None);

let valid = is_valid_otp("vvungrrdhvtklknvrtvuvbbkeidikkvgglrvdgrfcdft");

let public_id = get_public_id("vvungrrdhvtklknvrtvuvbbkeidikkvgglrvdgrfcdft");

let x = client
.verify("vvungrrdhvtklknvrtvuvbbkeidikkvgglrvdgrfcdft")
.unwrap();

assert_eq!(x.state, State::Ok);

After that you can check if a) the public ID is as expected and b) if the state is Ok.
In case the otp is invalid from the is_valid_otp check you might return early to not send a request.

yubico_otp's People

Watchers

 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.