Skip to content

feat(examples): add web app calling an API example - #14

Merged
frederikprijck merged 9 commits into
mainfrom
example/web-call-api
Jun 29, 2026
Merged

frederikprijck merged 9 commits into
mainfrom
example/web-call-api

Conversation

@frederikprijck

@frederikprijck frederikprijck commented Jun 19, 2026

Copy link
Copy Markdown
Member

Summary

Adds a new self-contained example, example-express-web-call-api, demonstrating how to use @auth0/auth0-express to:

  • log a user in with an audience, and
  • obtain an access token via req.auth0.client.getAccessToken() and call a separate resource server on the user's behalf with a Bearer token.

The resource server is the existing examples/example-express-api (protected by @auth0/auth0-express-api), run as a separate service. example-express-api gains a backward-compatible PORT env override so it can run on 3001 alongside this web app on 3000.

Tests

src/index.spec.ts follows the existing example-express-mcd pattern (MSW + supertest). It mocks Auth0 discovery, JWKS, and the token endpoint (signing real RS256 JWTs with jose) and the downstream API, then drives a full mocked login (/auth/login/auth/callback) and asserts:

  • the authorize request carries the configured audience,
  • /call-api forwards the access token and renders the API response,
  • /call-api redirects to login without a session.

CI

Adds a Web App Calling an API job to .github/workflows/examples.yml running build + test:ci, mirroring the other per-example jobs.

Verification

npm run build -w @auth0/auth0-express && npm run build -w example-express-web-call-api && npm run test:ci -w example-express-web-call-api — build clean, 3/3 tests passing.

…urce server

The two Auth0 SDKs both augment the global Express.Request.auth0 type with
incompatible shapes, so a web app (@auth0/auth0-express) and a resource server
(@auth0/auth0-express-api) cannot share one tsc compilation. Instead of bundling
the API, this example calls the existing example-express-api over HTTP. Adds a
PORT override to example-express-api so it can run on 3001 alongside this app.
Comment thread examples/example-express-web-call-api/package.json Outdated
…block

ts-node is not used by any script (start/build/test use tsx/tsc/vitest)
and the ts-node tsconfig key is read by nothing. Per PR review feedback.
@frederikprijck
frederikprijck merged commit 92c69c1 into main Jun 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants