PHPackages                             nti/keycloak-security-bundle - 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. nti/keycloak-security-bundle

ActiveSymfony-bundle[Authentication &amp; Authorization](/categories/authentication)

nti/keycloak-security-bundle
============================

Allows you to easily handle you application security thanks to keycloak.

v2.0.0(2y ago)21.2k4MITPHPPHP ^7.1

Since Aug 26Pushed 1y agoCompare

[ Source](https://github.com/ntidev/IDCIKeycloakSecurityBundle)[ Packagist](https://packagist.org/packages/nti/keycloak-security-bundle)[ RSS](/packages/nti-keycloak-security-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (14)Versions (32)Used By (0)

NTI Keycloak Security Bundle
============================

[](#nti-keycloak-security-bundle)

This Symfony bundle is an alternative solution to FOSUserBundle, working with keycloak.

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

[](#installation)

With composer:

```
$ composer require nti/keycloak-security-bundle

```

Configuration
-------------

[](#configuration)

If you want to set up keycloak locally you can download it [here](https://www.keycloak.org/downloads.html) and follow instructions from [the official documentation](https://www.keycloak.org/docs/3.2/server_installation/topics/installation.html). In case that you want to use keycloak in docker go directly to [configuration for Docker](#docker).

### Bundle configuration

[](#bundle-configuration)

#### Basic

[](#basic)

In case of you already have keycloak running locally on your machine or is running remotely but without proxy, here is the default configuration you should use:

```
# config/packages/nti_keycloak_security.yaml
nti_keycloak_security:
    server_url: 'http://localhost:8080/auth' # your accessible keycloak url
    # server_url: 'http://keycloak.example.com/auth' # example with public url
    realm: 'MyRealm'
    client_id: 'my-client'
    client_secret: '21d4cc5c-9ed6-4bf8-8528-6d659b66f216'
    default_target_path: 'home' # The route name you will be redirected to after sign in
```

#### Docker

[](#docker)

If you want to use keycloak in docker you can base your stack on this [sample](./Resources/docs/example).

Here is a stack example configuration for docker swarm:

```
# config/packages/nti_keycloak_security.yaml
nti_keycloak_security:
    server_public_url: 'http://keycloak.docker/auth' # your keycloak url accessible via your navigator
    server_private_url: 'http://keycloak:8080/auth' # your keycloak container reference in the network
    realm: 'MyRealm'
    client_id: 'my-client'
    client_secret: '21d4cc5c-9ed6-4bf8-8528-6d659b66f216'
    default_target_path: 'home' # The route you will be redirected to after sign in
```

Make sure that your php container in the container is attached to a network with keycloak, otherwise it will not be able to resolve "" and the public\_server\_url must be accessible through the port 80 because keycloak verify the issuer.

### Route configuration

[](#route-configuration)

Create a new file in `config/routes/` to load pre configured bundle routes.

```
# config/routes/nti_keycloak_security.yaml
KeycloakSecurityBundle:
    resource: "@KeycloakSecurityBundle/Resources/config/routing.yaml"
    prefix: /
```

### Symfony security configuration

[](#symfony-security-configuration)

To link keycloak with symfony you must change the default security configuration in symfony.

Here is a simple configuration that restrict access to `/admin/*` routes only to user with role "ROLE\_ADMIN" :

```
# config/packages/security.yaml
imports:
    - { resource: '@KeycloakSecurityBundle/Resources/config/security.yaml' } # import our security provider

security:

    firewalls:

        # Authorize everyone to try connecting (this route is imported from our bundle routing configuration)
        auth_connect:
            pattern: ^/auth/connect/.*
            security: false

        # This bundle is using security guard provided by symfony
        # Login form authentication
        secured_area:
            pattern: ^/admin
            guard:
                provider: nti_keycloak_security_provider
                authenticators:
                    - NTI\KeycloakSecurityBundle\Security\Authenticator\KeycloakAuthenticator

        # Bearer token authentication
        api:
            pattern: ^/api
            guard:
                provider: nti_keycloak_bearer_security_provider
                authenticators:
                    - NTI\KeycloakSecurityBundle\Security\Authenticator\KeycloakBearerAuthenticator

    role_hierarchy:
        ROLE_ADMIN: ROLE_USER

    access_control:
        - { path: ^/admin, roles: ROLE_ADMIN }
        - { path: ^/api, roles: ROLE_API }
```

Keycloak configuration
----------------------

[](#keycloak-configuration)

If you need help to use keycloak because it is the first time you work on it, we've made a little tutorial step by step describing a basic configuration of a keycloak realm that you can found [here](./Resources/docs/keycloak-help-guide.md)

TODO
----

[](#todo)

- Install bundle configuration with flex recipe.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 52.5% 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 ~49 days

Recently: every ~229 days

Total

28

Last Release

750d ago

Major Versions

v1.26 → v2.0.02024-04-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/d33aa0220bae1b0c48f14fc349b7b3181fec7aa674da145ded4446f2b098fe47?d=identicon)[ntidev](/maintainers/ntidev)

---

Top Contributors

[![BeBlood](https://avatars.githubusercontent.com/u/24357558?v=4)](https://github.com/BeBlood "BeBlood (31 commits)")[![burahimu](https://avatars.githubusercontent.com/u/4537997?v=4)](https://github.com/burahimu "burahimu (9 commits)")[![konandrum](https://avatars.githubusercontent.com/u/964354?v=4)](https://github.com/konandrum "konandrum (7 commits)")[![angelbencosme](https://avatars.githubusercontent.com/u/6846866?v=4)](https://github.com/angelbencosme "angelbencosme (5 commits)")[![pbek](https://avatars.githubusercontent.com/u/1798101?v=4)](https://github.com/pbek "pbek (3 commits)")[![samirant15](https://avatars.githubusercontent.com/u/18222884?v=4)](https://github.com/samirant15 "samirant15 (2 commits)")[![vinz2018](https://avatars.githubusercontent.com/u/3055727?v=4)](https://github.com/vinz2018 "vinz2018 (1 commits)")[![yansellrivasdiaz](https://avatars.githubusercontent.com/u/38452151?v=4)](https://github.com/yansellrivasdiaz "yansellrivasdiaz (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nti-keycloak-security-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/nti-keycloak-security-bundle/health.svg)](https://phpackages.com/packages/nti-keycloak-security-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k12.4M192](/packages/simplesamlphp-simplesamlphp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[scheb/2fa

Two-factor authentication for Symfony applications (please use scheb/2fa-bundle to install)

578630.7k1](/packages/scheb-2fa)

PHPackages © 2026

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