Skip to main content

Load secrets using 1Password SDKs

You can use 1Password SDKs to securely load secrets into your code with secret references. Before you begin, follow the steps to get started with a 1Password SDK.

You can retrieve secrets from supported field types. You can also retrieve one-time passwords using the otp attribute parameter.

A valid secret reference should use the syntax:

To get a one-time password, append the ?attribute=otp query parameter to a secret reference that points to a one-time password field in 1Password:

TIP

See the examples folder in the 1Password Go, JavaScript, or Python SDK GitHub repository for example code you can quickly clone and test in your project.

Load a secret from 1Password

Replace the placeholder secret reference in the example with a secret reference URI that specifies the vault, item, section (if applicable), and field where the secret is saved in your 1Password account.

If you have multiple vaults, items, or fields that share the same name, use a unique identifier instead of the name in the secret reference.

The resolve function resolves the secret reference and returns the value of the 1Password field it references. You can then use this value in your code, like to authenticate to another service.

Retrieve multiple secrets

You can use the secrets.resolveAll function to retrieve secrets from 1Password in bulk, improving the performance of the operation.

Replace the placeholder secret references in the example with secret reference URIs that specify the vault, item, section (if applicable), and field where the secrets are saved in your 1Password account.

Validate a secret reference

You can use the secret reference validation function to make sure that your secret reference is formatted correctly.

If the secret reference is formatted incorrectly, the SDK will return an error that describes the syntax problem. Learn more about secret references.

Learn more

Was this page helpful?