Security Testing

OAuth 2.0 Negative Testing for Enterprise IdPs: Okta, Azure AD, Ping (2026)

Total Shift Left Team5 min read
Share:
OAuth 2.0 negative testing — PKCE, scope, redirect URI for enterprise IdPs

In this article you will learn

  1. Why OAuth needs negative testing
  2. Eight test patterns that catch real bugs
  3. IdP-specific quirks: Okta, Azure AD, Ping
  4. How to run these tests automatically
  5. Mapping to RFC 9700 and OWASP API Top 10

Why OAuth needs negative testing

OAuth 2.0 is a framework, not a protocol. The positive flows — authorization code, client credentials, refresh token — are well-specified and well-tested by IdP vendors. The vulnerabilities live in the negative paths:

  • A client that doesn't validate the state parameter is vulnerable to CSRF.
  • A server that doesn't enforce PKCE on public clients is vulnerable to authorization code interception.
  • A redirect URI matched too loosely lets attackers exfiltrate tokens.
  • An authorization code reused after exchange opens session-fixation paths.
  • A refresh token not rotated lets stolen tokens persist.

Most production OAuth bugs are on these negative paths. The original integrator tested the happy flow because that's what the IdP vendor's docs show. The malicious flows weren't tested because there's no documentation saying "send a request with a tampered state parameter and confirm the server rejects it."

Negative testing exists to fill that gap.

Eight test patterns

Eight patterns cover most of the OAuth 2.0 security threat surface:

#PatternWhat it asserts
1Missing stateServer rejects the callback when no state is present
2Tampered stateServer rejects the callback when state doesn't match the request
3PKCE missing on public clientServer rejects auth requests without code_challenge for SPA / mobile clients
4PKCE mismatchServer rejects token exchange when code_verifier doesn't match code_challenge
5Redirect URI mismatchServer rejects callbacks to a redirect URI not exactly matching the registered list
6Authorization code replayServer rejects a second use of an already-exchanged code
7Scope escalation in token exchangeServer rejects a token request asking for scopes broader than the authorization granted
8Refresh token reuse after rotationServer invalidates the old refresh token after a rotation

Ready to shift left with your API testing?

Try our no-code API test automation platform free. Generate tests from OpenAPI, run in CI/CD, and scale quality.

Each pattern is testable as a request that the server should reject with a specific error. The test asserts the error code and verifies the rejection happens before any token is issued.

IdP-specific quirks

The patterns above are spec-compliant; the IdPs differ in how they implement them.

Okta. PKCE enforcement is configurable per application type. SPAs and mobile apps require PKCE by default; web apps are configurable. Tests have to know the application's type to assert the right behavior. Okta's redirect URI matching is exact-match only, no wildcards.

Azure AD / Entra ID. Redirect URI matching is stricter than the OAuth spec — Azure AD requires exact match including scheme, host, port, and path. The error response on mismatch is a generic invalid_request rather than a specific code; tests have to match on the error description text or the IdP's tracking ID.

Ping Identity. Authorization code reuse behavior is configurable per OAuth client; some installations allow code reuse within a short window for legacy reasons. Tests have to be configured to know which behavior the client is supposed to enforce.

A working enterprise pattern is to write the test logic IdP-agnostically and parameterize the assertions — IdP-specific quirks live in a small adapter layer per IdP.

How to run these tests automatically

Negative OAuth tests fit naturally into automated test pipelines:

  • No human interaction needed. Most negative tests use the authorization code flow with mocked / pre-captured authorization endpoints; the user-consent step doesn't have to run.
  • Fast. Each test is one or two HTTP requests against the token endpoint or authorization endpoint. Whole suites complete in seconds.
  • CI-friendly. No special infrastructure beyond credentials for the test IdP tenant.

Two integration patterns work well:

  1. Per-environment IdP test tenant. A dedicated Okta / Azure AD / Ping tenant for testing, with test users and clients. Tests run against the real IdP and assert the IdP enforces correctly.
  2. Mock IdP plus integration tests. A mock OAuth server (e.g. Hydra, Keycloak) for fast PR-stage tests, with periodic integration tests against the real IdP.

For deeper background on enterprise IdP-specific testing patterns including JWT validation, see JWT authentication testing for enterprise IdPs: Okta, Azure AD, Ping.

Mapping to RFC 9700 and OWASP API Top 10

The eight patterns map cleanly to standards:

PatternRFC 9700 sectionOWASP API Top 10 (2023)
Missing / tampered state4.7 (CSRF)API8 — Security Misconfiguration
PKCE missing / mismatch2.1.1 / 4.5 (Code injection)API2 — Broken Authentication
Redirect URI mismatch4.1 (Redirect URI manipulation)API2 — Broken Authentication
Authorization code replay4.6 (Code injection)API2 — Broken Authentication
Scope escalation4.10 (Privilege escalation)API5 — Broken Function Level Authorization
Refresh token reuse4.13 (Refresh token replay)API2 — Broken Authentication

A test suite covering these eight patterns gives the security function defensible coverage of OAuth-specific OWASP Top 10 risks for the IdPs in scope. For broader coverage of OWASP enterprise mitigations, see OWASP API Top 10 for enterprise teams.


OAuth 2.0 negative testing is one of the highest-leverage security investments an enterprise team can make. Eight patterns, IdP-aware adapters, fast CI integration. The teams that run these systematically catch the auth vulnerabilities the integrator didn't think to test — which is where most production OAuth incidents start.

Ready to shift left with your API testing?

Try our no-code API test automation platform free.