How promptfoo authenticates to an HTTP target
Many applications under test sit behind bearer tokens, OAuth 2.0 client credentials, mutual TLS or request signing, and promptfoo cannot test the application until it gets through that layer. The HTTP provider in the promptfoo documentation carries authentication in its request configuration, so the headers, certificates or signing logic you configure there must reproduce what a real client sends. Tests run locally, from the operator's workstation or from the CI runner that executes the suite, which means every credential the run needs must be available on that machine or runner and handled under your normal secrets policy.
Start by mapping the application's real auth flow before writing any provider configuration. Confirm with the application team which token issuer and grant type the client uses, how tokens expire and refresh, whether the gateway terminates mTLS and which certificate authority signs client certificates, and whether requests carry a signature over parts of the body or headers. A test harness that skips a step the production client performs can produce false failures, or worse, pass against a path that real users never reach. Confirm the exact config keys, certificate file formats and any supported PEM, PFX or JKS options against the current promptfoo HTTP provider documentation, since these settings change between releases.
Decide early which identity the tests use. A dedicated, low-privilege test account lets red team probes exercise authorization limits without touching production customer data, and it keeps test traffic separate in the application's logs. Ask the application owner whether that account can be provisioned in the target environment, how its tokens are rotated, and whether the environment is non-production. Finally, verify the configuration with a few plain requests through the provider before enabling full eval or red team runs, so that an expired token or wrong certificate chain shows up as one clear failure rather than hundreds of noisy results.
What you need before connecting promptfoo to a protected app
Before promptfoo can reach an application behind OAuth 2.0 or mutual TLS, five things need to be in place: the tool version, a safe target environment, a scoped test identity, the certificate material, and network paths. Each card below is one item to confirm, and each one blocks the next step if it is missing.
Supported promptfoo version
Use the npm release 0.124.1 or later, which requires Node.js 22.22.0 or newer. Check the runner's Node version before installing, and pin the promptfoo version in your repository so the authentication config behaves the same in every run. Recheck the release notes when you upgrade, since changes to auth handling in the HTTP provider are the kind of detail that can break a working config. The Community edition is MIT-licensed and already includes all model providers and integrations, including the HTTP provider used here, so no paid tier is needed to connect a protected target.
promptfoo on npmNon-production target environment
Test against a staging or test copy of the application that has its own identity provider realm or tenant. Do not point red teaming at production, because adversarial prompts and malformed requests will be sent to the live system. Ask the application owner to confirm that the test environment accepts the same token issuer, client registration pattern and certificate authority as production, so the auth flow you validate is the one you will rely on. If the environment shares an identity provider with production, agree in writing how test clients are separated.
Scoped test account
Create a dedicated test user or service client whose permissions are limited to synthetic, non-production data. Red teaming sends attack prompts through the application under that identity, so anything the account can read or change becomes part of the test surface. Confirm the account cannot reach real customer records, cannot send email or payments to real parties, and has no admin roles. Record who owns the account, when its password or client secret rotates, and how it is disabled after the engagement ends.
Certificate files and passwords
Collect the client certificate and private key in the form your tooling expects: PEM files, a PFX bundle, or a JKS keystore, along with the passwords that protect them. Confirm the certificate chain is complete, that the certificate is not expired, and that the issuing certificate authority is the one the test environment trusts. Store passwords in your secrets manager, not in the promptfoo config file, and keep private key files out of version control. Ask the application team which format they issued, since converting between formats is a common source of handshake errors.
Network routes from the runner
Confirm that the machine or CI runner executing promptfoo can reach three endpoints: the application's API, the identity provider's token endpoint, and any certificate revocation or OCSP endpoints the TLS handshake depends on. Firewalls, egress proxies and private DNS often block one of these while the application itself looks reachable from a browser. Test each route with a simple request from the exact runner that will execute the scans, and note any proxy settings the runner needs so the token and mTLS calls go through the same path.
Configure authentication in the order the app expects it
This sequence layers credentials onto a promptfoo HTTP target one mechanism at a time, so each failure can be traced to a single cause before the next layer is added. The result is a target that passes the same checks your application enforces for a real user or service.
Confirm the endpoint responds without credentials
Start with a plain request to the endpoint from the machine that will run promptfoo, using curl or a minimal promptfoo HTTP target with no auth block. Record the status code and the response headers, especially any 401 or 403 and any WWW-Authenticate or redirect to a login page. Expect the application to refuse the call; that refusal tells you which mechanism it uses. This step is done when you can name the auth method from the response and confirm that network routing, DNS and TLS to the host work. Ask the application team which routes are public and which require sign-in, so you know which route to use as the known check later.
Add a static bearer token from a secret store
If the application accepts a bearer token issued to a test account or service client, store that token in your secret manager and reference it from the promptfoo target configuration through an environment variable rather than writing it into the YAML file. Add it as an Authorization header on the target. Run the plain request again with the header set and confirm a 200 response on the known route you identified in the first step. Confirm the token is not echoed in promptfoo output or saved in reports, since eval results may be shared. Ask the application owner how long the token stays valid, because a static token that expires mid-scan will show up as a failure pattern.
Add OAuth 2.0 for a dedicated test identity
When the application issues tokens through an OAuth 2.0 authorization server, configure a test client with the grant type the identity provider supports for machine access, such as client credentials, or a password-style flow only where the provider allows it for test users. Keep the client ID and secret in the secret store and have promptfoo request the token before each run or reuse it within its lifetime. Verify that the token endpoint returns an access token with the scopes the target routes need, then repeat the known-route check. Confirm the grant type and scopes with your identity team, because some providers disable password flows entirely.
Check token refresh during a multi-turn session
Run a short multi-turn test that is long enough to outlast the access token lifetime, using session handling from the HTTP target. Watch for a 401 partway through the conversation and confirm the target obtains a new token and continues the session without losing context. Failures here usually come from a refresh token that is not issued for the test client or from a session identifier tied to the old token. The step is complete when the conversation completes with the expected turns and the logs show one token request per expiry rather than one per message. Ask the identity team how refresh tokens are issued for machine clients, since the answer determines whether this check can pass at all.
Attach mutual TLS client certificates
If the gateway or application requires a client certificate, load the certificate and key in the format the target supports, such as PEM files, or PFX or JKS bundles where the configuration accepts them. Keep private keys in a restricted location with file permissions limited to the account that runs promptfoo, and keep passphrases out of the repository. Confirm that the server certificate chain is trusted by the runner, and add a custom CA only if your organization requires it. Repeat the known-route check and confirm the handshake succeeds before the request reaches the application. Check the certificate expiry date now, because an expired client certificate will look like a generic connection failure.
Add request signing when the application requires it
Some APIs require each request to carry a signature computed over the method, path, timestamp and body, in addition to or instead of a bearer token. Implement the signing in a small script or Python function that promptfoo calls to set the headers for each request, and keep the signing key in the secret store. Test the signing against the known route and confirm the server accepts a fresh timestamp while rejecting a replayed one, which proves the signature covers what the application checks. Ask the application team for the exact canonical string format and clock tolerance, since a single byte difference in the signed content causes every request to fail.
Run a full validation pass before the red team scan
Before starting a red team scan, run a small eval that covers the known route, one authenticated business workflow and one multi-turn session, using the complete authentication stack. Confirm that every request in the run is authenticated, that no response is a login page or an authorization error disguised as a 200, and that credentials are not present in the saved output. Keep the test account limited to the permissions a real user would hold, so red team results reflect what an attacker with that access could reach. Record the configuration version and the identities used, so the results can be reproduced and reviewed later.
Choosing between bearer tokens, OAuth 2.0, mTLS and signed requests
The right authentication method for a promptfoo HTTP target follows from how the application already authenticates its users and services, not from which option is easiest to script. Start by reading the target's own auth design, then choose the test credential that reproduces it. A static bearer token is the simplest to configure and is often enough for a direct API that accepts long-lived service keys. Its weaknesses are that it expires, it is easy to leak through a shared config file or a CI log, and it tests a path that real users may never take. Keep such tokens in environment variables, scope them to a test tenant, and plan a rotation step when they expire.
OAuth 2.0 fits a gateway or identity provider in front of an agent or chat application, where the target expects a token issued by a dedicated test client. It adds work: the test setup must acquire tokens, refresh them before long red team runs finish, and keep the client's scopes narrow enough to test authorization rather than bypass it. Mutual TLS suits environments where the target only accepts connections from clients holding a certificate issued by its trust chain. Confirm the certificate format the target expects (PEM, PFX or JKS), who issues the client certificate, and whether the chain includes intermediates. Signed requests, where each call carries an HMAC or similar signature, need the signing logic reproduced byte for byte, so verify the signature against a single manual request before any scan starts.
As a working rule, a gateway in front of an agent usually calls for OAuth 2.0 with a test client, or mTLS where the gateway enforces it, because those controls are what the gateway tests against. A direct API with service-to-service trust often calls for a bearer token or mTLS. Ask the application team which identity the production traffic uses, and test with that identity. Before scoping the work, confirm which of these the target actually enforces, because a test that passes with a credential the production system never accepts gives false assurance.
How a promptfoo test request reaches a protected app
The request starts on the test runner, where promptfoo runs and holds the credentials it needs. The runner first asks the identity provider for an access token when OAuth 2.0 is in use, then sends the request to the gateway, which checks the client certificate during the TLS handshake. Only after both checks does the application receive the request and its token. Check each boundary separately: a token the gateway rejects, or a certificate the identity provider never saw, points to a different layer.
Trust boundaries between the test runner, identity provider, gateway and application.
Mapping test identities, certificates and secrets to promptfoo config
This table maps each credential the HTTP target needs (test account, OAuth client, token endpoint, certificates, signing key) to where it should live and which app role it should hold. Read each row as a question to answer before the first red team run. The main takeaway is that every test identity should be a dedicated, least-privilege account whose secrets live outside the config file.
| Credential | Where it lives | Role in the app | Notes for red teaming |
|---|---|---|---|
| Test user account | Secret store entry for the username and password, referenced by an environment variable in the config | Standard end-user role with access only to the features under test | Create a separate account per tenant or role under test so authorization failures can be tested in both directions |
| Privileged test account | Separate secret store path with stricter access than the standard test account | Admin or support role, used only in scans that target elevated functions | Keep out of default scans so a privilege escalation finding is deliberate, not accidental |
| OAuth 2.0 client ID and secret | Environment variable or secret store entry, never hard-coded in the YAML | Client registered with only the scopes the target endpoints need | Confirm with your identity team whether the client supports the client credentials grant for machine tests |
| Token endpoint URL | Config value, documented alongside the environment it belongs to | Not a role, but must match the issuer for the test environment | Confirm the URL differs between staging and production so tokens are never requested from the wrong tenant |
| Client certificate and private key (PEM) | Mounted file with restricted read permissions, path given by environment variable | Identifies the test client to the gateway or service | Confirm whether the key is protected by a passphrase and where that passphrase is stored |
| PFX or JKS keystore and passphrase | Keystore file in a restricted directory, passphrase in the secret store | Same identity as the PEM pair, packaged for Windows or Java tooling | Confirm the keystore format your target expects and that the test certificate is not the production one |
| Request signing key | Secret store entry, accessed only by the runner that signs requests | Service identity for signed requests to the target | Confirm the signing algorithm and header names with the application team before writing the template |
| CI or runner secret | CI variables or a vault integration, scoped to the scan job | Not an app role, but controls who can trigger scans against the target | Restrict to protected branches so untrusted pull requests cannot read test credentials |
Keeping test credentials out of configs, logs and reports
Test credentials for an authenticated promptfoo target can leak in four places: committed config files, CI logs, saved eval results and shared red team reports. The cards below cover where to keep secrets, how to scope the accounts behind them, and what to do once results have left the team.
Store secrets in CI variables or a vault
Keep bearer tokens, OAuth client secrets and private key passwords in your CI system's secret store or a dedicated vault, and reference them from the promptfoo configuration through environment variables. A committed YAML file with a token in it stays in Git history even after it is deleted. Check that CI jobs mask these values in logs and that forks or pull requests from outside the team cannot read them.
Use dedicated non-production test accounts
Create test users on the staging or test environment of the application, with roles limited to what the scan needs. Do not reuse an administrator account or a real customer account, because a red team run will attempt prompts and actions the application did not anticipate. Ask the application owner which roles the test user holds, what data it can reach and whether it can be locked out without affecting others.
Prefer short-lived tokens
Where the application issues tokens with an expiry, use a flow that refreshes them during the run rather than pasting a long-lived token into a file. Short lifetimes limit the damage if a log or report is exposed. Confirm with the identity team how the token lifetime interacts with long red team runs, because an expired token mid-scan can produce a burst of authentication failures that look like application findings.
Separate red team traffic from production logs
Tag or route promptfoo traffic so it is identifiable in gateway, application and SIEM logs, for example with a dedicated test client identifier or a separate test hostname. Without this, adversarial prompts appear next to real user sessions and can trigger alerts or pollute analytics. Agree with the security operations team who watches these logs and how the test window is recorded.
Restrict certificate and key file permissions
Client certificates for mutual TLS arrive as PEM, PFX or JKS files, and their private keys are the credential. Keep them out of the repository, mount them read-only into the runner, set owner-only file permissions and remove them when the job ends. Confirm that the promptfoo configuration points to the file path rather than inlining key material, and that eval output does not echo request headers that include certificate details.
Rotate test credentials after sharing reports
Red team reports often include request examples, and those examples can contain tokens, session cookies or account identifiers. Before a report leaves the testing team, redact or review it for credentials. Once it has been shared with a vendor, auditor or wider team, rotate the test account password and any client secret used in the run. Record the rotation date so the evidence file shows credentials were not left active.
Questions teams ask before authenticating promptfoo to a real app
Can our in-house team set up promptfoo authentication without a partner?
Yes, many teams do, especially when one application uses a single bearer token and the team already owns its identity provider. The work is mostly configuration in the promptfoo target block, plus a short validation run against a non-production environment. It becomes harder when the target needs OAuth 2.0 token refresh, mutual TLS with certificates in several formats, or signed requests, because each of those adds code and failure modes that someone must own. Ask your team who will maintain the auth configuration after the first scan, since test accounts and certificates expire and need rotating.
What makes authentication work for promptfoo harder or easier?
Effort follows the number of authentication flows the target expects and how much each one differs from the others. The main drivers are:
- The number of distinct auth flows, such as a bearer token for the API and a separate OAuth 2.0 flow for the web app.
- The certificate format and chain. PEM, PFX and JKS files each need their own handling, and password or alias mismatches are common.
- The identity provider's behavior, including token lifetimes, refresh rules, MFA requirements and whether it supports machine-to-machine clients.
- Signing logic. A request that must carry a computed signature depends on code that has to be tested against the real service.
A single static token with no certificates is the simplest case.
How long does promptfoo target authentication usually take?
No duration is fixed in our research, so the honest answer depends on the application and the access you can give. Timing usually moves with three things: how quickly you can provision a dedicated test account with the right roles, how long certificate and client registration requests take inside your organization, and how many environments must be configured before the first authenticated run succeeds. Ask any partner, including DeployOpen, to state the duration in the written scope, with the dependencies on your side listed as their own milestones.
What do we need to provide for the work to go smoothly?
Most delays come from access, not from configuration. Plan to provide:
- Dedicated test accounts with the minimum roles needed for red teaming, separate from production users.
- Client credentials, certificates and their passwords through your approved secrets process, not email.
- Network access from the test runner to the application and to the identity provider, including any allowlisting of the runner's addresses.
- A named owner for the identity provider who can answer questions about flows, scopes and token lifetimes.
- An environment where failed authentication attempts do not lock out accounts or trigger alerts without notice.
Does promptfoo Enterprise add SSO or team access control for the promptfoo side?
Enterprise, as described on the promptfoo pricing page, adds teams-based access control and SSO, custom roles and permissions, and team sharing. These features govern who can use promptfoo, which is separate from how promptfoo authenticates to your application. The target authentication described in this topic, meaning bearer tokens, OAuth 2.0 and mutual TLS, is configured in the promptfoo target itself and still has to be built and tested. Confirm the Enterprise feature list and any licensing terms with promptfoo before you assume how they interact with your target setup.
Which costs are one-time and which recurring?
The one-time costs are the design and build of the authentication configuration, validation against the target, and any custom signing or certificate handling code. Recurring costs include rotating certificates and client secrets, updating test accounts when roles change, re-running scans after the application or identity provider changes, and keeping the promptfoo version current. promptfoo Community is free under the MIT license, so software licensing is not usually the cost driver here. Ask for any quote to split one-time and recurring items explicitly, and to state who pays for the identity provider changes and certificate authority work.
How do we keep test credentials safe while promptfoo runs?
Keep test credentials out of configuration files committed to source control. Store them in your secrets manager or CI secret store, and reference them at runtime. Use accounts that cannot touch production data, limit their scope, and set expiry so a forgotten credential does not stay valid. Review what promptfoo logs and reports, because captured headers or responses can expose tokens. Confirm with promptfoo's documentation how each target field is read and what appears in reports before you run against a live system.
Common authentication failures in promptfoo HTTP targets and their fixes
This table lists the authentication failures teams hit when promptfoo calls an application behind OAuth 2.0 or mutual TLS, with the likely cause and the fix for each. Read it when a run fails at the first request or partway through a long scan, and check the cause column against the symptom you see before changing configuration.
| Failure | Likely cause | Fix |
|---|---|---|
| Token expires during a long run | The access token was fetched once at startup and its lifetime is shorter than the scan, so later requests return 401 Unauthorized. | Refresh the token inside the request flow rather than once at startup, and confirm the token lifetime with your identity provider before setting scan size. |
| Test user lacks a required scope | The OAuth client requests a scope the test account was never granted, so the API returns 403 Forbidden on some routes but not others. | Compare the scopes in the token with the scopes the endpoint requires, then ask the identity team to grant the missing scope to the test account only. |
| Certificate chain not trusted by the gateway | The client certificate is signed by an intermediate CA that the gateway does not have, so the TLS handshake fails before any HTTP request is sent. | Bundle the full chain in the PEM or PFX file, and confirm the gateway's trust store includes the issuing CA. |
| Wrong PFX password | The password passed to promptfoo does not match the one set when the PFX file was exported, which often shows up as a decryption error at startup. | Re-export the PFX from the source certificate with a known password, and store that password in your secrets manager rather than in the config file. |
| JKS alias mismatch | The alias named in the configuration does not match the entry in the keystore, so no private key is found even though the file loads. | List the keystore entries with the Java keytool utility, copy the exact alias, and check that the key password matches the store password where your setup requires it. |
| Clock skew breaks signed requests | The signature includes a timestamp, and the runner's clock differs enough from the server's that the server rejects the request as stale or future-dated. | Sync the runner's clock with NTP, then rerun a single request to confirm the signature is accepted before starting a full scan. |
| MFA on the test account | The test account requires a second factor on each sign-in, so an automated token request stalls or fails with an interactive challenge. | Use a dedicated non-interactive client or service account for red teaming, scoped to test data, and confirm with the identity team that policy allows it. |
| Rate limits or lockouts from token requests | Each red team probe triggers a new token request, so the identity provider throttles the client or locks the test account after repeated failures. | Cache the token until shortly before expiry, reuse it across probes, and ask the identity team which rate limits and lockout rules apply to the test client. |
What a DeployOpen engagement covers for protected targets
DeployOpen plans and configures the connection between promptfoo and a protected application as part of red teaming readiness. That covers the targets block in the promptfoo config, the token acquisition flow for OAuth 2.0 client credentials or a pre-issued bearer token, the client certificate and key material for mutual TLS, any request signing the application requires, and the dedicated test accounts that red team runs will use. The work is scoped in writing before it starts, so the protected endpoints, identity provider, certificate authority, environments and the set of accounts in scope are agreed up front rather than discovered during a run.
The deliverables are a working provider configuration that runs against the agreed environment, documented secret handling and a validated test run. The documentation covers where each credential lives, who can read it, how it is rotated, and how CI runners or the self-hosted promptfoo server receive it without writing it into a repository. The validation run confirms that requests reach the application as authenticated test identities, that expired tokens and rejected certificates fail visibly instead of producing false passes, and that the red team plugins exercise the intended authorization paths. Ask the team that owns the identity provider and certificate authority to confirm the token lifetimes, certificate chain and revocation behavior before scoping begins.
DeployOpen does not issue audit reports, attestations or certifications. The engagement prepares the configuration, controls and evidence that an assessor may ask to see, such as how test identities are separated from production accounts and where test logs are kept. Independent auditors and certification bodies make their own determinations. Buyers should confirm with their assessor which evidence they need before the scope is signed, so that the documentation is written to the format their review expects.
How DeployOpen scopes and delivers protected-target testing
DeployOpen plans and delivers promptfoo test access to applications behind OAuth 2.0 and mutual TLS, inside the client's own infrastructure. Each engagement starts with a written scope that names the target, the identity flow and the test accounts, so the work stays within what the client has approved.
How we scope
- We map the authentication path in front of your target, including token endpoints, certificate authorities and gateways.
- We agree in writing which test accounts, roles and environments promptfoo may use during evaluations and red team runs.
- Engagements are fixed-scope, with deliverables and timelines confirmed before any configuration work begins.
How we build
- We configure promptfoo HTTP targets for bearer tokens, OAuth 2.0 client credentials and mTLS certificates in your chosen format.
- We validate the target first with simple requests, then confirm token refresh and session behavior for multi-turn tests.
- We keep credentials out of config files and CI logs, using the secret store your organization already operates.
How we hand over
- You receive the working promptfoo configuration, a runbook for certificate and token rotation, and notes on known limits.
- We document which test accounts were used, what they can access and how they are disabled after testing ends.
- Findings and fixes come with a retest, so you can confirm that authentication works as designed before handover.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers when your authentication setup changes.
- We help renew certificates, rotate client secrets and update identity settings before they expire during scheduled runs.
- Ask us to confirm how promptfoo's current release handles your certificate format and identity flow before you commit.

