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

ActiveLibrary

chenming1337/keycloak
=====================

Keycloak OAuth2 Provider for Laravel Socialite

02PHP

Since Jun 29Pushed 5y agoCompare

[ Source](https://github.com/chenming1337/keycloak)[ Packagist](https://packagist.org/packages/chenming1337/keycloak)[ RSS](/packages/chenming1337-keycloak/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Keycloak OAuth2 Provider for Laravel Socialite
----------------------------------------------

[](#keycloak-oauth2-provider-for-laravel-socialite)

### Installation

[](#installation)

```
    clone : git clone https://github.com/chenming1337/keycloak.git
    installing package : composer require chenming1337/keycloak

```

### Requirements

[](#requirements)

```
    Download latest keycloak server repository from https://www.keycloak.org/ and setup keycloak server at admin console.

```

### Environment Setup

[](#environment-setup)

Add below key array in '/config/services.php' file.

```
    'keycloak' => [
            'authServerUrl'         => env('KEYCLOAK_AUTHSERVERURL'),
            'realm'                 => env('KEYCLOAK_REALM'),
            'clientId'              => env('KEYCLOAK_CLIENTID'),
            'clientSecret'          => env('KEYCLOAK_CLIENTSECRET'),
            'redirectUri'           => env('KEYCLOAK_REDIRECTURI'),
            'encryptionAlgorithm'   => env('KEYCLOAK_ENCRYPTIONALGORITHM'),
            'encryptionKeyPath'     => env('KEYCLOAK_ENCRYPTIONKEYPATH'),
            'encryptionKey'         => env('KEYCLOAK_ENCRYPTIONKEY'),
    ]
```

### Laravel AppServiceProvider

[](#laravel-appserviceprovider)

Add below code in /app/Providers/AppServiceProvider.php file which helps to execute keycloak as a socialite provider.

```
    use Avdevs\Keycloak\KeycloakProvider;
```

In boot() method, add below code

```
    $this->bootKeycloakSocialite();
```

Add Function

```
    private function bootKeycloakSocialite()
    {
        $socialite = $this->app->make('Laravel\Socialite\Contracts\Factory');
        $socialite->extend(
            'keycloak',
            function ($app) use ($socialite) {
                $config = $app['config']['services.keycloak'];
                return new KeycloakProvider($config);
            }
        );
    }
```

### Laravel Functions and Routes

[](#laravel-functions-and-routes)

```
    use Socialite;
```

```
    Route::get('/redirect/{provider}', 'ProviderAuthController@redirectToProvider');

    /**
     * Redirect to keycloak server.
     * @provider
     * @return
     */
    public function redirectToProvider($provider)
    {
        /* where $provider = 'keycloak' */
        return Socialite::driver($provider)
                    ->stateless()
                    ->scopes([]) // Array ex : name
                    ->redirect();
    }
```

```
    Route::get('/callback/{provider}', 'ProviderAuthController@CallbackFunction');

    /**
     * retrieve user information which is located at keycloak serve.
     * @provider
     * @return
     */
    public function CallbackFunction($provider)
    {
        /* where $provider = 'keycloak' */
        $userData = Socialite::driver($provider)
                        ->stateless()
                        ->user();
        /* Note : */
        /* 1) Callback url is same for login and logout request. so this function executed twice. */
        /* 2) Must add below code, Because user data not retrieved while logout calls is requested. */
        if(!isset($userData->email)){
            return redirect()->back();
        }

        /* your logic for add or get user detail */

    }
```

```
    Route::get('/logout/{provider}', 'ProviderAuthController@ProviderLogout');

     /**
     * Log the user out of the application.
     * @provider
     * @return void
     */
    public function ProviderLogout($provider)
    {
        /* where $provider = 'keycloak' */
        /* logout from laravel auth */
        Auth::logout();
        /* redirect to keycloak logout url */
        return redirect(
            Socialite::driver($provider)
                ->getLogoutUrl()
        );
    }
```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/115218122?v=4)[onethird](/maintainers/onethird)[@OneThird](https://github.com/OneThird)

---

Top Contributors

[![DhavalatAVDEVS](https://avatars.githubusercontent.com/u/45190947?v=4)](https://github.com/DhavalatAVDEVS "DhavalatAVDEVS (7 commits)")[![NewAvdevs](https://avatars.githubusercontent.com/u/131870947?v=4)](https://github.com/NewAvdevs "NewAvdevs (4 commits)")[![chenming1337](https://avatars.githubusercontent.com/u/17350775?v=4)](https://github.com/chenming1337 "chenming1337 (3 commits)")[![aXent](https://avatars.githubusercontent.com/u/506956?v=4)](https://github.com/aXent "aXent (1 commits)")[![leakhand](https://avatars.githubusercontent.com/u/11495529?v=4)](https://github.com/leakhand "leakhand (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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