pickmap/keycloak-middleware

keycloak

Installs: 537

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 1

Forks: 0

Open Issues: 1

pkg:composer/pickmap/keycloak-middleware

0.5.0 2023-09-10 07:09 UTC

This package is not auto-updated.

Last update: 2025-10-19 17:16:08 UTC


README

step #1

install package with below code

composer require pickmap/keycloak-middleware

step #2

‍‍ Go to ‍‍‍‍‍‍‍/config/app.php and put KeycloakMiddlewareServiceProvider::class code

    'providers' => ServiceProvider::defaultProviders()->merge([
        /*
         * Package Service Providers...
         */
        KeycloakMiddlewareServiceProvider::class,

step #3

add this command in terminal in your root of project

php artisan vendor:publish --tag=keycloak-middleware

than add your keycloak public key in /config/keycloak-middleware.php

return [
    'public_key' => null,
];

step #4

Now you can check keycloak tokens by installing middleware ‍‍‍keycloak-middleware for your route

Route::get('/', function () {
    dd(request()->all());
})->middleware('keycloak-middleware');

Scope And Role

Also, you can limit the access of users by sending the required scopes or roles

" * " means all (role or scope)

Route::group(['prefix' => 'v1','middleware' => 'keycloak-middleware:*,*'],function(){
    #  routes
});

Route::group(['prefix' => 'v1','middleware' => 'keycloak-middleware:admin,*'],function(){
    #  routes
});

Route::group(['prefix' => 'v1','middleware' => 'keycloak-middleware:admin|user,view.profile|send.email'],function(){
    #  routes
});