PHPackages                             drago-ex/keycloak - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. drago-ex/keycloak

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

drago-ex/keycloak
=================

Simple Keycloak adapter for easy integration.

v1.0.6(1y ago)1659MITPHPPHP &gt;=8.3 &lt;9CI passing

Since Jul 29Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/drago-ex/keycloak)[ Packagist](https://packagist.org/packages/drago-ex/keycloak)[ RSS](/packages/drago-ex-keycloak/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (5)Used By (0)

Drago Keycloak
--------------

[](#drago-keycloak)

Simple Keycloak adapter for easy integration.

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://raw.githubusercontent.com/drago-ex/keycloak/master/license)[![PHP version](https://camo.githubusercontent.com/30948815aa9fb0ee200ff25e3a9084850800e4cccb677d8736ec07fbb1ef3382/68747470733a2f2f62616467652e667572792e696f2f70682f647261676f2d65782532466b6579636c6f616b2e737667)](https://badge.fury.io/ph/drago-ex%2Fkeycloak)[![Tests](https://github.com/drago-ex/keycloak/actions/workflows/tests.yml/badge.svg)](https://github.com/drago-ex/keycloak/actions/workflows/tests.yml)[![Coding Style](https://github.com/drago-ex/keycloak/actions/workflows/coding-style.yml/badge.svg)](https://github.com/drago-ex/keycloak/actions/workflows/coding-style.yml)[![CodeFactor](https://camo.githubusercontent.com/0efddc0fffdd9bf84a7ed1210fb88aefac5e511c84be864a2eeb80255bef058a/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f647261676f2d65782f6b6579636c6f616b2f6261646765)](https://www.codefactor.io/repository/github/drago-ex/keycloak)[![Coverage Status](https://camo.githubusercontent.com/f8508140d0f73015cd8824a66c072ccf8af7fcc35bc651ecbb7c722f0db7211f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f647261676f2d65782f6b6579636c6f616b2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/drago-ex/keycloak?branch=master)

Requirements
------------

[](#requirements)

- PHP &gt;= 8.3
- Nette Framework
- Composer

Installation
------------

[](#installation)

```
composer require drago-ex/keycloak

```

Extension registration in `config.neon`
---------------------------------------

[](#extension-registration-in-configneon)

```
extensions:
	keycloak: Drago\Keycloak\DI\KeycloakExtension

keycloak:

	# https://github.com/stevenmaguire/oauth2-keycloak
	authServerUrl: keycloak-server-url
	realm: keycloak-realm
	clientId: keycloak-client-id
	clientSecret: keycloak-client-secret
	redirectUri: https://example.com/callback-url

	# optional
	# version: 21.0.1
	# encryptionAlgorithm: 'RS256'
	# encryptionKeyPath: '../key.pem'
	# encryptionKey: 'contents_of_key_or_certificate'

	# https://github.com/guzzle/guzzle
	# guzzleHttp:
```

Usage in Presenter
------------------

[](#usage-in-presenter)

```
use Drago\Keycloak\KeycloakAdapter;

public function __construct(
  private Keycloak $keycloak,
  private KeycloakSessions $keycloakSessions,
) {
  parent::__construct();
}

// Simple login
protected function startup(): void
{
  parent::startup();
  if (!$this->getUser()->isLoggedIn()) {
    $keycloakUser = $this->keycloakSessions->getItems()->resourceOwner;
    $this->getUser()->login($keycloakUser->getName(), $keycloakUser->getId());
    $this->redirect('redirect');
  }
}

// Custom authentication with Keycloak attributes and backlink
protected function startup(): void
{
  parent::startup();
  if (!$this->getUser()->isLoggedIn()) {
    $keycloakUser = $this->keycloakSessions->getItems()->resourceOwner;

    try {
      if ($keycloakUser) {
        $user = $this->getUser();

        // Custom authenticator
        $user->setAuthenticator($this->authRepository);

        // User login
        $user->login($keycloakUser->getName(), $keycloakUser->getId());

        // Backlink handling
        $this->restoreRequest($this->backlink);
        $this->redirect(':Backend:Admin:');
      }

    } catch (AuthenticationException $e) {
      if ($e->getCode() === 1) {
        $this->template->userLoginError = true;
        $this->getUserLogout();
        $redirect = $this->keycloak->getLogoutUrl();
        header('refresh:6; url=' . $redirect);
      }
    }
  }
}

// User logout
private function getUserLogout(): void
{
  $this->getUser()->logout();
  $this->keycloakSessions->remove();
}
```

### Error message in `@layout.latte`

[](#error-message-in-layoutlatte)

```

		{_'The user does not have the required attributes set in keycloak.'}

	...

```

### Items from Keycloak

[](#items-from-keycloak)

```
// Get state, accessToken, and resource owner
$this->keycloakSessions->getItems();
```

User Logout Method
------------------

[](#user-logout-method)

```
$this->keycloakSessions->remove();
$this->redirectUrl($this->keycloak->getLogoutUrl());
```

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance60

Regular maintenance activity

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~304 days

Total

4

Last Release

477d ago

PHP version history (4 changes)v1.0.0PHP &gt;=8.0

v1.0.2PHP &gt;=8.1

v1.0.5PHP &gt;=8.1 &lt;8.4

v1.0.6PHP &gt;=8.3 &lt;9

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5998929?v=4)[Zdeněk Papučík](/maintainers/accgit)[@accgit](https://github.com/accgit)

---

Top Contributors

[![accgit](https://avatars.githubusercontent.com/u/5998929?v=4)](https://github.com/accgit "accgit (89 commits)")

---

Tags

keycloaknette

### Embed Badge

![Health badge](/badges/drago-ex-keycloak/health.svg)

```
[![Health](https://phpackages.com/badges/drago-ex-keycloak/health.svg)](https://phpackages.com/packages/drago-ex-keycloak)
```

###  Alternatives

[mainick/keycloak-client-bundle

Keycloak client bundle for Symfony, designed to simplify Keycloak integration into your application and provide additional functionality for token management and user information access

4526.0k](/packages/mainick-keycloak-client-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
