PHP code example of cometa / key-cloack

1. Go to this page and download the library: Download cometa/key-cloack library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cometa / key-cloack example snippets


   $routerMiddleware = [
       'auth' => Cometa\KeyCloack\Middlewares\Authenticate::class,
       'permission' => Cometa\KeyCloack\Middlewares\Authorization::class
       ...
   ];


$app->register(Cometa\KeyCloack\Providers\KeyCloackServiceProvider::class);

$app->routeMiddleware([
   'auth' => Cometa\KeyCloack\Middlewares\Authenticate::class,
   'permission' => Cometa\KeyCloack\Middlewares\Authorization::class
]);


$router->get('/keycloack', [
    'uses' => "KeyCloackController@index",
    'middleware' => ['auth', 'permission:users#list-all']
]);



    /**
     * @return \Illuminate\Contracts\Auth\Authenticatable|null
     **/
    Illuminate\Support\Facades\Auth::user();



    /**
     * @param  array<App\Model\Role>| Role
     * @return bool
     **/
     Illuminate\Support\Facades\Auth::hasRoles(Role::admin);
     ## OR
     Illuminate\Support\Facades\Auth::hasRoles([Role::admin, Role::gestor]);

    /**
     * @return array
     **/
    Illuminate\Support\Facades\Auth::allPermission();

    /**
     * @return array
     **/
    Illuminate\Support\Facades\Auth::getRoles();


    /**
     * @param string
     * @return mixed
     **/
    Illuminate\Support\Facades\Auth::getAttribute("name");