1 个不稳定版本

0.1.0 2023年6月28日

#4 in #yubico

Download history 19/week @ 2024-04-01 41/week @ 2024-06-03 75/week @ 2024-06-10

每月下载量 116

Apache-2.0

20KB
454

yubico_otp

Yubikey 验证协议 2.0 客户端实现,使用 Rust 编写。

示例

use yubico_otp::{client::Client, params::ApiCredentials, params::ValidationOption};
use std::process::ExitCode;

#[tokio::main]
async fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let creds = ApiCredentials::from_base64_secret(
        "your_client_id".into(),
        "your_base64_secret_key",
    )?;
    let client = Client::new(&client, creds);
    let opt = ValidationOption::default();
    let (status, resp) = client
        .verify(std::env::args().nth(1).expect("OTP missing"), &opt)
        .await?;
    eprintln!("Status: {:?}", status);
    eprintln!("Response: {:?}", resp);
    Ok(if status.is_ok() {
       ExitCode::SUCCESS
    } else {
       ExitCode::FAILURE
    })
}

lib.rs:

Yubico OTP 验证库。

示例

use yubico_otp::{client::Client, params::ApiCredentials, params::ValidationOption};
use std::process::ExitCode;

#[tokio::main]
async fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let creds = ApiCredentials::from_base64_secret(
        "your_client_id".into(),
        "your_base64_secret_key",
    )?;
    let client = Client::new(&client, creds);
    let opt = ValidationOption::default();
    let (status, resp) = client
        .verify(std::env::args().nth(1).expect("OTP missing"), &opt)
        .await?;
    eprintln!("Status: {:?}", status);
    eprintln!("Response: {:?}", resp);
    Ok(if status.is_ok() {
       ExitCode::SUCCESS
    } else {
       ExitCode::FAILURE
    })
}

依赖项

~4–19MB
~251K SLoC