Skip to content

Securing Apps

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.

LessonWhat you will learn
SPA FrontendInstall keycloak-js, initialise it with PKCE, attach the token to API calls
Backend APIFetch JWKS, verify the JWT in Node/Express, reject invalid tokens
Refresh & LogoutupdateToken(), session lifetimes, and the end-session endpoint
Framework AdaptersSpring Boot, Node, and the general OIDC resource-server pattern

Each lesson is standalone — you can jump to the one that matches your stack today.

What is the responsibility of the FRONTEND in a Keycloak-secured application?
What is the responsibility of the BACKEND (resource server) in a Keycloak-secured application?
Which endpoint does the backend use to fetch Keycloak public keys for JWT verification?
Why must the backend validate the JWT on every request rather than trusting the frontend?