Manage secrets in Insomnia with 1Password

Uses: Insomnia
TL;DR

Install the 1Password CLI. In Insomnia, navigate to Preferences > Plugins, allow elevated access to plugins, and install the Insomnia 1Password plugin. Configure the plugin with the __op_plugin environment variable, and use the 1Password template tag to fetch a secret.

Prerequisites

Download and install Insomnia.

This guide requires a 1Password account.

  1. Once you have an account, follow the steps in the 1Password docs to install 1Password CLI on the same system as Insomnia.
  2. Create a vault:
    op vault create insomnia
    
  3. Create a secret:
    op item create --category=login --title='test-secret' --vault='insomnia' \
     password='my-password'
    

Enable elevated access for plugins

The 1Password plugin needs to make system-level calls to the local 1Password CLI. To enable this, in Insomnia, navigate to Preferences > Plugins and select the Allow elevated access for plugins checkbox.

Install the 1Password plugin

Go to the Insomnia Plugin Hub and install the 1Password plugin.

Configure the plugin

The 1Password plugin is configured through a JSON environment variable. This environment variable can be defined with any environment type. In this example, we’ll configure it in a global base environment.

  1. In your project, click + Create and click Environment to create a new global environment.
  2. In the base environment disable Table View and add the following content, with the correct path and 1Password sign-in address:
    {
     "__op_plugin": {
       "cliPath": "/opt/homebrew/bin/op",
       "defaultAccount": "account-name.1password.com"
     }
    }
    

    Notes:

    • The cliPath parameter is the path to the 1Password CLI binary. This parameter is only required on macOS to avoid issues locating 1Password CLI.
    • The plugin also supports the cacheTTL and flags parameters. See the plugin configuration for more details.

Use a 1Password secret in a request

The 1Password plugin creates a custom template tag that you can configure to fetch a secret and use it in multiple places in a request.

  1. Create a collection or open an existing one.
  2. Click the environments on the left pane and select the global environment containing the 1Password configuration that we created in the previous step.
  3. Create a new request. For this example, we’ll send a POST request to http://httpbin.konghq.com/anything.
  4. Open the Body tab, click No Body and select Form Data.
  5. Enter a parameter name, secret for example.
  6. Click the value field field, press Control+Space to display the available template tags, and select 1Password => Fetch Secret.
  7. Click the template tag to configure it, and add the reference to the 1Password secret we created in the prerequisites: op://insomnia/test-secret/password. The live preview should show my-password.
  8. Click Done to apply the configuration.

Validate

To validate the configuration, send the request. The response should contain the secret field we added:

{
	"args": {},
	"data": "",
	"files": {},
	"form": {
		"secret": "my-password"
	},
	"headers": {
		"Accept": "*/*",
		"Content-Length": "110",
		"Content-Type": "multipart/form-data; boundary=X-INSOMNIA-BOUNDARY",
		"Host": "httpbin.konghq.com",
		"User-Agent": "insomnia/11.3.0"
	},
	"json": null,
	"method": "POST",
	"url": "http://httpbin.konghq.com/anything"
}

FAQs

No, currently Insomnia plugins are not supported in Inso CLI.

No, secrets are cached in memory only and not persisted to disk.

There are a few known issues that may be cause errors with the plugin. Make sure that everything is configured properly:

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!