<!-- llms.txt: https://workos.com/llms.txt -->
<!-- feedback.md: https://workos.com/docs/feedback.md -->

# Quick Start

## Before getting started

To get the most out of these guides, you'll need:

- A [WorkOS account](https://dashboard.workos.com/)

Sign in to your WorkOS Dashboard account and create a new Organization.

![WorkOS Dashboard UI showing organization creation](https://images.workoscdn.com/images/a727afae-5af5-4403-936b-08bdcc009e3f.png?auto=format\&fit=clip\&q=50)

## What you'll build

In this guide, we will walk you through what you will need to set up Vault for securing and isolating organization-specific data:

- Encrypt and store data linked to an organization
- Retrieve the encrypted data
- Delete an object that's no longer in use

## API object definitions

[Object](https://workos.com/docs/reference/vault/object)
: Represents an encrypted key-value item stored by Vault.

[Organization](https://workos.com/docs/reference/organization)
: Describes an organization whose users sign in with a SSO Connection, or whose users are synced with a Directory Sync Connection.

## Add Vault to your app

### Install the WorkOS SDK

WorkOS offers native SDKs in several popular programming languages. Choose a language below to see instructions in your application's language.

Install the SDK using the command below.

:::code-group{title="Install the WorkOS SDK"}

```bash language="js" title="npm" tab="js-1"
npm install @workos-inc/node
```

```bash language="js" title="Yarn" tab="js-2"
yarn add @workos-inc/node
```

```bash language="ruby" title="Terminal" tab="ruby-5"
gem install workos
```

```rb language="ruby" title="Bundler" tab="ruby-6"
gem "workos"
```

```bash language="python"
pip install workos
```

```bash language="go"
go get github.com/workos/workos-go/v10
```

```bash language="php"
composer require workos/workos-php
```

```bash language="laravel"
composer require workos/workos-php-laravel
```

```xml language="java" title="Maven" tab="java-3"
<dependency>
  <groupId>com.workos</groupId>
  <artifactId>workos</artifactId>
  <version>{version}</version>
</dependency>
```

```groovy language="java" title="Gradle" tab="java-4"
dependencies {
  implementation 'com.workos:workos:VERSION'
}
```

```bash language="dotnet"
nuget install WorkOS.net
```

```elixir language="elixir"
def deps do
  [{:workos, "~> 3.1"}]
end
```

```bash language="rust"
cargo add workos
```

:::

### Set objects

To make calls to WorkOS, provide the API key and, in some cases, the client ID. Store these values as managed secrets, such as `WORKOS_API_KEY` and `WORKOS_CLIENT_ID`, and pass them to the SDKs either as environment variables or directly in your app's configuration based on your preferences.

```plain title="Environment variables"
WORKOS_API_KEY='sk_example_123456789'
WORKOS_CLIENT_ID='client_123456789'
```

> The code examples use your staging API keys when [signed in](https://dashboard.workos.com)

### Create an object

The Vault API and SDKs provide a method to encrypt and store a blob of data linked to a WorkOS organization. The encryption key used will be both unique to the KV item and cryptographically isolated from all other organizations.

:::code-group{title="Create an object"}

```js language="js"
import { WorkOS } from '@workos-inc/node';

const workos = new WorkOS('sk_example_123456789');

const organization = await workos.organizations.getOrganization(
  'org_01EHZNVPK3SFK441A1RGBFSHRT',
);

const object = await workos.vault.createObject({
  name: 'foo-corp-secret',
  value: 'secret value',
  context: { organizationId: organization.id },
});
```

```rb language="ruby"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.vault.create_kv(
  key_context: { organization_id: "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P" },
  name: "my-secret",
  value: "s3cr3t-v4lu3"
)
```

```py language="python"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.vault.create_kv(
    key_context={"organization_id": "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P"},
    name="my-secret",
    value="s3cr3t-v4lu3",
)
```

```go language="go"
// workos:manual - do not regenerate; see scripts/generate-sdk-snippets.ts
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.Vault().CreateKv(context.Background(), &workos.VaultCreateKvParams{
		KeyContext: map[string]string{"organization_id": "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P"},
		Name:       "my-secret",
		Value:      "s3cr3t-v4lu3",
	})
	if err != nil {
		// Handle the error according to your application's needs.
		return
	}
}
```

```php language="php"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos
    ->vault()
    ->createKv(
        keyContext: ["organization_id" => "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P"],
        name: "my-secret",
        value: "s3cr3t-v4lu3",
    );
```

```java language="java"
// workos:manual - target the current Java SDK
import com.workos.WorkOS;
import java.util.Map;

WorkOS workos = WorkOS.builder().apiKey("sk_example_123456789").build();

workos.getVault().createKv(Map.of("organization_id", "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P"),
    "my-secret",
    "s3cr3t-v4lu3");
```

```cs language="dotnet"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.Vault.CreateKvAsync(new VaultCreateKvOptions {
    KeyContext =
        new Dictionary<string, object> {
            { "organization_id", "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P" },
        },
    Name = "my-secret",
    Value = "s3cr3t-v4lu3",
});
```

```elixir language="elixir"
client =
  WorkOS.client(
    api_key: "sk_example_123456789",
    client_id: "client_123456789"
  )

WorkOS.Vault.create_kv(client, %{
  key_context: %{organization_id: "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P"},
  name: "my-secret",
  value: "s3cr3t-v4lu3"
})
```

```rust language="rust"
// workos:manual - target the current Rust SDK request model
use std::collections::HashMap;
use workos::vault::CreateKvParams;
use workos::{Client, CreateObjectRequest};

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _object = client
        .vault()
        .create_kv(CreateKvParams::new(CreateObjectRequest {
            key_context: HashMap::from([(
                "organization_id".into(),
                "org_01K8ZYT4AWJ6XP0E0S8CTBHE3P".into(),
            )]),
            name: "my-secret".into(),
            value: "s3cr3t-v4lu3".into(),
        }))
        .await?;

    Ok(())
}
```

:::

### Update the value of the object

Once created, the key context for an object cannot be changed. Only the value can be updated. The expected version of the object can be provided as a consistency lock when writing to the object.

:::code-group{title="Update the object"}

```js language="js"
const updatedObject = await workos.vault.updateObject({
  id: object.id,
  value: 'new value',
  versionCheck: object.metadata.versionId,
});
```

```rb language="ruby"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.vault.update_kv(
  id: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  value: "upd4t3d-v4lu3"
)
```

```py language="python"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.vault.update_kv(
    id_="a1b2c3d4-e5f6-7890-abcd-ef1234567890", value="upd4t3d-v4lu3"
)
```

```go language="go"
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.Vault().UpdateKv(context.Background(), "a1b2c3d4-e5f6-7890-abcd-ef1234567890", &workos.VaultUpdateKvParams{
		Value: "upd4t3d-v4lu3",
	})
	if err != nil {
		// Handle the error according to your application's needs.
		return
	}
}
```

```php language="php"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos
    ->vault()
    ->updateKv(
        id: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
        value: "upd4t3d-v4lu3",
    );
```

```java language="java"
// workos:manual - target the current Java SDK
import com.workos.WorkOS;

WorkOS workos = WorkOS.builder().apiKey("sk_example_123456789").build();

workos.getVault().updateKv("a1b2c3d4-e5f6-7890-abcd-ef1234567890", "upd4t3d-v4lu3");
```

```cs language="dotnet"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.Vault.UpdateKvAsync("a1b2c3d4-e5f6-7890-abcd-ef1234567890", new VaultUpdateKvOptions {
    Value = "upd4t3d-v4lu3",
});
```

```elixir language="elixir"
client =
  WorkOS.client(
    api_key: "sk_example_123456789",
    client_id: "client_123456789"
  )

WorkOS.Vault.update_kv(
  client,
  "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  %{value: "upd4t3d-v4lu3"}
)
```

```rust language="rust"
// workos:manual - target the current Rust SDK request model
use workos::vault::UpdateKvParams;
use workos::{Client, UpdateObjectRequest};

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _object = client
        .vault()
        .update_kv(
            "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
            UpdateKvParams::new(UpdateObjectRequest {
                value: "upd4t3d-v4lu3".into(),
                version_check: None,
            }),
        )
        .await?;

    Ok(())
}
```

:::

### Retrieve the object value

Objects can be listed, returning just the names of the objects. The metadata for each object can be queried - this provides more information about it without needing to decrypt the actual value. Fetching the object value will return the same metadata in addition to the unencrypted value.

:::code-group{title="Retrieve the object"}

```js language="js"
const id = 'secret_51B0AC67C2FB4247AC5ABDDD3C701BDC';

// List all objects
const objects = await workos.vault.listObjects();

// Fetch metadata for an object
const metadata = await workos.vault.describeObject({ id });

// Fetch full object
const object = await workos.vault.readObject({ id });
```

```rb language="ruby"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.vault.get_kv(id: "a1b2c3d4-e5f6-7890-abcd-ef1234567890")
```

```py language="python"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.vault.get_kv(id_="a1b2c3d4-e5f6-7890-abcd-ef1234567890")
```

```go language="go"
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.Vault().GetKv(context.Background(), "a1b2c3d4-e5f6-7890-abcd-ef1234567890")
	if err != nil {
		// Handle the error according to your application's needs.
		return
	}
}
```

```php language="php"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos->vault()->getKv(id: "a1b2c3d4-e5f6-7890-abcd-ef1234567890");
```

```java language="java"
// workos:manual - target the current Java SDK
import com.workos.WorkOS;

WorkOS workos = WorkOS.builder().apiKey("sk_example_123456789").build();

workos.getVault().getKv("a1b2c3d4-e5f6-7890-abcd-ef1234567890");
```

```cs language="dotnet"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.Vault.GetKvAsync("a1b2c3d4-e5f6-7890-abcd-ef1234567890");
```

```elixir language="elixir"
client =
  WorkOS.client(
    api_key: "sk_example_123456789",
    client_id: "client_123456789"
  )

WorkOS.Vault.get_kv(
  client,
  "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
)
```

```rust language="rust"
use workos::Client;

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _result = client
        .vault()
        .get_kv("a1b2c3d4-e5f6-7890-abcd-ef1234567890")
        .await?;

    Ok(())
}
```

:::

### Delete the object

When an object is no longer needed it can be marked for deletion. This will make the object unavailable to API operations, but the data will not be immediately deleted.

:::code-group{title="Delete the object"}

```js language="js"
await workos.vault.deleteObject({ id: object.id });
```

```rb language="ruby"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.vault.delete_kv(id: "a1b2c3d4-e5f6-7890-abcd-ef1234567890")
```

```py language="python"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.vault.delete_kv(id_="a1b2c3d4-e5f6-7890-abcd-ef1234567890")
```

```go language="go"
// workos:manual - do not regenerate; see scripts/generate-sdk-snippets.ts
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	err := client.Vault().DeleteKv(context.Background(), "a1b2c3d4-e5f6-7890-abcd-ef1234567890", &workos.VaultDeleteKvParams{})
	if err != nil {
		// Handle the error according to your application's needs.
		return
	}
}
```

```php language="php"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos->vault()->deleteKv(id: "a1b2c3d4-e5f6-7890-abcd-ef1234567890");
```

```java language="java"
// workos:manual - target the current Java SDK
import com.workos.WorkOS;

WorkOS workos = WorkOS.builder().apiKey("sk_example_123456789").build();

workos.getVault().deleteKv("a1b2c3d4-e5f6-7890-abcd-ef1234567890");
```

```cs language="dotnet"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.Vault.DeleteKvAsync("a1b2c3d4-e5f6-7890-abcd-ef1234567890");
```

```elixir language="elixir"
client =
  WorkOS.client(
    api_key: "sk_example_123456789",
    client_id: "client_123456789"
  )

WorkOS.Vault.delete_kv(
  client,
  "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
)
```

```rust language="rust"
// workos:manual - target the current Rust SDK method signature
use workos::vault::DeleteKvParams;
use workos::Client;

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    client
        .vault()
        .delete_kv(
            "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
            DeleteKvParams::default(),
        )
        .await?;

    Ok(())
}
```

:::
