pagewiser / keycloak-adapter
Easy-to-use PHP adapter for Keycloak authentication
Requires
- php: >= 8.0
- nette/utils: >= 2.4
Requires (Dev)
- nette/tester: ^2.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-12-01 15:20:07 UTC
README
Install
composer require ataccama/keycloak-adapter
Neon config:
parameters:
keycloak:
realmId: your_realm
clientDd: your_client_id
host: https://your.keycloak.com
defaultRedirectUri: https://your.default.url
api:
username: your_username
password: your_password
clientId: your_api_client_id
clientSecret: your_client_secret
services:
- Ataccama\Adapters\Keycloak(%keycloak%)
Self-signed certificates
TLS certificate verification is on by default. For local development against a Keycloak with a self-signed certificate it can be turned off:
parameters:
keycloak:
verify: false
This applies to every request the adapter makes. Never use it in production: client secrets and passwords can then be intercepted.
Use
Create new class and extend class Ataccama\Auth, then you MUST implement all missing methods with your own logic.
Login URL:
$loginUrl = $yourAuthClass->getLoginUrl()
In code use your class like this:
$yourAuthClass->authorize($_GET['code'])
Example (Nette Framework):
// waiting for authorization code from Keycloak
if ($yourAuthClass->authorize($this->getParameter('code'))) {
$this->redirectUrl($yourAuthClass->getRedirectUri());
} else {
if (!$yourAuthClass->isAuthorized()) {
$this->redirectUrl($yourAuthClass->getLoginUrl());
}
}
// check if user is logged in on every page, if not redirect him to Keycloak login page
if (!$yourAuthClass->isAuthorized()) {
$this->redirectUrl($yourAuthClass->getLoginUrl());
}