22个版本
0.11.0 | 2022年5月10日 |
---|---|
0.10.0 | 2021年2月11日 |
0.9.2 |
|
0.9.1 | 2020年7月18日 |
0.1.1 | 2016年12月2日 |
在身份验证中排名267
每月下载量3,019
30KB
634 行
Yubico

允许与Yubico验证平台集成,因此您可以在Rust应用程序中使用Yubikey的一次性密码,允许用户通过Yubikey进行身份验证。
当前功能
注意:与USB相关的功能已移动到单独的存储库,yubico-manager
用法
将其添加到您的Cargo.toml中
[dependencies]
yubico = "0.9"
以下是可以启用或禁用的Cargo功能列表
- online-tokio(默认启用):使用futures提供与Tokio的集成。
您可以使用下面的示例启用或禁用它们
[dependencies.yubico]
version = "0.9"
# don't include the default features (online-tokio)
default-features = false
# cherry-pick individual features
features = []
带有默认服务器的OTP
extern crate yubico;
use yubico::config::*;
use yubico::verify;
fn main() {
let config = Config::default()
.set_client_id("CLIENT_ID")
.set_key("API_KEY");
match verify("OTP", config) {
Ok(answer) => println!("{}", answer),
Err(e) => println!("Error: {}", e),
}
}
带有自定义API服务器的OTP
extern crate yubico;
use yubico::verify;
use yubico::config::*;
fn main() {
let config = Config::default()
.set_client_id("CLIENT_ID")
.set_key("API_KEY")
.set_api_hosts(vec!["https://api.example.com/verify".into()]);
match verify("OTP", config) {
Ok(answer) => println!("{}", answer),
Err(e) => println!("Error: {}", e),
}
}
异步OTP验证
#![recursion_limit="128"]
extern crate futures;
extern crate tokio;
extern crate yubico;
use futures::future::Future;
use yubico::verify_async;
extern crate yubico;
use std::io::stdin;
use yubico::config::Config;
fn main() {
println!("Please plug in a yubikey and enter an OTP");
let client_id = std::env::var("YK_CLIENT_ID")
.expect("Please set a value to the YK_CLIENT_ID environment variable.");
let api_key = std::env::var("YK_API_KEY")
.expect("Please set a value to the YK_API_KEY environment variable.");
let otp = read_user_input();
let config = Config::default()
.set_client_id(client_id)
.set_key(api_key);
tokio::run(verify_async(otp, config)
.unwrap()
.map(|_|{
println!("Valid OTP.");
})
.map_err(|err|{
println!("Invalid OTP. Cause: {:?}", err);
}))
}
fn read_user_input() -> String {
let mut buf = String::new();
stdin()
.read_line(&mut buf)
.expect("Could not read user input.");
buf
}
变更日志
- 0.10.0: Upgrade to `tokio` 1.1 and `reqwest` 0.11
- 0.9.2: (Yanked) Dependencies update
- 0.9.1: Set HTTP Proxy (Basic-auth is optional)
- 0.9.0: Moving to `tokio` 0.2 and `reqwest` 0.10
- 0.9.0-alpha.1: Moving to `futures` 0.3.0-alpha.19
- 0.8: Rename the `sync` and `async` modules to `sync_verifier` and `async_verifier` to avoid the use of the `async` reserved keyword.
依赖项
~4–19MB
~247K SLoC