A service preset for aux4/mock that stands up a generic OAuth2/OIDC auth dance on a running mock server with a single command: a token endpoint, a bearer-gated /userinfo endpoint, and an RFC 6750 invalid_token 401 envelope. Use it for any OAuth2/OIDC provider that isn't covered by a vendor-specific preset. Install it and aux4 mock preset oauth becomes available — the mock core stays preset-agnostic.
This is a pure .aux4 package (no binary, no bundle). It works entirely by contributing an oauth command into aux4/mock's mock:preset profile via aux4's global.aux4 profile merge.
aux4 aux4 pkger install community/mock-preset-oauth
Installing this package pulls in aux4/mock as a dependency.
aux4 mock start --port 8080
aux4 mock preset oauth --port 8080
stub POST /token -> 200
stub GET /userinfo -> 200
stub GET /userinfo -> 401
Confirm it is installed and visible to the mock:
aux4 mock presets
Installed presets (apply with: aux4 mock preset <service> --port <port>):
oauth
| Method + Path | Status | Behavior | |---------------|--------|----------| | POST /token | 200 | OAuth2 token response (access_token, refresh_token, scope: openid profile email, token_type) | | GET /userinfo | 200 | OIDC identity JSON (sub, email, name) — only when Authorization: Bearer <token> is present | | GET /userinfo | 401 | RFC 6750 invalid_token envelope — fallback when no bearer token |
The /userinfo endpoint is registered as two stubs on the same path: a happy path gated on Authorization: Bearer * (any token) and a bare fallback returning the 401:
# with a bearer token → 200 identity
curl -s http://localhost:8080/api/userinfo -H 'Authorization: Bearer x'
# {"email":"sally@example.com","name":"Sally","sub":"1234567890"}
# without one → 401 invalid_token envelope
curl -s http://localhost:8080/api/userinfo
# {"error":"invalid_token","error_description":"The access token is missing or invalid"}
The preset is additive — it only calls aux4 mock stub, so it never clears existing stubs. Layer the business endpoints your test exercises on top:
aux4 mock preset oauth --port 8080
aux4 mock stub --port 8080 --method GET \
--path /api/v1/profile \
--status 200 --body '{"id":"u_1","plan":"pro"}'
All optional, with sane defaults, so a test can assert a known identity:
aux4 mock preset oauth --port 8080 \
--accessToken TOK123 --email sally@corp.io --user "Sally"
--accessToken — token returned by POST /token (default mock-access-token)--email — email in the userinfo response (default sally@example.com)--user — name in the userinfo response (default Sally)Also accepts --name and --stateDir to address a server the same way every other aux4/mock command does (precedence: --stateDir > --name > --port).
The preset stubs the conventional OIDC paths (/token, /userinfo). Point the code-under-test's base URL at http://localhost:<port>/api and let it append the real path — aux4/mock strips the /api mount prefix before matching. If your provider uses different paths, override them with aux4 mock stub on top of the preset.
aux4/mock and this preset are plain CLIs, so they drop straight into an aux4/test .test.md. In CI, declare both packages on the test job:
- uses: aux4/action@v1
with:
command: test
packages: aux4/mock,community/mock-preset-oauth
community/mock-preset-oauth follows the same pattern as community/mock-preset-google, the reference implementation for writing your own community/mock-preset-<service> package: depend on aux4/mock, re-declare the mock profile with a preset routing command, and add a <service> command under mock:preset whose execute is a sequence of aux4 mock stub calls.