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

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

edoaurahman/keycloak-sso
========================

Integrate Laravel with Keycloak

v7.4.x-dev(8mo ago)086MITPHPPHP ^7.4 || ^8.0 || ^8.1

Since Mar 17Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/tekinfopg/sso-helper-laravel)[ Packagist](https://packagist.org/packages/edoaurahman/keycloak-sso)[ RSS](/packages/edoaurahman-keycloak-sso/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (6)Used By (0)

Keycloak SSO for Laravel
========================

[](#keycloak-sso-for-laravel)

This package provides integration between Laravel and Keycloak, enabling Single Sign-On (SSO) and a convenient way to handle Keycloak tokens.

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

[](#requirements)

- PHP ^8.1
- Laravel ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0

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

[](#installation)

1. Require the package:

    ```
    composer require tekinfopg/sso-helper-laravel
    ```
2. Publish and configure the package:

    ```
    php artisan vendor:publish --provider="Edoaurahman\\KeycloakSso\\KeycloakServiceProvider" --tag=keycloak-config
    ```

    or

    ```
    php artisan vendor:publish --tag=keycloak-config
    ```

    This will publish a config file at `config/keycloak.php`. Adjust the settings to match your Keycloak realm, tokens, etc.
3. Add configuration to `config/services.php`

    ```
    'keycloak' => [
      'client_id' => env('KEYCLOAK_CLIENT_ID'),
      'client_secret' => env('KEYCLOAK_CLIENT_SECRET'),
      'redirect' => env('KEYCLOAK_REDIRECT_URI'),
      'base_url' => env('KEYCLOAK_BASE_URL'),   // Specify your keycloak server URL here
      'realms' => env('KEYCLOAK_REALM')         // Specify your keycloak realm
    ],
    ```
4. Add provider event listener

    Laravel 11+

    In Laravel 11, the default EventServiceProvider provider was removed. Instead, add the listener using the listen method on the Event facade, in your AppServiceProvider boot method.

    - Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers.

    ```
    Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
        $event->extendSocialite('keycloak', \SocialiteProviders\Keycloak\Provider::class);
    });
    ```

    Laravel 10 or below Configure the package's listener to listen for `SocialiteWasCalled` events. Add the event to your listen\[\] array in `app/Providers/EventServiceProvider`.

    ```
    protected $listen = [
        \SocialiteProviders\Manager\SocialiteWasCalled::class => [
            // ... other providers
            \SocialiteProviders\Keycloak\KeycloakExtendSocialite::class.'@handle',
        ],
    ];
    ```
5. Set up the fields for storing tokens in your User model:

    ```
    // in your database migration
    Schema::table('users', function (Blueprint $table) {
        $table->string('keycloak_token')->nullable();
        $table->string('keycloak_refresh_token')->nullable();
    });

    // in your User model
    protected $fillable = [
        // ...
        'keycloak_token',
        'keycloak_refresh_token',
    ];
    ```

Usage
-----

[](#usage)

KeycloakProviderService Interface
=================================

[](#keycloakproviderservice-interface)

MethodDescriptionParametersReturn Type`setBaseUrl($baseUrl)`Set the base Keycloak URL.`string $baseUrl``void``setRealm($realm)`Set the Keycloak realm.`string $realm``void``setTokenField($tokenField)`Set the custom token field.`string $tokenField``void``setRefreshTokenField($refreshTokenField)`Set the custom refresh token field.`string $refreshTokenField``void``refreshToken($refreshToken = null)`Refresh the Keycloak access token.`string $refreshToken` (nullable)`string`request($method, $url, $data = [])`Generic request to Keycloak API.`string $method`, `string $url`, `array $data``array``getClientList()`Get Keycloak client list.*N/A*`array``getUserList()`Get Keycloak user list.*N/A*`array``getUser($id)`Get a single user.`stringint $id``createUser($data)`Create a new Keycloak user.`array $data``array``updateUser($id, $data)`Update an existing user.`stringint $id`, `array $data``deleteUser($id)`Delete a user.`stringint $id``regenerateClientSecret($id)`Regenerate client’s secret.`stringint $id``getUserRoles($id)`Get roles assigned to a user.`string $id``array``getRoles($clientUuid)`Get all roles by client or realm.`string $clientUuid``array``getUsersWithRole($roleName)`Get all users with a given role.`string $roleName``array``getUsersWithRoles($clientUuid)`Get all users and their roles for a client.`string $clientUuid``array``createRole($clientUuid, $data)`Create a role for the realm or client.`string $clientUuid`, `array $data``array``resetUserPassword($userId, $newPassword)`Reset the password of a user by ID.`string $userId`, `string $newPassword``array``updateCurrentUserProfile($data)`Update the profile of the currently logged-in user.`array $data``array``deleteAllCurrentUserSessions()`Delete all sessions except the current session for the logged-in user.*N/A*`array``deleteCurrentUserSessionById($sessionId)`Delete a session associated with the currently logged-in user by ID.`string $sessionId``array``sendVerificationEmail($userId)`Send a verification email to a user to verify their email address.`string $userId``array``sendResetPasswordEmail($userId)`Send a reset password email to a user to reset their password.`string $userId``array``Other method on progress`---Example
-------

[](#example)

```
Route::get('/login-keycloak', function () {
    return Socialite::driver('keycloak')->redirect();
});

Route::get('/callback-keycloak', function () {
    $user = Socialite::driver('keycloak')->user();
    // Handle login logic...
});

Route::get('/get-users-keycloak', function (KeycloakProviderServiceInterface $keycloak) {
    return $keycloak->getUserList();
});
```

Logout Example
==============

[](#logout-example)

```
public function logout() {
    // Logout of your app.
    Auth::logout();

    // The user will not be redirected back.
    return redirect(Socialite::driver('keycloak')->getLogoutUrl());

    // The URL the user is redirected to after logout.
    $redirectUri = Config::get('app.url');

    // Keycloak v18+ does support a post_logout_redirect_uri in combination with a
    // client_id or an id_token_hint parameter or both of them.
    // NOTE: You will need to set valid post logout redirect URI in Keycloak.
    return redirect(Socialite::driver('keycloak')->getLogoutUrl($redirectUri, env('KEYCLOAK_CLIENT_ID')));
    return redirect(Socialite::driver('keycloak')->getLogoutUrl($redirectUri, null, 'YOUR_ID_TOKEN_HINT'));
    return redirect(Socialite::driver('keycloak')->getLogoutUrl($redirectUri, env('KEYCLOAK_CLIENT_ID'), 'YOUR_ID_TOKEN_HINT'));

    // You may add additional allowed parameters as listed in
    // https://openid.net/specs/openid-connect-rpinitiated-1_0.html
    return redirect(Socialite::driver('keycloak')->getLogoutUrl($redirectUri, CLIENT_ID, null, ['state' => '...'], ['ui_locales' => 'de-DE']));

    // Keycloak before v18 does support a redirect URL
    // to redirect back to Keycloak.
    return redirect(Socialite::driver('keycloak')->getLogoutUrl($redirectUri));
}
```

Env
---

[](#env)

```
KEYCLOAK_CLIENT_ID=client
KEYCLOAK_CLIENT_SECRET=secret_value
KEYCLOAK_CLIENT_UUID=uuid_value
KEYCLOAK_REDIRECT_URI=redirect_uri_value
KEYCLOAK_BASE_URL=https://example.com/
KEYCLOAK_REALM=example_realm
KEYCLOAK_API_URL=https://api.example.com/
```

Contributing
------------

[](#contributing)

Contributions are welcome! Feel free to submit a pull request or open an issue.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance70

Regular maintenance activity

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 70.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 ~165 days

Total

2

Last Release

255d ago

Major Versions

v1.0.0.x-dev → v7.4.x-dev2025-08-30

PHP version history (2 changes)v1.0.0.x-devPHP ^7.4 || ^8.1

v7.4.x-devPHP ^7.4 || ^8.0 || ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/33ed4d77e2c8074955a4b1c3cdc927864b9baf19c381359a1f965b863dff1038?d=identicon)[edoaurahman](/maintainers/edoaurahman)

---

Top Contributors

[![edoaurahman](https://avatars.githubusercontent.com/u/42271774?v=4)](https://github.com/edoaurahman "edoaurahman (79 commits)")[![fadlynj](https://avatars.githubusercontent.com/u/73513300?v=4)](https://github.com/fadlynj "fadlynj (32 commits)")[![yafianshori](https://avatars.githubusercontent.com/u/5766965?v=4)](https://github.com/yafianshori "yafianshori (1 commits)")

---

Tags

laravelSSOkeycloak

### Embed Badge

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

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

###  Alternatives

[socialiteproviders/manager

Easily add new or override built-in providers in Laravel Socialite.

42442.0M544](/packages/socialiteproviders-manager)[josiasmontag/laravel-recaptchav3

Recaptcha V3 for Laravel package

2641.6M2](/packages/josiasmontag-laravel-recaptchav3)[scaler-tech/laravel-saml2

SAML2 Service Provider integration for Laravel applications, based on OneLogin toolkit

2737.5k](/packages/scaler-tech-laravel-saml2)[truckersmp/steam-socialite

Laravel Socialite provider for Steam OpenID.

1516.7k](/packages/truckersmp-steam-socialite)[rahul900day/laravel-captcha

Different types of Captcha implementation for Laravel Application.

10715.9k](/packages/rahul900day-laravel-captcha)[kovah/laravel-socialite-oidc

OpenID Connect OAuth2 Provider for Laravel Socialite

2073.7k](/packages/kovah-laravel-socialite-oidc)

PHPackages © 2026

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