Skip to content

Auth & Request Signing

Recon can add credentials to a request for you. You describe the scheme once with a # @auth directive, and Recon adds the right header or query parameter each time the request is sent. It can also fetch and cache OAuth 2.0 tokens and sign requests with AWS Signature Version 4 or an HMAC. The recon auth commands let you fetch tokens, run a browser login, and preview signatures without sending anything.

### Bearer
# @name auth-bearer
# @auth {"kind":"bearer","token":"{{DEV_API_TOKEN}}"}
GET http://127.0.0.1:4310/echo
Terminal window
recon --format human send auth-bearer
GET http://127.0.0.1:4310/echo 200 0.7ms 218B -> 218B (HTTP/1.1)
{
"method": "GET",
"path": "/echo",
"headers": {
"host": "127.0.0.1:4310",
"user-agent": "recon/0.3.2",
"accept-encoding": "gzip, br, deflate",
"authorization": "Bearer rk_dev_sandbox_9981"
},
...

The examples on this page send to a local server that echoes the request back, so you can see exactly what Recon added.

# @auth takes one line of JSON. The kind field picks the scheme. String fields accept {{variable}} templates, so you can keep credentials in an environment or in the vault.

The directive must appear above the request line. If the JSON is invalid, the whole workspace fails to load, and every command that reads collections reports the error:

error E_CLI_RUNTIME: parse error in `@auth`: invalid @auth JSON directive: missing field `location`

The same object is the auth field of a request in the HTTP API and MCP request model.

kind Adds
none Nothing. This is the default.
bearer Authorization: Bearer <token>
basic Authorization: Basic base64(username:password)
api_key A header or a query parameter.
oauth2 Authorization: Bearer <access token> from the token cache.
aws_sigv4 Authorization, X-Amz-Date, X-Amz-Content-Sha256, and X-Amz-Security-Token when a session token is set.
hmac A signature header, and optionally a timestamp header.
# @auth {"kind":"bearer","token":"{{DEV_API_TOKEN}}"}
Field Required Meaning
token yes Token value.

If the request already has an Authorization header, Recon leaves it alone:

# @auth {"kind":"bearer","token":"from-auth"}
GET http://127.0.0.1:4310/echo
Authorization: Bearer from-header
"authorization": "Bearer from-header"
# @auth {"kind":"basic","username":"alice","password":"wonderland"}
"authorization": "Basic YWxpY2U6d29uZGVybGFuZA=="
Field Required Meaning
username yes User name.
password yes Password.

An existing Authorization header wins, as with bearer. When the password comes from a secret variable, Recon also records the Base64 username:password string against that secret, so the encoded form is tracked too.

# @auth {"kind":"api_key","key":"X-Api-Key","value":"{{DEV_API_TOKEN}}","location":"header"}
# @auth {"kind":"api_key","key":"api_key","value":"plain-demo-key","location":"query"}
Field Required Meaning
key yes Header name or query parameter name.
value yes Key value.
location yes header or query.

With header, an existing header of the same name wins. With query, the parameter is always appended to the URL:

GET http://127.0.0.1:4310/echo?api_key=plain-demo-key 200 0.6ms 192B -> 192B (HTTP/1.1)
# @auth {"kind":"oauth2","token_url":"http://127.0.0.1:4301/_sandbox/oauth/token","client_id":"docs-client","client_secret":"cs_demo","scope":"read:students"}
"authorization": "Bearer recon_sandbox_tok_docs-client_client_credentials"
Field Required Default Meaning
grant no client_credentials client_credentials, authorization_code or refresh_token.
token_url yes Token endpoint.
auth_url no Authorization endpoint. Used only by the browser login.
client_id yes Client ID.
client_secret no Client secret.
scope no Space-separated scopes.
audience no audience parameter.
profile no <client_id>@<token host> Key in the token cache.
use_pkce no true Use PKCE in the browser login.

What happens on each send:

  1. Recon looks up profile in the token cache. A token that has not expired is used as is.
  2. Otherwise, if grant is refresh_token, or a refresh token is cached for the profile, Recon refreshes. If no refresh token is cached, the request fails with no refresh_token cached for `<profile>` .
  3. Otherwise, if grant is client_credentials, Recon requests a new token.
  4. Otherwise (authorization_code with nothing cached), the request fails:
error E_CLI_RUNTIME: OAuth 2.0 error: no valid cached token for OAuth profile `fresh-client@127.0.0.1`; run `recon auth oauth2-login` first

The token is sent as Authorization: Bearer <token>. Unlike bearer and basic, this replaces any Authorization header already on the request. The word Bearer is used whatever token_type the server returned.

# @auth {"kind":"aws_sigv4","access_key_id":"AKIDEXAMPLE","secret_access_key":"wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY","region":"us-east-1","service":"execute-api"}
POST http://127.0.0.1:4310/echo?b=2&a=1
Content-Type: application/json
{"ping": true}
"content-type": "application/json",
"x-amz-date": "20261130T154949Z",
"x-amz-content-sha256": "8504a88517d0b77bc2c674eb1081f163c16115bd083a61f31617349cd1a3b3d3",
"authorization": "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20261130/us-east-1/execute-api/aws4_request, SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date, Signature=54b76d967093843ab93e126a49ccda5d9f597aec2c6047720a4a2ef1c5720d2b",
Field Required Meaning
access_key_id yes Access key ID. Must not be empty.
secret_access_key yes Secret access key. Must not be empty.
session_token no STS session token, sent as X-Amz-Security-Token and signed.
region yes Region, for example us-east-1.
service yes Service name, for example execute-api or s3.

The added headers replace any existing headers of the same name.

# @auth {"kind":"hmac","secret":"whsec_demo","timestamp_header":"X-Timestamp"}
"x-timestamp": "1796053790",
"x-signature": "85e75ff605481cce0a7ac48442b221f86fedaea76f208dd9a5269953530c7885",
Field Required Default Meaning
secret yes Shared secret. Must not be empty.
algorithm no sha256 sha256 or sha512.
encoding no hex hex (lowercase) or base64 (standard, padded).
header_name no X-Signature Header that receives the signature.
timestamp_header no Header that receives the timestamp. Omitted when not set.
payload_template no {timestamp}\n{method}\n{path}\n{body} The string that is signed.

The added headers replace any existing headers of the same name.

Recon builds the signature itself:

  • Algorithm: AWS4-HMAC-SHA256. The timestamp is the current UTC time in YYYYMMDDTHHMMSSZ form. The credential scope is <YYYYMMDD>/<region>/<service>/aws4_request.
  • Signed headers: every header on the request at signing time, except Authorization, X-Amz-Date and X-Amz-Content-Sha256 (which Recon sets itself). Names are lowercased. Values have runs of whitespace collapsed to one space. Repeated names are merged with commas. Headers are sorted by name.
  • Added to the signed set: host (the URL host, with :port when the URL has an explicit port) unless the request sets Host; x-amz-date; x-amz-content-sha256; and x-amz-security-token when a session token is set.
  • Payload hash: lowercase hex SHA-256 of the request body. It is always sent as X-Amz-Content-Sha256. There is no unsigned-payload option.
  • Canonical URI: the URL path in its percent-encoded form, encoded once more with AWS rules (unreserved characters and / kept). An existing % becomes %25. An empty path is /.
  • Canonical query: query pairs are decoded, re-encoded with AWS rules, and sorted by name, then value.

Signing happens before Recon adds its default headers (User-Agent, Accept-Encoding, Content-Length, Cookie), so those are not signed. Headers set by a pre-request script are signed, because the script runs first.

The payload template is filled in by plain text replacement:

Placeholder Value
{timestamp} Current Unix time in seconds.
{method} HTTP method, for example POST.
{path} URL path, percent-encoded as in the URL.
{query} Raw query string without the ?; empty when there is none.
{body} Request body as UTF-8 text.

The result is signed with HMAC-SHA256 or HMAC-SHA512 using the secret’s UTF-8 bytes as the key. The timestamp header (when configured) is added first, then the signature header. Both carry the same timestamp that was used in the template.

# @auth {"kind":"hmac","secret":"whsec_demo","algorithm":"sha512","encoding":"base64","header_name":"X-Hub-Signature","payload_template":"{method} {path}?{query}"}
"x-hub-signature": "22iFcp3n9zfNkzWUt30qNai4fljn6c9q+8ciolEio0cKMjCx+NkiH2MAeX8y9Bmj0LTe/TTYsnTANJfbr/g8yQ=="

Every token request is a POST to token_url with an application/x-www-form-urlencoded body and Accept: application/json. The client secret is sent in the body as client_secret (never as HTTP Basic), and only when it is not empty.

Grant Form fields
Client credentials grant_type=client_credentials, client_id, client_secret, scope, audience
Refresh grant_type=refresh_token, refresh_token, client_id, client_secret
Authorization code grant_type=authorization_code, code, redirect_uri, client_id, client_secret, code_verifier

The token request goes through the Outbound Secret Firewall like any other request.

The response must be JSON with a non-empty access_token. Recon reads token_type (default Bearer), refresh_token, scope (falls back to the requested scope) and expires_in. Errors:

Message Cause
token endpoint returned HTTP <status>: <body> Status 400 or higher.
invalid JSON from token endpoint: ... The body is not JSON.
token response missing `access_token` No access_token.

Tokens are stored in .recon/tokens.json in the workspace, written with mode 0600 on Unix. recon init adds this file to .gitignore. It is a JSON object keyed by profile. Each entry holds profile, token_url, access_token, token_type, refresh_token, scope, expires_at_utc, allowed_hosts and updated_at_utc. The access and refresh tokens are stored in plain text in this file.

A token counts as expired 30 seconds before expires_at_utc. A token without expires_in never expires in the cache.

allowed_hosts is the list of hosts that may receive the token. The firewall enforces it. It is set when the token is fetched:

  • From # @auth: the request’s # @taint-scope hosts, or else the host of the request URL.
  • From recon auth oauth2-token or oauth2-login: the --host values, or else the token endpoint host.

If a cached token has no hosts, the request’s # @taint-scope hosts are used.

recon auth oauth2-login runs the authorization code flow:

  1. Recon opens a listener on 127.0.0.1 with a port chosen by the operating system. The redirect URI is http://127.0.0.1:<port>/callback.
  2. It prints an authorization URL with response_type=code, client_id, redirect_uri, a random state, scope and audience (when set), and code_challenge with code_challenge_method=S256. The verifier is 43 Base64URL characters. Recon does not open a browser; open the URL yourself.
  3. It accepts the first connection to the listener. If the callback has error or error_description, or the state does not match, the login fails and the browser gets a 400 page. Otherwise the browser gets a “Recon Authorized” page and Recon exchanges the code.
  4. The token is cached under the profile.

The port changes on every run, so your OAuth client registration has to accept a loopback redirect URI on any port.

Shows which secret providers are available and lists cached OAuth profiles. No token values are printed.

Terminal window
recon --format human auth status
Providers: age_unlocked=false, dotenv=false, op_cli=false, keychain=false
- docs-client@127.0.0.1 (http://127.0.0.1:4301/_sandbox/oauth/token) expired=false refresh=true hosts=["127.0.0.1"] [e133cc412d1a]

The bracketed value is a fingerprint: the first 12 hex characters of the SHA-256 of the access token. With --format json, the output has providers, vault (the vault status) and profiles. Each profile has profile, token_url, token_type, scope, expires_at_utc, is_expired, has_refresh_token, token_fingerprint and allowed_hosts.

Fetches a token with the client credentials grant, or refreshes a cached one, and stores it in the cache.

Terminal window
recon --format human auth oauth2-token \
--token-url http://127.0.0.1:4301/_sandbox/oauth/token \
--client-id ci-bot --scope "read:students" --host 127.0.0.1
OK OAuth2 token cached for `ci-bot@127.0.0.1` [474b338d3ba0] (refresh=true)
Terminal window
recon --format json auth oauth2-token \
--token-url http://127.0.0.1:4301/_sandbox/oauth/token --client-id ci-bot --refresh
{
"token": {
"allowed_hosts": [
"127.0.0.1"
],
"expires_at_utc": "2026-11-30T16:49:58.045666493+00:00",
"has_refresh_token": true,
"is_expired": false,
"profile": "ci-bot@127.0.0.1",
"scope": "read:students write:enrollments",
"token_fingerprint": "09d6d468574c",
"token_type": "Bearer",
"token_url": "http://127.0.0.1:4301/_sandbox/oauth/token"
}
}
Flag Required Meaning
--token-url yes Token endpoint.
--client-id yes Client ID.
--client-secret no Client secret.
--scope no Space-separated scopes.
--audience no audience parameter.
--profile no Cache key. Default <client_id>@<token host>.
--host no, repeatable Hosts allowed to receive the token.
--refresh no Use the cached refresh token instead of client credentials.
--env no Environment for {{variable}} templates. Defaults to the workspace default.

Runs the browser login described above.

Terminal window
recon --format human auth oauth2-login \
--auth-url http://127.0.0.1:4301/_sandbox/oauth/authorize \
--token-url http://127.0.0.1:4301/_sandbox/oauth/token \
--client-id spa-client --scope "read:students" --profile spa

On standard error:

Open in browser to authenticate:
http://127.0.0.1:4301/_sandbox/oauth/authorize?response_type=code&client_id=spa-client&redirect_uri=http%3A%2F%2F127.0.0.1%3A45721%2Fcallback&state=474764f7c57f43aab8a668674fd277ff&scope=read%3Astudents&code_challenge=nBSrZ_bjKLkLufgD6EGtgNEoQdhtPW5WONL8skV__ns&code_challenge_method=S256
Waiting on http://127.0.0.1:45721/callback (timeout 180s)...

After the callback, on standard output:

OK PKCE login cached `spa` [b5f70d0f303f]
Flag Required Default Meaning
--auth-url yes Authorization endpoint.
--token-url yes Token endpoint.
--client-id yes Client ID.
--client-secret no Client secret, sent in the code exchange.
--scope no Space-separated scopes.
--audience no audience parameter.
--profile no <client_id>@<token host> Cache key.
--host no, repeatable token endpoint host Hosts allowed to receive the token.
--pkce no on PKCE is always used; this flag cannot turn it off.
--timeout-secs no 180 How long to wait for the callback. Values under 5 wait 5 seconds.
--env no workspace default Environment for {{variable}} templates.

If no callback arrives in time:

error E_CLI_RUNTIME: OAuth 2.0 error: timed out waiting for OAuth callback

The recon ui server includes an offline sandbox authorization endpoint at /_sandbox/oauth/authorize and token endpoint at /_sandbox/oauth/token, which the examples on this page use. See Offline Sandboxes.

Computes AWS SigV4 or HMAC headers for a request without sending it.

Terminal window
recon --format human auth sign-preview \
--url 'https://abc123.execute-api.us-east-1.amazonaws.com/prod/items?limit=10' \
--access-key-id AKIDEXAMPLE --secret wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY \
--session-token FQoGZXIvYXdzEXAMPLE
Scheme: aws_sigv4 (20261130/us-east-1/execute-api/aws4_request)
X-Amz-Date: 20261130T155044Z
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Security-Token: FQoGZXIvYXdzEXAMPLE
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20261130/us-east-1/execute-api/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=effb645489c96de81aa62efbd048d4dbf2d134ed35cfd1fcd929ac9a382f76ee
Terminal window
recon --format json auth sign-preview --scheme hmac --method POST \
--url 'https://hooks.example.com/ingest?v=1' --body '{"id":1}' \
--secret whsec_demo --timestamp-header X-Timestamp
{
"preview": {
"canonical_preview": "1796053844\nPOST\n/ingest\n{\"id\":1}",
"credential_scope": "hmac-sha256",
"headers": [
{
"name": "X-Timestamp",
"value": "1796053844"
},
{
"name": "X-Signature",
"value": "b67a05476a319e8d23cf2f3251f3da0b77093139f96df11ad009d291d564196c"
}
],
"scheme": "hmac-sha256"
}
}

For AWS, canonical_preview holds the string to sign (algorithm, timestamp, scope and the hash of the canonical request). For HMAC it holds the filled-in payload template. Neither includes the secret, but the human and JSON output both include the full Authorization header or signature.

Flag Default Meaning
--scheme aws_sigv4 aws_sigv4. Any other value means HMAC.
--method GET HTTP method.
--url required URL to sign.
--body "" Request body.
--secret required AWS secret access key or HMAC secret. Secret references are resolved.
--access-key-id AWS access key ID. Secret references are resolved.
--session-token AWS session token. Secret references are resolved.
--region us-east-1 AWS region.
--service execute-api AWS service.
--algorithm sha256 sha512, or anything else for SHA-256.
--encoding hex base64, or anything else for hex.
--header-name X-Signature HMAC signature header.
--timestamp-header HMAC timestamp header.
--payload-template {timestamp}\n{method}\n{path}\n{body} HMAC payload template. The two characters \n are turned into a newline.

sign-preview signs with no request headers, so for AWS the signed set is only host, x-amz-content-sha256, x-amz-date and, with a session token, x-amz-security-token. A real request also signs its own headers, such as Content-Type.

# @auth is applied in full (including secret references, OAuth 2.0, SigV4 and HMAC) by:

  • recon send, recon twin, recon test and recon watch,
  • recon graphql, recon sse, recon ws and recon grpc,
  • the HTTP API POST /api/v1/send and POST /api/v1/twin,
  • the MCP tools recon_send_request and recon_twin_run.

For sse, ws and grpc, an OAuth 2.0 token request uses a client without the proxy, custom CA and cookie settings described in Transport.

  • Web Studio: the Vault button in the top bar opens a dialog with Age Vault, OAuth 2.0 / OIDC and SigV4 & HMAC tabs. The command palette has Open OAuth 2.0 / OIDC Token Manager and Open AWS SigV4 & HMAC Signer.
  • HTTP API (mutating calls need the X-Recon-Token header):
    • GET /api/v1/auth/oauth2/status lists cached profiles (metadata only).
    • POST /api/v1/auth/oauth2/token fetches a token. grant: "refresh_token" refreshes; any other grant runs client credentials. The body takes the same fields as the CLI flags (token_url, client_id, client_secret, scope, audience, profile, allowed_hosts, env).
    • POST /api/v1/auth/oauth2/pkce/start starts a browser login and returns session_id, authorize_url and redirect_uri. timeout_secs defaults to 180 and is clamped to the range 5 to 600. use_pkce: false turns PKCE off.
    • GET /api/v1/auth/oauth2/pkce/{session_id} returns the login state: pending, completed (with token) or failed (with error).
    • DELETE /api/v1/auth/oauth2/{profile} removes a cached profile. There is no CLI command for this.
    • POST /api/v1/auth/sign/preview is the HTTP form of sign-preview. The session token is not resolved as a secret reference here.
  • MCP: recon_auth_status returns provider availability and cached profile metadata. See MCP Tools, Resources & Prompts.