Skip to content
Bitwarden Logo

C++ SDK

The C++ language wrapper for interacting with the Bitwarden Secrets Manager. The SDK, like the Secrets Manager CLI built on-top of it, can be used to execute the following operations:

  • Authenticate using an access token.
  • Retrieve a single secret or all secrets in a project.
  • List all secrets, secrets in a project, or projects.

Requirements

Setting up a Secrets Manager account prior to using the C++ SDK is recommended. This includes:

GitHub Repository

Locate the C++ GitHub repository here.

Basic code examples

Client settings

Initialize BitwardenSettings by passing in api_url and identity_url. If these values are not defined in /.env, Bitwarden will use defaults https://api.bitwarden.com and https://identity.bitwarden.com for api_url and identity_url respectively.

// Optional - if not stressed, then default values are used
BitwardenSettings bitwardenSettings;
bitwardenSettings.set_api_url("<bitwarden-url>");
bitwardenSettings.set_identity_url("<bitwarden-identity>");

Create new Bitwarden client

Before using the client you must pass the accessToken:

std::string accessToken = "<access-token>";
// Optional - argument in BitwardenClient
BitwardenClient bitwardenClient = BitwardenClient(bitwardenSettings);
bitwardenClient.accessTokenLogin(accessToken);

Secrets Manager operations

Once the Bitwarden client has been created and authorized, Secrets Manager CLI commands can be passed into the client:

Projects

The project command is used to access, manipulate, and create projects. The scope of access assigned to your machine account will determine what actions can be completed with the project command.

create project

boost::uuids::uuid organizationUuid = boost::uuids::string_generator()("<organization-id>");
ProjectResponse projectResponseCreate = bitwardenClient.createProject(organizationUuid, "TestProject");

list projects

ProjectsResponse projectResponseList = bitwardenClient.listProjects(organizationUuid);

get project

boost::uuids::uuid projectId = boost::uuids::string_generator()(projectResponseCreate.get_id());
ProjectResponse projectResponseGet = bitwardenClient.getProject(projectId);

update project

boost::uuids::uuid projectId = boost::uuids::string_generator()(projectResponseCreate.get_id());
ProjectResponse projectResponseUpdate = bitwardenClient.updateProject(projectId, organizationUuid, "TestProjectUpdated");

delete projects

ProjectDeleteResponse projectDeleteResponse = bitwardenClient.deleteProjects({projectId});

Secrets

The secret command is used to access, manipulate and create secrets. As with all commands, secrets and projects outside your access token’s scope of access cannot be read or written-to.

create secret

std::string key = "key";
std::string value = "value";
std::string note = "note";
SecretResponse secretResponseCreate = bitwardenClient.createSecret(key, value, note, organizationUuid, {projectId});

list secrets

SecretIdentifiersResponse secretIdentifiersResponse = bitwardenClient.listSecrets(organizationUuid);

get secret

boost::uuids::uuid secretId = boost::uuids::string_generator()(secretResponseCreate.get_id());
SecretResponse secretResponseGet = bitwardenClient.getSecret(secretId);

update secret

SecretResponse secretResponseUpdate = bitwardenClient.updateSecret(secretId, "key2", "value2", "note2", organizationUuid, {projectId});

delete secrets

SecretsDeleteResponse secretsDeleteResponse = bitwardenClient.deleteSecrets({secretId});