Running OAuth Integration Tests in GitHub Actions Without Live Credentials

Federated OIDC and a stateful simulator keep CI free of live secrets.

· 8 min read · Updated
Cover illustration for “Running OAuth Integration Tests in GitHub Actions Without Live Credentials”
Auth Flow Testing · October 24, 2026 · 8 min read · 1,764 words

Federation takes away the need to store long-lived secrets, and simulation keeps tests off live services. For APIs where the order of operations matters, the simulator must keep state across calls so that later responses reflect what earlier calls did.

Why storing long-lived OAuth credentials in CI is the wrong starting point

A long-lived OAuth credential creates work beyond its initial storage. When a credential is rotated, every repository and environment that uses it needs the update, or stale credentials stay in place. A leaked credential remains useful until someone notices and revokes it. Moving the secret into CI does not shorten that exposure.

Yet credential management is only half the problem. Even when a secret is correctly rotated, tests still connect to a service whose availability, rate limits, and state are outside the pipeline’s control. The same code can therefore give different results from one run to the next. The architecture needs separate boundaries for workflow authentication and test execution, because removing stored secrets does not remove dependence on live APIs.

How GitHub Actions OIDC federation replaces stored credentials with short-lived tokens

OIDC federation makes the workflow’s identity the basis for authentication. If the claims match, the provider issues temporary credentials. The workflow can then authenticate to the cloud resources its setup requires without retrieving a long-lived key from repository secrets.

The claims make that exchange specific to the workflow. They include the subject, sub, the audience, aud, and an expiry. The subject is the primary trust anchor, identifying the repository and its ref or environment context. Accepting a subject is therefore a decision about which workflow context may authenticate.

Timing is a practical constraint in this flow. The GitHub JWT expires in five minutes, so authentication must happen before long-running setup steps. That expiry belongs to the JWT used for federation, rather than describing every credential obtained through the exchange. Credential issuance also provides a more specific audit trail, with CloudTrail or Azure Monitor events identifying the repository, branch, workflow run, and commit instead of only an IAM user name shared by workflows.

Scoping the OIDC trust policy tightly enough to be safe in a test environment

