Securing Apps
Two halves, one security model
Section titled “Two halves, one security model”Integrating Keycloak into an application is not a single task — it is two distinct responsibilities that must both be done correctly.
The frontend (a browser-based SPA, a mobile app, or any public client) is responsible for the login experience. It redirects the user to Keycloak, receives the authorization code, exchanges it for tokens, and stores those tokens safely in memory. From that point on, it attaches the access token to every API call it makes.
The backend (your REST API, your resource server) never talks to Keycloak on the user’s behalf during a request. Instead, it receives the access token in the Authorization header, fetches Keycloak’s public keys from the JWKS endpoint, and verifies the token’s signature, issuer, audience, and expiry. Only after that verification passes does the backend trust the identity claims inside the token.
What this module covers
Section titled “What this module covers”| Lesson | What you will learn |
|---|---|
| SPA Frontend | Install keycloak-js, initialise it with PKCE, attach the token to API calls |
| Backend API | Fetch JWKS, verify the JWT in Node/Express, reject invalid tokens |
| Refresh & Logout | updateToken(), session lifetimes, and the end-session endpoint |
| Framework Adapters | Spring Boot, Node, and the general OIDC resource-server pattern |
Each lesson is standalone — you can jump to the one that matches your stack today.