Demo Rails app showcasing authentication & authorization with Keycloak via the keycloak_middleware gem (v0.1.4).
🚀 Features
✅ Integrates with Keycloak using OpenID Connect.
✅ Middleware validates JWT and enforces required roles.
✅ Protects /secured and /admin endpoints.
✅ Role-based access control.
📦 Installation Clone and install dependencies:
git clone https://github.com/<your-username>/keycloak-demo-app.git
cd keycloak-demo-app
bundle install
Run database migrations if needed:
rails db:setup
🔧 Configuration Set the following environment variables for Keycloak:
export KEYCLOAK_SITE="http://localhost:8080"
export KEYCLOAK_REALM="myrealm"
export KEYCLOAK_CLIENT_ID="my-client"
export KEYCLOAK_CLIENT_SECRET="my-secret"
🛣️ Routes
Method Path Description
GET /public Public page
GET /secured Requires user role
GET /admin Requires admin role
🧪 Run Start the server:
bin/dev
Or simply:
rails server
Visit: http://localhost:3000
This app uses the Keycloak::Middleware to intercept requests and validate JWT tokens for /secured and /admin.
You can customize required roles in config/initializers/keycloak_middleware.rb.
📄 License MIT