Skip to main content
hitspec supports 8 authentication methods through the # @auth metadata directive. Instead of manually constructing Authorization headers, declare your auth method and hitspec handles the rest.

Syntax

All parameters support {{variable}} interpolation. Separate the parameters with commas (basic alice, s3cret) or with whitespace (basic alice s3cret). If the line contains a comma outside {{ ... }} it is split on commas, so a value may then contain spaces; a comma inside {{ ... }} (for example {{$random(1, 5)}}) never splits. For the OAuth2 grants, every parameter after the required ones is part of the scope list. hitspec checks the method name and the number of parameters when it parses the file. An unknown method (@auth magic foo) or a wrong parameter count is a parse error: hitspec validate reports it and exits with code 2 instead of sending the request without credentials.

Methods

bearer

Sends an Authorization: Bearer <token> header.
Generated header: Authorization: Bearer <token>

basic

Sends a Base64-encoded Authorization: Basic <credentials> header.
Generated header: Authorization: Basic <base64(username:password)>

apiKey

Sends the API key as a custom request header.
Generated header: <headerName>: <value>

apiKeyQuery

Appends the API key as a URL query parameter.
Effect: Appends ?api_key=<value> to the request URL.

digest

HTTP Digest authentication. hitspec handles the challenge-response handshake automatically.

aws

Signs requests using AWS Signature Version 4 for AWS services or compatible APIs (e.g., MinIO, LocalStack).
With temporary credentials, add the session token as a fifth argument:
If the fifth argument is left out and the access key equals $AWS_ACCESS_KEY_ID, hitspec uses $AWS_SESSION_TOKEN when it is set. A >>>multipart body is signed over the exact bytes sent.

oauth2 client_credentials

Fetches an access token using the OAuth2 Client Credentials grant, then sends it as a Bearer token.

oauth2 password

Fetches an access token using the OAuth2 Resource Owner Password Credentials grant.

Quick Reference


Using Auth with Captures

Capture a token from a login response and use it in subsequent requests:
Store credentials in environment variables or hitspec.yaml environments to keep them out of your test files. Reference them with {{$env(VAR)}} or {{variableName}}.
Last modified on October 19, 2026