lorem-keycloak-client
v1.0.2
Published
A Node.js client for managing Keycloak users and authentication
Maintainers
Readme
🔐 lorem-keycloak-client
A lightweight Node.js SDK to manage users, login, and authorization in Keycloak. Ideal for teams that want to interact with Keycloak programmatically — register users, log in, reset passwords, and secure routes.
🔧 Usage
1. Register a User
const registerUser = require('lorem-keycloak-client/lib/registerUser');
await registerUser({
email: '[email protected]',
username: '[email protected]',
password: 'SecurePass123',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
baseUrl: 'https://auth.example.com',
realm: 'YourRealm',
role: 'user',
attributes: {
firstName: 'Ada',
lastName: 'Lovelace',
phone: '1234567890',
}
});2. Login a User
const loginUser = require('lorem-keycloak-client/lib/loginUser');
const tokens = await loginUser({
username: '[email protected]',
password: 'SecurePass123',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
baseUrl: 'https://auth.example.com',
realm: 'YourRealm'
});3. Reset Password
const resetPassword = require('lorem-keycloak-client/lib/resetPassword');
await resetPassword({
userId: 'keycloak-user-id',
newPassword: 'NewPass456',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
baseUrl: 'https://auth.example.com',
realm: 'YourRealm'
});4. Secure Your Routes with Middleware
const authMiddleware = require('lorem-keycloak-client/lib/authMiddleware');
app.get(
'/admin',
authMiddleware({
clientId: 'your-client-id',
requiredRoles: ['admin'],
baseUrl: 'https://auth.example.com',
realm: 'YourRealm'
}),
(req, res) => {
res.json({ message: 'Welcome Admin', user: req.user });
}
);👨🏽💻 Local Development
npm install
npm run devTo test the library locally:
npm link
cd your-other-project
npm link lorem-keycloak-client🤝 Contributing
- Fork this repo
- Make your changes in a feature branch
- Submit a PR with a detailed description
🛡 License
MIT License © 2025 Gbolahan Adegoke
💬 Need Help?
Open an issue here, or message your team lead.
