Awesome Go

auth0-mock

CategoryTesting
SubcategoryMock
Stars9

Mock Auth0 server for tests and local development, with signed JWTs, OIDC login flows and the Management API

About auth0-mock

auth0-mock

A drop-in mock of Auth0's HTTP API (Authentication + Management) that you can point any Auth0-using service at, with no code changes.

Real RS256 JWTs. 480+ Management API endpoints. Runtime claim and permission injection. MFA, PKCE, OIDC discovery. HTTP and HTTPS.

Quick start ยท What's mocked ยท Recipes ยท Architecture ยท Contributing

CI CodeQL Go Report Card codecov Go Reference OpenSSF Scorecard OpenSSF Best Practices Signed releases govulncheck Release Go version GHCR Go module License: MIT Conventional Commits PRs welcome

๐Ÿ“– Docs: https://sergiu.dev/auth0-mock/

โœจ What is this?

A self-contained Go service that looks and behaves like Auth0 to a calling client:

  • ๐ŸŽซ Mints real RS256 JWTs signed with an in-process key, and publishes the matching JWKS at /.well-known/jwks.json. Consumer SDKs validate signatures normally โ€” no InsecureSkipVerify, no fake-token kludges.
  • ๐Ÿ“ฆ Covers the whole Management API by embedding a stripped skeleton of Auth0's OpenAPI 3.1 document (~480 operations: paths, methods, and schemas; Auth0's prose removed) and routing every endpoint through one generic handler. You stub responses by POSTing {method, path, response} to /admin0/expectations, and the OpenAPI schema validates the stubbed body at registration time. Set "template": true to fill in {{uuid}}, {{now}}, {{path.NAME}} and {{body.PATH}} per request. An optional request matcher lets you register multiple responses per operation; resolution is 4-tier (exact-path beats template-path; within a path, a request-matched expectation beats a catch-all; newest wins within a tier).
  • ๐Ÿ›  Shapes runtime state over HTTP: custom JWT claims, per-audience permissions, and the MFA-required flag are mutable mid-test through /admin0/* endpoints. No restart, no config-file juggling.
  • ๐Ÿณ Ships as a single static binary (~13 MB) or a small Docker image. Sub-second boot, both HTTP (:8080) and HTTPS (:8443) by default.

๐ŸŽฏ Who is this for?

Anyone whose service talks to Auth0 in tests or local dev:

  • CI pipelines that need deterministic Auth0 responses without burning rate limit on a real tenant.
  • Local dev loops where you don't want to share an Auth0 tenant or wait on its latency.
  • Integration test suites for Auth0 SPA / native / API SDKs (auth0-react, auth0-js, auth0-spa-js, auth0-android, auth0-swift, auth0-react-native, etc.).
  • Resilience tests for code paths that hit /api/v2/users, /api/v2/clients, /api/v2/roles, etc.
  • Service-to-service flows using client_credentials, with realistic scopes and permissions claim shapes.

It is not for: production traffic, replacing your IdP, or anything that needs a real RBAC engine.

๐Ÿš€ Quick start

docker run --rm -p 127.0.0.1:8080:8080 -e ADMIN_ALLOW_REMOTE=true ghcr.io/sergiught/auth0-mock:latest

Then, in another terminal:

# 1. Mint a real signed access token
TOKEN=$(curl -s -X POST http://localhost:8080/oauth/token \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'grant_type=client_credentials&client_id=demo&client_secret=x&audience=http://localhost:8080/api/v2/' \
  | jq -r .access_token)

# 2. Stub a Management API response
curl -X POST http://localhost:8080/admin0/expectations \
  -H 'Content-Type: application/json' \
  -d '{"method":"GET","path":"/api/v2/users/auth0|123","response":{"status":200,"body":{"user_id":"auth0|123","email":"[email protected]"}}}'

# 3. Call the stubbed endpoint with your bearer
curl http://localhost:8080/api/v2/users/auth0%7C123 \
  -H "Authorization: Bearer ${TOKEN}"
# => {"user_id":"auth0|123","email":"[email protected]"}

Your code calls auth0-mock the same way it calls Auth0. No SDK shims, no monkey-patching.

๐Ÿ“– Documentation

Full docs live at https://sergiu.dev/auth0-mock/.

PageWhat it covers
InstallationInstall and run auth0-mock from a release, from source, with go install, in a live-reload loop or in Docker.
First requestMint a token, stub a Management API response and call it, using only curl.
curl quickstartCall the mock with plain curl, from starting it to calling a stubbed endpoint.
Node.js quickstartTest a Node API and a Management API client against the mock with express-oauth2-jwt-bearer and the auth0 SDK.
Python quickstartTest a Python API and a Management API client against the mock with PyJWT and the auth0-python SDK.
Go quickstartTest a Go API and a Management API client against the mock with go-jwt-middleware and the go-auth0 SDK.
Stubbing the Management APIStub Management API responses, errors and retries, and reset or inspect what is registered.
Tokens and claimsTest code that reads permissions or custom claims, and test token expiry without sleeping.
Login flowsTest PKCE, login errors, silent login, MFA challenges, organizations, token exchange and the password-realm grant.
Event streamsDrive an event-stream consumer from a test.
HTTPS / TLSRun auth0-mock over HTTPS and make clients trust its self-signed certificate.
Calling the API from Postman or InsomniaImport the merged OpenAPI document into Postman or Insomnia, and regenerate it after spec changes.
Browser appsCall the mock from a browser app.
Go SDKUse the typed Go client and test helpers to drive auth0-mock from Go tests.
Common recipesShort curl recipes for claims, permissions, MFA and the clock.
What's mockedWhat the mock implements: the Authentication API, supported OAuth grants, the Management API, event streams, the admin surface and operations endpoints.
ConfigurationEvery environment variable and flag that configures auth0-mock.
Verifying releasesVerify the Cosign signature on Docker images and find the SBOM for each release.
ArchitectureA walkthrough of how auth0-mock is put together, for contributors and curious users.

๐Ÿค Contributing

PRs welcome. See CONTRIBUTING.md for local setup, code style, testing requirements, and how to add a new endpoint. Also see SECURITY.md, CODE_OF_CONDUCT.md and CHANGELOG.md.

โš–๏ธ License

MIT.

โš ๏ธ Disclaimer

auth0-mock is an independent, community-built testing tool. It is not affiliated with, endorsed by, or sponsored by Auth0 or Okta, Inc. "Auth0" and "Okta" are trademarks of Okta, Inc.; they are used here only nominatively, to describe what this project mocks.

To route and validate every Management API endpoint, this repo embeds a stripped skeleton of Auth0's published Management API OpenAPI specification (sourced from https://auth0.com/docs/api/management/openapi.json): paths, methods, parameters, and JSON-schema shapes only. Every Auth0-authored description, externalDocs link, and x-* extension is removed before commit by stripUpstreamProse; see the refresh procedure. The raw download is gitignored and never committed; only the skeleton is.

Auth0 does not attach an explicit redistribution license to the published spec. The deliberate stripping above is what lets us redistribute the structural shape for interoperability without redistributing Auth0's prose. If the distinction matters for your compliance review, confirm the terms with Auth0/Okta directly.

Frequently Asked Questions

What is auth0-mock?

auth0-mock is a Testing library for the Go programming language. Mock Auth0 server for tests and local development, with signed JWTs, OIDC login flows and the Management API

How do I install auth0-mock?

Install auth0-mock with the Go module system using `go get sergiught/auth0-mock`. Check the repository for the current installation instructions.

What category does auth0-mock belong to?

auth0-mock is listed under Testing, specifically Mock.

โ† Back to Mock