Skip to content

Mock an identity provider

Before you begin

Plan
Included in Pro and Team. How plans and limits work
Role
Editor or higher to add endpoints and Admin or higher to rotate the keys.
You need
  • A project with response templating on

The project becomes an identity provider: a discovery document, a JWKS, and token, authorize, userinfo, introspection, revocation and sign-out endpoints, each an ordinary mock. Tokens are JWTs signed with keys only this project holds, so your application verifies them exactly as it would a real provider’s.

  1. Open Identity provider in the project.

  2. Select Add endpoints.

  3. Choose a Preset: Generic OpenID Connect, Auth0-shaped or Keycloak-shaped. A preset decides paths and claim names only. For the Keycloak shape, enter the Realm, or leave it empty for demo.

  4. Untick the Endpoints and Grants the token endpoint accepts you do not need. Under Allowed redirect addresses, enter your application’s callback, such as https://app.example.test/callback, one per line. http://localhost and http://127.0.0.1 on any port are always allowed.

  5. Optionally fill in the Signed-in user: Subject (sub), Email, Name and Audience (aud). A field left empty uses the value shown in it, such as user-1 and my-api.

  6. Select Preview. Each endpoint is listed by name, with its method and path. An endpoint an existing mock already answers starts unticked, with the mock named. A value MockHub refuses is marked on its field, such as “Line 2: This value is not a valid URL.” under the redirect addresses.

  7. Select Create mocks. The mocks are created Inactive, tagged identity-provider.

  8. On the Identity provider page, select Show them in Mocks, tick every mock, and select Activate.

  9. Point your application at the discovery URL the Identity provider page shows for your host, such as https://orders-api.mockhub.dev/.well-known/openid-configuration.

From a terminal, the CLI does the same:

Terminal window
mockhub idp init --env staging --preset keycloak --realm shop --redirect-uri https://app.example.test/callback

A client-credentials request returns a signed token:

Terminal window
curl -s https://orders-api.mockhub.dev/oauth/token \
-d grant_type=client_credentials -d client_id=my-app -d client_secret=made-up
{ "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6…", "token_type": "Bearer", "expires_in": 3600 }

The authorization-code flow works end to end: authorize redirects at once to the allowed address with a code and your state, and the token endpoint exchanges the code for an access token, an ID token and a refresh token that carry the nonce, scope and client the flow began with.

The token endpoint has responses for invalid_grant (400) and invalid_client (401) besides the successful ones. To get one, send X-MockHub-Response: <mock reference>:<response key>, such as 1a2b3c4d5e6f:invalid-grant. Copy the value from the response in the mock editor instead of writing it: a key alone is refused with a 400. See Ask for a response in one request. An unsupported grant_type answers unsupported_grant_type (400). Authorize and sign-out take no request override, so the header cannot change where a browser is redirected: a request that sends it is refused with a 422.

The project gets one RS256 and one ES256 signing key the first time a mock that signs or publishes them is served. Rotate keys makes new ones: new tokens are signed with them, tokens signed with the previous keys keep verifying, and tokens signed two rotations ago stop verifying. Keys are never exported: a copied project, a configuration pushed into another project or an ephemeral environment signs with its own.

  • The provider checks nothing on its own: not a client secret, a password, a PKCE verifier, a registered client or that a code is used once. A token MockHub did not sign gets the response’s defaults, not a 401. No rule can tell a forged or expired token from a good one, since a rule reads only what the request states. To test a rejection, name the error response with X-MockHub-Response, or add a rule on a value your test sends, such as a particular client_id.
  • There is no login page. authorize redirects at once, so a browser never sees a form. No form_post, implicit or device flow, no SAML, no HS256 and no key of your own.
  • A mock’s traffic is logged as sent, form fields such as client_secret included. Use made-up secrets and passwords.
  • Anyone who can edit the project’s mocks can mint tokens your staging system trusts. A private project limits who can reach them.
  • Try it previews sign with a key no project’s JWKS lists, so a preview token never verifies.
  • A strict verification run refuses a dependency that signs tokens, since each token differs.

Report a problem with this page