PHPackages                             g4t/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. g4t/keycloak

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

g4t/keycloak
============

1.0.1(3y ago)1210MITPHPPHP ^8.0

Since Apr 27Pushed 3y ago1 watchersCompare

[ Source](https://github.com/hussein4alaa/keycloak-guard-laravel)[ Packagist](https://packagist.org/packages/g4t/keycloak)[ RSS](/packages/g4t-keycloak/feed)WikiDiscussions 1.0.1 Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Keycloak Guard Laravel Package
==============================

[](#keycloak-guard-laravel-package)

The keycloak-guard-laravel package provides an integration between the Keycloak authentication server and a Laravel application. It allows you to use Keycloak as the authentication provider for your Laravel application.

[![image](https://camo.githubusercontent.com/3273fc21aa6199c54d6c29f61f46c0dd6a4f9eeaae27f44ddf22219ddc16acd9/68747470733a2f2f696d616765732e673263726f77642e636f6d2f75706c6f6164732f70726f647563742f696d6167652f736f6369616c5f6c616e6473636170652f736f6369616c5f6c616e6473636170655f30343864616633326434373438613464636438613338363137616634666638352f6b6579636c6f616b2e706e67)](https://camo.githubusercontent.com/3273fc21aa6199c54d6c29f61f46c0dd6a4f9eeaae27f44ddf22219ddc16acd9/68747470733a2f2f696d616765732e673263726f77642e636f6d2f75706c6f6164732f70726f647563742f696d6167652f736f6369616c5f6c616e6473636170652f736f6369616c5f6c616e6473636170655f30343864616633326434373438613464636438613338363137616634666638352f6b6579636c6f616b2e706e67)

Installation You can install the package using Composer:

```
composer require g4t/keycloak
```

now publish config file run following command

```
php artisan vendor:publish
```

and select `g4t\Keycloak\KeycloakGuardServiceProvider` provider

Configuration
=============

[](#configuration)

To configure the package, you need to add your Keycloak server details to your Laravel .env file:

```
K_REALM_PUBLIC_KEY=
K_LOAD_USER_FROM_DATABASE=true # get user data from database or keycloak
K_USER_PROVIDER_CREDENTIAL=username # This setting specifies the unique column name in your user provider table that will be used to retrieve the user's credentials for authentication.
K_TOKEN_PRINCIPAL_ATTRIBUTE=preferred_username # This setting specifies the key name for the attribute in the Keycloak token that will be used to check against the unique column specified in K_USER_PROVIDER_CREDENTIAL. The attribute should contain the user's unique identifier, such as a username or email address.
K_TOKEN_EXPIRED=false # Enable this when you are sure that you have set the Keycloak server time correctly.
```

You also need to configure your Laravel application to use the keycloak guard. To do this, add the following to your `config/auth.php` file:

```
'guards' => [
    // Other guards...

    'keycloak' => [
        'driver' => 'keycloak',
        'provider' => 'users',
    ],
],

'providers' => [
    // Other providers...

    'users' => [
        'driver' => 'keycloak',
    ],
],
```

Usage
=====

[](#usage)

Once the package is installed and configured, you can use the keycloak guard to authenticate users in your Laravel application. To authenticate a user, you can use the Auth::guard('keycloak')-&gt;attempt($credentials) method, where $credentials is an array of user credentials.

For example:

```
return auth('keycloak')->attempt([
      'url' => 'http://localhost:8080',
      'realm' => 'realm-name',
      'username' => 'username',
      'password' => 1234,
      'client_id' => 'client_id',
      'client_secret' => 'client_secret',
      'grant_type' => 'password',
]);
```

You can also use the auth('keycloak')-&gt;check() method to check if the user is authenticated:

```
if (auth('keycloak')->check()) {
    // User is authenticated
} else {
    // User is not authenticated
}
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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 ~0 days

Total

3

Last Release

1110d ago

### Community

Maintainers

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

---

Top Contributors

[![hussein4alaa](https://avatars.githubusercontent.com/u/13614747?v=4)](https://github.com/hussein4alaa "hussein4alaa (12 commits)")

---

Tags

keycloakkeycloak-spilaravelphp

### Embed Badge

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

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

###  Alternatives

[google/auth

Google Auth Library for PHP

1.4k272.7M162](/packages/google-auth)[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2509.6M48](/packages/thenetworg-oauth2-azure)[stevenmaguire/oauth2-keycloak

Keycloak OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[robsontenorio/laravel-keycloak-guard

🔑 Simple Keycloak Guard for Laravel

5161.1M3](/packages/robsontenorio-laravel-keycloak-guard)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[wp-graphql/wp-graphql-jwt-authentication

JWT Authentication for WPGraphQL

361118.4k1](/packages/wp-graphql-wp-graphql-jwt-authentication)

PHPackages © 2026

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