Backend Token Validation
Creating a OAuth2 enabled resource server.
Now that you’ve set up oidc-spa in your web app, you can call your API like this:
const todos = fetch("/api/todos", {
headers: {
Authorization: `Bearer ${await oidc.getAccessToken()}`
}
});Next, let’s implement the backend side of things.
When you implement the server GET /api/todos handler, you want to read the Authorization header.
Use it to authenticate the user.
Optionally, check permissions (roles/scopes) to authorize the request.
If you’re building a JavaScript backend (Express, Hono, tRPC, NestJS, etc.), oidc-spa provides utilities to validate and decode access tokens. Validation includes DPoP proof checks and replay protection.
Integration
Integration instruction for common HTTP framworks. This only covers REST APIs and RPC. For securing WebSocket connection see bellow.
WebSocket
WebSocketMock Modes
Mock ModesTODO List Example
A TODO list example app built with Vite / React / TanStack Router on the frontend, and Node.js / Hono on the backend.
The app is live here:
Source code (REST API):
Source code (frontend):
Last updated
Was this helpful?