Skip to main content

Crate bitwarden

Crate bitwarden 

Source
Expand description

§Bitwarden

A Rust client SDK to interact with the Bitwarden Secrets Manager. This is a beta release and might be missing some functionality.

To use this crate, add it to your Cargo.toml:

[dependencies]
bitwarden = { "*", features = ["secrets"] }

§Basic setup

All operations in this crate are done via a Client:

use bitwarden::{
    auth::login::AccessTokenLoginRequest,
    error::Result,
    secrets_manager::{secrets::SecretIdentifiersRequest, ClientSecretsExt},
    Client, ClientSettings, DeviceType,
};
use uuid::Uuid;

async fn test() -> Result<()> {
    // Use the default values
    let mut client = Client::new(None);

    // Or set your own values
    let settings = ClientSettings {
        identity_url: "https://identity.bitwarden.com".to_string(),
        api_url: "https://api.bitwarden.com".to_string(),
        user_agent: "Bitwarden Rust-SDK".to_string(),
        device_type: DeviceType::SDK,
        device_identifier: None,
        bitwarden_package_type: None,
        bitwarden_client_version: Some(env!("CARGO_PKG_VERSION").to_string()),
    };
    let mut client = Client::new(Some(settings));

    // Before we operate, we need to authenticate with a token
    let token = AccessTokenLoginRequest {
        access_token: String::from(""),
        state_file: None,
    };
    client.auth().login_access_token(&token).await.unwrap();

    let org_id = SecretIdentifiersRequest {
        organization_id: Uuid::parse_str("00000000-0000-0000-0000-000000000000").unwrap(),
    };
    println!(
        "Stored secrets: {:#?}",
        client.secrets().list(&org_id).await.unwrap()
    );
    Ok(())
}

Modules§

auth
Authentication module
client
Bitwarden SDK Client
error
Errors that can occur when using this SDK
generators
key_management
This module contains the definition for the key identifiers used by the rest of the crates. Any code that needs to interact with the KeyStore should use these types.
mobile
Mobile specific functionality.
platform
Platform code
secrets_manager

Macros§

require
This macro is used to require that a value is present or return an error otherwise. It is equivalent to using val.ok_or(Error::MissingFields)?, but easier to use and with a more descriptive error message. Note that this macro will return early from the function if the value is not present.

Structs§

Client
The main struct to interact with the Bitwarden SDK.
ClientSettings
Basic client behavior settings. These settings specify the various targets and behavior of the Bitwarden Client. They are optional and uneditable once the client is initialized.
MissingFieldError
Missing required field.
MissingPrivateKeyError
Missing private key.
NotAuthenticatedError
Client is not authenticated or the session has expired.
OrganizationId
NewType wrapper for OrganizationId
UserId
NewType wrapper for UserId
WrongPasswordError
Wrong password.
ZeroizingAllocator
Allocator wrapper that zeros on free

Enums§

ApiError
Errors from performing network requests.
DeviceType