How ngtrieuvi92/keycloak-reactjs-demo works
Project type and purpose
• This is a full-stack demo application showcasing a React.js single-page application (SPA) integrated with Keycloak for SSO, plus a proxied backend service described by a Swagger spec.
File structure
• Top-level:
• public/ contains static HTML and Keycloak adapter config
• src/ houses React components, business-logic modules, and proxy setup
• backend-swagger-spec.yml describes the API schema
• setupProxy.js configures the CRA dev server to forward API calls
• Patterns:
• Component-based UI (BookList, BookDetails, BookForm, etc.)
• A thin “modules/books.js” layer for HTTP calls to /books endpoints
• Integration with Keycloak’s JavaScript adapter and silent-check-sso
README for additional insights
• Purpose: demo of Keycloak SSO + “silent check-sso” flow in a React app
• Prerequisites: CRA (>= v16.3), Keycloak >= v8.x
• Backend: can be spun up via the provided Swagger spec or any compatible service; dev proxy points to a local backend
Main components & interactions
a. Components
1. Browser / User Agent
2. React SPA (running in the browser)
– Components: BookList, BookDetails, BookForm, etc.
– Modules layer (books.js) calling REST API
– Keycloak adapter (in index.js + silent-check-sso.html)
3. Keycloak SSO Server (external identity provider)
4. Backend API Service (implements Swagger spec)
5. (Optional) Database behind the backend
b. Relationships / Data flow
– User → Browser → serves index.html + React bundle
– SPA → Keycloak: initialization, login redirect, token exchange, silent-check-sso via hidden iframe
– SPA → Backend API: authenticated REST calls (GET/POST/PUT/DELETE /books) through the CRA proxy
– Backend API → Database: CRUD operations
c. Architectural patterns / principles
– SPA architecture with separation of concerns: UI components vs. API modules
– Proxying dev-server traffic to avoid CORS
– OIDC authorization code flow (with PKCE) and silent SSO check
d. Key technologies
– React.js (create-react-app)
– keycloak-js adapter
– Webpack Dev Server proxy (setupProxy.js)
– Swagger/OpenAPI (backend-swagger-spec.yml)
– Node/Express or any RESTful backend (implied)
Detail without over-splitting
• Essential pieces (static assets, SPA runtime, auth adapter, proxy, API spec)