A permissive trust policy defeats the purpose of precise workflow identity. A subject pattern such as repo:your-org/* allows workflows across the organization to assume the role, including workflows that were not intended to use it. The safer test boundary is a specific GitHub Environment. For the name-based subject format, the condition should allow only the exact subject repo:acme/shop-web:environment:test, which rules out an organization-wide wildcard. A job that does not declare environment: test receives a different subject and cannot assume that role.

Required reviewers and deployment branch rules constrain its use, while non-secret identifiers such as AWS_ROLE_ARN, AWS_REGION, and TEST_BASE_URL can live in environment variables. GitHub Docs states that repositories created after July 15, 2026 use an immutable default subject containing numeric owner and repository IDs, while older repositories retain the previous format unless they opt in. New repositories should use the immutable format immediately. The accepted subject must match the repository’s actual format, rather than copying a name-based example into an ID-based policy.

The trust policy controls who may assume a role, while the role’s permission policy controls what the authenticated job may do. Both need restrictive scope. AWS and Azure follow this pattern, with Azure Entra ID app-role assignments such as Sample.Read determining access for the GitHub Actions principal. The workflow should grant id-token: write only to the job that needs cloud authentication, because that permission permits a token request but does not itself authorize changes to cloud resources.

What OIDC alone does not solve: the test still calls a live API

Temporary credentials do not make a live endpoint deterministic. Tests against Stripe, Slack, or GitHub still inherit outages and rate limits, and can create records, trigger webhooks, or consume quota. Even an official sandbox can have settings that differ from the live service. Stripe states that sandbox settings and capabilities are not synchronized with live and can diverge at any time. The missing component is a test endpoint that remembers prior operations and returns realistic responses without contacting the real service.

How can you do integration testing against stateful APIs without hitting production?

A stateless mock maps a request pattern to a canned response. It has no memory of earlier calls. As a result, a successful retrieval response cannot establish that the object was actually created earlier in the test. When order of operations is part of the integration contract, that distinction separates checking individual responses from checking whether a workflow is valid.

A checkout flow makes the limitation concrete. The application creates a payment intent, polls its status, and relies on an asynchronous webhook three seconds later. These are three linked events in one transaction whose state changes as it goes. A static stub cannot reproduce that stateful, asynchronous choreography. A stateful simulator instead maintains world state, so creating, listing, retrieving, and deleting records changes what subsequent calls return.

With pre-seeded realistic data, tests can run through paths that an empty sandbox can leave untouched, and assertions have records and states to check. Fidelity also needs maintenance as the real API changes. Hand-maintained stubs need updates whenever fields, statuses, or behavior change, and mock drift often becomes visible only in production. Checking a simulator against the live API on an ongoing basis can catch drift before developers run into it, while each CI run stays independent of that API.

Wiring a stateful simulator into a GitHub Actions OAuth integration test

The workflow joins the layers without making them interchangeable. OIDC gives the job temporary credentials for the cloud infrastructure it needs to set up tests, and the simulator provides the API behavior the application tests. A job declares environment: test and grants itself id-token: write. Its first authentication step uses aws-actions/configure-aws-credentials@v6 or the Azure equivalent before setup work can outlast the GitHub JWT.

The next setup component is the simulator itself. It can run as a Docker service container or as a background process started before the tests. The test configuration then points API base URLs at the local simulator. No live credentials for Stripe, Slack, GitHub, or the other simulated services are referenced.

Each parallel test job gets its own simulator container, so jobs do not share a database or depend on one another’s execution order. Within a job, however, the simulator preserves the sequence that the test is meant to exercise. This lets a create-then-retrieve test depend on earlier calls as it would in real use, without making unrelated jobs compete for the same records.

Fault injection as a first-class concern in OAuth integration tests

Success-path coverage leaves important OAuth integration behavior untested. Latency spikes, 429 responses, and 503 responses can interrupt otherwise valid workflows, while an HTTP 200 response can contain a semantically incorrect payload. That last case is especially hard to catch. The request appears successful, so calling code may continue without raising an error and propagate the bad result into downstream state.

A 429 response with the correct Retry-After header tests whether the client backs off, and token expiry during the flow tests whether it re-authenticates gracefully. A stateful simulator can cause the same failure at the same point in each run, so the suite can compare how the code recovers under the same conditions.

Payment and webhook failures also depend on history. A PaymentIntent stuck at requires_capture tests behavior that a generic error response does not represent. Delivering a webhook more than once, sending out-of-order events, and failing to deliver updates test whether the integration handles asynchronous updates correctly. PayPal documents webhook retries over multiple days, illustrating why delivery behavior cannot be reduced to one successful callback. Encoding these patterns in a maintained failure library allows tests to reuse them with realistic fixtures rather than reconstructing disconnected response stubs.

Testing AI agents that call OAuth-protected APIs requires the same two-layer approach

An LLM-based agent can write text that makes sense while sending malformed JSON to a payment API, so the defect is at the tool boundary even when the visible answer reads well. Live testing may expose such a failure only by accident. A canned success response can conceal it because it does not establish whether the operation was valid or changed the expected state.

AgentChaos, published on arXiv in August 2026, tested injected faults across five agent architectures and four backbone models and found large drops in pass@1. Particularly damaging failures returned normal HTTP 200 responses and were caught by current diagnosis tools only a small fraction of the time. The agent’s next action must be evaluated against the state produced by its previous tool call, including when that call appeared to succeed.

llmmas-otel, also published on arXiv in August 2026, provides framework-agnostic fault injection with OpenTelemetry tracing across workflow phases, agent steps, inter-agent communication, tool calls, and LLM calls. Its trace-aligned approach supports reproducible comparisons between baseline and faulty executions. Stateful simulation gives those comparisons an environment to run in. Given the same state and tool call, deterministic behavior makes evaluation scores comparable, while persistent state makes tasks such as searching a repository, opening an issue, and commenting on a PR meaningful across steps.

Reinforcement learning and large-scale evaluations can spawn thousands of parallel environments, each of which needs isolated state without exposure to real API rate limits. The same simulator used in CI can serve these training and evaluation environments. OIDC still governs any cloud authentication the workflow needs, while simulation governs the agent’s API interactions. Agent testing extends the workload within the same two-layer architecture.

Putting the two layers together: what a complete credential-free OAuth test setup looks like

The GitHub Actions job authenticates through OIDC under a trust policy bound to its test environment and the appropriate subject format. Its token-request permission stays at job scope, and its cloud permissions cover only the resources needed for setup. The simulator then runs with isolated state, realistic fixtures, and fault scenarios, while the test code addresses localhost.

This arrangement removes stored long-lived secrets without sacrificing stateful integration coverage. Tests can cover ordered operations, token-expiry recovery, rate-limit handling, and webhook failures without creating real records or relying on external services to be available. Continuous fidelity checks address API drift separately from individual test runs. The setup can run on a developer’s laptop or in CI, including air-gapped enterprise environments, because simulated API interactions need no live access. The two layers can be configured independently, but their value compounds when workflow identity is short-lived and every tested API interaction remains inside a controlled environment.

More in Auth Flow Testing