Skip to main content

Crate yubico_ng

Crate yubico_ng 

Source
Expand description

§yubico_ng

A Yubico OTP validation library for Rust.

Should be compatible with third-party servers which support the Yubico Validation Protocol Version 2.0.

§Usage

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

[dependencies]
yubico_ng = "1"

You need to have a valid Client ID and API Key. These can be obtained from Yubico via https://upgrade.yubico.com/getapikey/ Without a valid Client ID and API Key you can not validate any OTP key registered at Yubico.

§Features

As a default features we have reqwest and default-tls enabled. This provides quick usage of this crate with reqwest as the transport client.

Other features you can use, either together with the default or without the default.

  • reqwest: (default) Enables the reqwest crate and provides client transports for ease of use
  • default-tls (default): Uses the default-tls set at the reqwest crate
  • native-tls: Uses the reqwest/native-tls feature to use the system provided TLS library
  • reqwest-blocking: Provides a blocking reqwest client transport for ease of use Ensure that if you use default-features = false that you also enable a TLS engine either by using one of the -tls features mentioned above, or enable a TLS engine your self

§Example

A simple example on how to use this library. Also checkout the examples directory for some more examples.

async fn main() {
    use yubico_ng::{config::Config, verify};
    // Extract the `client_id` and `api_key` from a safe location, do not embed them in your code!
    let client_id = "012345678901";
    let api_key = "Base64/Base64/Base64/Base64=";
    let config = Config::default()
        .set_client_id(client_id)
        .set_key(api_key)
        .expect("Invalid API key (must be Base64)");

    // Retrieve the users OTP via a safe way
    let otp = "vvcbdefghijklnrtuvcbdefghijklnrtuvcbdefghijk";

    match verify(otp, config).await {
        Ok(()) => println!("Valid OTP."),
        Err(e) => println!("Error: {e}"),
    }
}

For more example on how to use this crate I would suggest to checkout the examples directory.

Re-exports§

pub use asynchronous::verify;reqwest
pub use error::YubicoError;

Modules§

asynchronous
Provides async yubico_ng::verify(otp, cfg).await
blocking
Provides blocking yubico_ng::blocking::verify(otp, cfg)
config
Provides Config and ProxyConfig
error
Provided YubicoError
transport
Provide a client agnostic transport if you do not want to use reqwest or use your own client

Structs§

Verifier
Verifier struct which contains the config and HTTP client

Type Aliases§

Result
Result used by yubico_ng Provides either Ok<T> or Err<YubicoError>