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.
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).
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}}.