Skip to content
stuft2Public

About

Knock once. Keep sending. HTTP requests with automatic host-based auth.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

knok

Overview

knok is an HTTP command-line client that selects authentication by hostname from a YAML configuration file. It supports API keys in HTTP headers, Bearer tokens, HTTP Basic authentication, and OAuth 2.0 client credentials and browser login. OAuth access tokens are refreshed automatically. Supply credentials through standard input and save them in encrypted sessions, or use them for a single request. Configuration files contain no secrets.

Status: v0 development. The configuration and command interface may change.

Installation

Prebuilt binaries (no Go required)

Download the archive matching your operating system and CPU from the latest release. Releases include macOS, Linux, and Windows binaries for amd64 (Intel/AMD) and arm64 (including Apple Silicon).

On macOS or Linux, extract the .tar.gz archive, then run these commands from the extracted directory:

mkdir -p "$HOME/.local/bin"
install -m 0755 knok "$HOME/.local/bin/knok"
export PATH="$HOME/.local/bin:$PATH"
knok --version

Add that export PATH line to your shell startup file to keep it available in new terminals. On Windows, extract the .zip and add the folder containing knok.exe to your user Path.

See the installation guide for platform selection, download commands, checksum verification, and Windows setup.

With Go

Requires Go 1.27.4 or newer:

go install github.com/stuft2/knok/cmd/knok@latest
knok_bin="$(go env GOBIN)"
export PATH="${knok_bin:-$(go env GOPATH)/bin}:$PATH"
knok --help

Go installs to GOBIN when configured, otherwise to the bin directory under GOPATH; make sure that directory is on your PATH. Use @main instead of @latest to install the current development branch.

How to Use This

knok https://api.example.com/users
knok -X POST -H 'Content-Type: application/json' -d '{"name":"Sam"}' https://api.example.com/users
knok --location --include https://example.com
knok -d @payload.json --output response.json https://api.example.com/users

Completed HTTP responses exit 0 by default, including 4xx and 5xx responses. Use --fail (-f) to exit 22 when the final HTTP status is 400 or higher and suppress the response body. Use --fail-with-body to exit 22 and keep the body on stdout or in the file selected by --output. Choose one mode per request. Both modes preserve --include status and headers and report failures on stderr.

Put authentication settings in ~/.config/knok/config.yaml (or $XDG_CONFIG_HOME/knok/config.yaml):

version: 2
hosts:
  api.example.com:
    auth:
      type: bearer

Pipe a token from your password manager to save an encrypted session:

op read 'op://Work/Example/token' |
  knok auth login --host api.example.com --token-stdin
knok https://api.example.com/users
knok auth status --host api.example.com
knok auth logout --host api.example.com

Use --secret-stdin for HTTP Basic passwords, API keys, and OAuth client secrets. For a single request, combine --token-stdin or --secret-stdin with --ephemeral. This mode uses credentials in memory without accessing saved sessions or the OS keyring. Saved sessions require access to the OS keyring. See configuration and authentication for browser login, headless operation, and migration from configuration version 1. The example configuration includes all authentication methods.

Use knok --help to list options and knok cache clear to remove legacy plaintext token caches. Response bodies go to standard output, and diagnostics go to standard error. A completed HTTP response returns exit status 0, including 4xx and 5xx responses. Runtime failures return 1; invalid arguments or configuration return 2.

API keys

Use type: api-key and header: X-API-Key, then pipe a key into knok auth login --host HOST --secret-stdin. See the API-key configuration guide for examples.

How to Build Locally

Requires Go 1.27.4 or newer.

git clone git@github.com:stuft2/knok.git
cd knok
go build -o knok ./cmd/knok
./knok --help

How to Publish

Release Please opens a version/changelog PR from Conventional Commits on main. Merging that PR creates a GitHub release with binaries and checksums for macOS, Linux, and Windows (amd64 and arm64). See release instructions.

Architectural Overview

The CLI uses Go's net/http client, parses configuration without secret values, and stores encrypted sessions with keys in the OS keyring. It handles OAuth authorization and token refresh. Runtime dependencies provide YAML parsing and OS keyring integration.

Configured authentication requires HTTPS. Redirects must be enabled explicitly and are restricted to the original origin. The CLI does not use curl or libcurl, match wildcard hosts, or retry requests at the application level.

How to Test

go test -race ./...
go vet ./...

CI runs formatting checks, go vet, race-enabled tests, and a build on pull requests and on main before release processing. Tests use temporary directories and local HTTP/TLS servers; no external API credentials are required. See development notes for the vulnerability check and dependency review.

Security

See the security policy for supported versions and private vulnerability reporting.

License

MIT © 2026 Spencer Tuft.

About

Knock once. Keep sending. HTTP requests with automatic host-based auth.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages